Exemplo n.º 1
0
def test_save_dataview():
    ds = RemoteDataService()
    ds.init_from_config()
    dv = DataView()

    props = {
        'start_date': 20170101,
        'end_date': 20171001,
        'universe': '000300.SH',
        'fields': ('float_mv,pb,pe_ttm,sw2'),
        'freq': 1
    }

    dv.init_from_config(props, ds)
    dv.prepare_data()

    factor_formula = 'GroupQuantile(-float_mv, sw2, 10)'
    dv.add_formula('rank_mv', factor_formula, is_quarterly=False)

    factor_formula = 'GroupQuantile(If(pb >= 0.2, pb, 100), sw2, 10)'
    dv.add_formula('rank_pb', factor_formula, is_quarterly=False)

    factor_formula = 'GroupQuantile(If(pe_ttm >= 3, pe_ttm, 9999.0), sw2, 10)'
    dv.add_formula('rank_pe', factor_formula, is_quarterly=False)

    dv.save_dataview(folder_path=dataview_dir_path)
Exemplo n.º 2
0
def save_dataview():
    ds = RemoteDataService()
    ds.init_from_config()
    dv = DataView()

    props = {
        'start_date': 20140101,
        'end_date': 20171001,
        'universe': '000300.SH',
        'fields': 'volume,turnover,float_mv,pb,total_mv',
        'freq': 1
    }

    dv.init_from_config(props, ds)
    dv.prepare_data()

    # for convenience to check limit reachers
    dv.add_formula('limit_reached',
                   'Abs((open - Delay(close, 1)) / Delay(close, 1)) > 0.095',
                   is_quarterly=False)

    dv.add_formula('random', 'StdDev(volume, 20)', is_quarterly=False)
    dv.add_formula('momentum', 'Return(close_adj, 20)', is_quarterly=False)
    # dv.add_formula('size', '', is_quarterly=False)

    dv.save_dataview(dataview_folder)
Exemplo n.º 3
0
def save_dataview():
    ds = RemoteDataService()
    ds.init_from_config()
    dv = DataView()

    props = {'start_date': 20150101, 'end_date': 20170930, 'universe': '000905.SH',
             'fields': ('turnover,float_mv,close_adj,pe,pb'),
             'freq': 1}

    dv.init_from_config(props, ds)
    dv.prepare_data()

    factor_formula = 'Cutoff(Standardize(turnover / 10000 / float_mv), 2)'
    dv.add_formula('TO', factor_formula, is_quarterly=False)

    factor_formula = 'Cutoff(Standardize(1/pb), 2)'
    dv.add_formula('BP', factor_formula, is_quarterly=False)

    factor_formula = 'Cutoff(Standardize(Return(close_adj, 20)), 2)'
    dv.add_formula('REVS20', factor_formula, is_quarterly=False)

    factor_formula = 'Cutoff(Standardize(Log(float_mv)), 2)'
    dv.add_formula('float_mv_factor', factor_formula, is_quarterly=False)

    factor_formula = 'Delay(Return(close_adj, 1), -1)'
    dv.add_formula('NextRet', factor_formula, is_quarterly=False)

    dv.save_dataview(folder_path=dataview_dir_path)
Exemplo n.º 4
0
def test_write():
    ds = RemoteDataService()
    ds.init_from_config()
    dv = DataView()

    secs = '600030.SH,000063.SZ,000001.SZ'
    props = {
        'start_date': 20160601,
        'end_date': 20170601,
        'symbol': secs,
        'fields': 'open,close,high,low,volume,pb,net_assets,pcf_ncf',
        'freq': 1
    }

    dv.init_from_config(props, data_api=ds)
    dv.prepare_data()
    assert dv.data_d.shape == (281, 48)
    assert dv.dates.shape == (281, )
    # TODO
    """
    PerformanceWarning:
    your performance may suffer as PyTables will pickle object types that it cannot
    map directly to c-types [inferred_type->mixed,key->block1_values] [items->[('000001.SZ', 'int_income'), ('000001.SZ', 'less_handling_chrg_comm_exp'), ('000001.SZ', 'net_int_income'), ('000001.SZ', 'oper_exp'), ('000001.SZ', 'symbol'), ('000063.SZ', 'int_income'), ('000063.SZ', 'less_handling_chrg_comm_exp'), ('000063.SZ', 'net_int_income'), ('000063.SZ', 'oper_exp'), ('000063.SZ', 'symbol'), ('600030.SH', 'int_income'), ('600030.SH', 'less_handling_chrg_comm_exp'), ('600030.SH', 'net_int_income'), ('600030.SH', 'oper_exp'), ('600030.SH', 'symbol')]]
    """

    dv.save_dataview(folder_path=daily_path)
Exemplo n.º 5
0
def save_dataview(sub_folder='test_dataview'):
    ds = RemoteDataService()
    dv = DataView()

    props = {
        'start_date':
        20141114,
        'end_date':
        20160327,
        'universe':
        '000300.SH',
        'fields': (
            'open,high,low,close,vwap,volume,turnover,'
            # + 'pb,net_assets,'
            + 's_fa_eps_basic,oper_exp,tot_profit,int_income'),
        'freq':
        1
    }

    dv.init_from_config(props, ds)
    dv.prepare_data()

    factor_formula = 'close > Ts_Max(close, 20)'  # 20 days new high
    factor_name = 'new_high'
    dv.add_formula(factor_name, factor_formula, is_quarterly=False)

    dv.save_dataview(
        folder_path=fileio.join_relative_path('../output/prepared'),
        sub_folder=sub_folder)
Exemplo n.º 6
0
def test_save_dataview():
    ds = RemoteDataService()
    ds.init_from_config()
    dv = DataView()
    
    props = {'start_date': 20150101, 'end_date': 20170930, 'universe': '000905.SH',
             'fields': ('tot_cur_assets,tot_cur_liab,inventories,pre_pay,deferred_exp,'
                        'eps_basic,ebit,pe,pb,float_mv,sw1'),
             'freq': 1}
    
    dv.init_from_config(props, ds)
    dv.prepare_data()
    
    factor_formula = 'pe < 30'
    dv.add_formula('pe_condition', factor_formula, is_quarterly=False)
    factor_formula = 'pb < 3'
    dv.add_formula('pb_condition', factor_formula, is_quarterly=False)
    factor_formula = 'Return(eps_basic, 4) > 0'
    dv.add_formula('eps_condition', factor_formula, is_quarterly=True)
    factor_formula = 'Return(ebit, 4) > 0'
    dv.add_formula('ebit_condition', factor_formula, is_quarterly=True)
    factor_formula = 'tot_cur_assets/tot_cur_liab > 2'
    dv.add_formula('current_condition', factor_formula, is_quarterly=True)
    factor_formula = '(tot_cur_assets - inventories - pre_pay - deferred_exp)/tot_cur_liab > 1'
    dv.add_formula('quick_condition', factor_formula, is_quarterly=True)
    
    dv.add_formula('mv_rank', 'Rank(float_mv)', is_quarterly=False)
    
    dv.save_dataview(folder_path=dataview_dir_path)
Exemplo n.º 7
0
def save_dataview():
    ds = RemoteDataService()
    ds.init_from_config()

    dv = DataView()

    props = {
        'start_date':
        20170101,
        'end_date':
        20171030,
        'universe':
        '000300.SH',
        'fields': (
            'open,high,low,close,vwap,volume,turnover,sw1,'
            # + 'pb,net_assets,'
            + 'eps_basic,total_mv,tot_profit,int_income'),
        'freq':
        1
    }

    dv.init_from_config(props, ds)
    dv.prepare_data()

    factor_formula = 'close >= Delay(Ts_Max(close, 20), 1)'  # 20 days new high
    factor_name = 'new_high'
    dv.add_formula(factor_name, factor_formula, is_quarterly=False)

    dv.add_formula('total_profit_growth',
                   formula='Return(tot_profit, 4)',
                   is_quarterly=True)

    dv.save_dataview(folder_path=dataview_dir_path)
Exemplo n.º 8
0
def test_add_formula_directly():
    from jaqs.data.dataservice import RemoteDataService
    
    ds = RemoteDataService()
    dv = DataView()
    
    secs = '600030.SH,000063.SZ,000001.SZ'
    props = {'start_date': 20160601, 'end_date': 20170601, 'symbol': secs,
             'fields': 'open,close',
             'freq': 1}
    dv.init_from_config(props, data_api=ds)
    dv.prepare_data()
    
    dv.add_formula("myfactor", 'close / open', is_quarterly=False)
    assert dv.data_d.shape == (281, 33)
Exemplo n.º 9
0
    def _download_data(self):
        "使用quantos的dataview,下载单个股票的给定字段的数据,返回pd.DataFrame"
        dv = DataView()
        # fields = ','.join(list(dv.reference_daily_fields))
        props = {
            'symbol': self.symbol,
            'fields': self.fields,
            'start_date': self.start_date,
            'end_date': self.end_date,
            'freq': 1
        }

        dv.init_from_config(props=props, data_api=self._remote_data_service)
        dv.prepare_data()
        self._dataview_data = dv.data_d
Exemplo n.º 10
0
def save_dataview():
    ds = RemoteDataService()
    ds.init_from_config(data_config)
    dv = DataView()
    start_date = get_index_basic_information()[2]
    end_date = get_index_basic_information()[3]
    props = {
        'universe': index,
        'start_date': start_date,
        'end_date': end_date,
        'fields': fields,
        'freq': 1
    }
    dv.init_from_config(props, data_api=ds)
    dv.prepare_data()
    dv.save_dataview(folder_path=dataview_dir_path)
Exemplo n.º 11
0
def test_dataview_universe():
    from jaqs.data.dataservice import RemoteDataService

    ds = RemoteDataService()
    dv = DataView()
    
    props = {'start_date': 20170227, 'end_date': 20170327, 'universe': '000016.SH',
             # 'symbol': 'rb1710.SHF,rb1801.SHF',
             'fields': ('open,high,low,close,vwap,volume,turnover,'
                        + 'roe,net_assets,'
                        + 'total_oper_rev,oper_exp,tot_profit,int_income'
                        ),
             'freq': 1}
    
    dv.init_from_config(props, ds)
    dv.prepare_data()
Exemplo n.º 12
0
def test_save_dataview():
    ds = RemoteDataService()
    ds.init_from_config()
    dv = DataView()

    props = {'start_date': 20170201, 'end_date': 20171001, 'universe': '000300.SH',
             'fields': ('float_mv,sw2,sw1'),
             'freq': 1}

    dv.init_from_config(props, ds)
    dv.prepare_data()

    factor_formula = 'GroupQuantile(float_mv, sw1, 10)'
    dv.add_formula('gq30', factor_formula, is_quarterly=False)

    dv.save_dataview(folder_path=dataview_dir_path)
Exemplo n.º 13
0
def test_write_future():
    ds = RemoteDataService()
    ds.init_from_config()
    dv = DataView()

    secs = 'rb1710.SHF,j1710.DCE'
    props = {
        'start_date': 20170401,
        'end_date': 20170901,
        'symbol': secs,
        'fields': 'open,close,high,low,volume,oi',
        'freq': 1,
        'all_price': False
    }

    dv.init_from_config(props, data_api=ds)
    dv.prepare_data()
    assert dv.data_d.shape == (145, 14)
Exemplo n.º 14
0
def test_q():
    from jaqs.data.dataservice import RemoteDataService
    
    ds = RemoteDataService()
    dv = DataView()
    
    secs = '600030.SH,000063.SZ,000001.SZ'
    props = {'start_date': 20160609, 'end_date': 20170601, 'universe': '000300.SH', 'symbol': secs,
             'fields': ('open,close,'
                        + 'pb,net_assets,'
                        + 'total_oper_rev,oper_exp,'
                        + 'cash_paid_invest,'
                        + 'capital_stk,'
                        + 'roe'), 'freq': 1}
    
    dv.init_from_config(props, data_api=ds)
    dv.prepare_data()
    folder_path = '../output/prepared'
    dv.save_dataview(folder_path=folder_path)
Exemplo n.º 15
0
def test_save_dataview():
    ds = RemoteDataService()
    ds.init_from_config()
    dv = DataView()

    props = {
        'start_date': 20170101,
        'end_date': 20171001,
        'universe': '000300.SH',
        'fields': 'pe_ttm,net_profit_incl_min_int_inc',
        'freq': 1
    }

    dv.init_from_config(props, ds)
    dv.prepare_data()

    factor_formula = 'Return(net_profit_incl_min_int_inc, 4)'
    factor_name = 'net_profit_growth'
    dv.add_formula(factor_name, factor_formula, is_quarterly=True)

    dv.save_dataview(folder_path=dataview_dir_path)
Exemplo n.º 16
0
def save_dataview():
    # total 130 seconds
    
    ds = RemoteDataService()
    dv = DataView()
    
    props = {'start_date': 20141114, 'end_date': 20170327, 'universe': '000300.SH',
             # 'symbol': 'rb1710.SHF,rb1801.SHF',
             'fields': ('open,high,low,close,vwap,volume,turnover,'
                        # + 'pb,net_assets,'
                        + 's_fa_eps_basic,oper_exp,tot_profit,int_income'
                        ),
             'freq': 1}
    
    dv.init_from_config(props, ds)
    dv.prepare_data()
    
    dv.add_formula('eps_ret', 'Return(s_fa_eps_basic, 3)', is_quarterly=True)
    
    dv.add_formula('ret20', 'Delay(Return(close_adj, 20), -20)', is_quarterly=False)
    
    dv.save_dataview(folder_path=fileio.join_relative_path('../output/prepared'))
Exemplo n.º 17
0
def build_stock_selection_factor():
    ds = RemoteDataService()
    dv = DataView()

    props = {'start_date': 20120101, 'end_date': 20170901, 'universe': '000300.SH',
             # 'symbol': 'rb1710.SHF,rb1801.SHF',
             'fields': ('open,high,low,close,vwap,volume,turnover,'
                        # + 'pb,net_assets,'
                        + 's_fa_eps_basic,oper_exp,tot_profit,int_income'
                        ),
             'freq': 1}

    dv.init_from_config(props, ds)
    dv.prepare_data()

    dv.add_formula('eps_ret', 'Return(s_fa_eps_basic, 4)', is_quarterly=True)
    dv.add_formula('rule1', '(eps_ret > 0.2) && (Delay(eps_ret, 1) > 0.2)', is_quarterly=True)
    dv.add_formula('rule2', 'close > Ts_Max(close, 120)', is_quarterly=False)
    # dv.add_formula('ytan', 'rule1 && rule2', is_quarterly=False)

    dv.add_formula('ret20', 'Delay(Return(close_adj, 20), -20)', is_quarterly=False)

    dv.save_dataview(folder_path=fileio.join_relative_path('../output/prepared'))
Exemplo n.º 18
0
def test_q():
    ds = RemoteDataService()
    ds.init_from_config()
    dv = DataView()

    secs = '600030.SH,000063.SZ,000001.SZ'
    props = {
        'start_date':
        20160609,
        'end_date':
        20170601,
        'symbol':
        secs,
        'fields':
        ('open,close,' + 'pb,net_assets,' + 'total_oper_rev,oper_exp,' +
         'cash_paid_invest,' + 'capital_stk,' + 'roe'),
        'freq':
        1
    }

    dv.init_from_config(props, data_api=ds)
    dv.prepare_data()
    dv.save_dataview(folder_path=quarterly_path)
Exemplo n.º 19
0
def test_save_dataview(sub_folder='test_dataview'):
    ds = RemoteDataService()
    ds.init_from_config()
    dv = DataView()

    props = {
        'start_date': 20150101,
        'end_date': 20170930,
        'universe': '000905.SH',
        'fields':
        ('float_mv,tot_shrhldr_eqy_excl_min_int,deferred_tax_assets,sw2'),
        'freq': 1
    }

    dv.init_from_config(props, ds)
    dv.prepare_data()

    factor_formula = 'Quantile(-float_mv,5)'
    dv.add_formula('rank_mv', factor_formula, is_quarterly=False)

    factor_formula = 'Quantile(float_mv/(tot_shrhldr_eqy_excl_min_int+deferred_tax_assets), 5)'
    dv.add_formula('rank_pb', factor_formula, is_quarterly=False)

    dv.save_dataview(folder_path=dataview_dir_path)
Exemplo n.º 20
0
# indexList = ['000016.SH', '000300.SH', '000905.SH', '000985.CSI']
indexList = ['000016.SH', '000300.SH', '000905.SH', '000985.CSI']
retCompare = pd.DataFrame()
startdate = 20121231
enddate = 20171130

for index in indexList:
    # 设置DataView
    props = {
        'start_date': startdate,
        'end_date': enddate,
        'universe': index,
        'fields': 'close_adj',
        'freq': 1
    }
    dv.init_from_config(props, data_api=ds)
    dv.prepare_data()

    print(index)

    # 取出板块指数,版块成份股日收盘价及是否为成分股的信息
    closeData = dv.get_ts('close_adj')
    closeData['trade_date'] = closeData.index
    closeData['trade_date'] = closeData['trade_date'].apply(lambda x: str(x))
    closeData['trade_y'] = closeData['trade_date'].apply(lambda x: x[:4])

    benchmarkData = dv.data_benchmark
    benchmarkData['trade_date'] = benchmarkData.index
    benchmarkData['trade_date'] = benchmarkData['trade_date'].apply(
        lambda x: str(x))
    benchmarkData['trade_y'] = benchmarkData['trade_date'].apply(
Exemplo n.º 21
0
    # Investment universe and performance benchmark
    'universe': UNIVERSE,
    # Data fields that we need
    'fields': 'close',
    # freq = 1 means we use daily data. Please do not change this.
    'freq': 1
}

# RemoteDataService communicates with a remote server to fetch data
ds = RemoteDataService()
# Use username and password in data_config to login
ds.init_from_config(data_config)

# DataView utilizes RemoteDataService to get various data and store them
dv = DataView()
dv.init_from_config(dataview_props, ds)
dv.prepare_data()

# In[35]:

type(dv)

# In[ ]:

props = {
    'start_date': 20150101,
    'end_date': 20170901,
    'universe': '000300.SH',
    'fields': ('open,high,low,close,vwap,volume,turnover,eps_basic,roe,sw2'),
    'freq': 1
}