Exemplo n.º 1
0
def test_q_add_field():
    dv = DataView()
    dv.load_dataview(folder_path=quarterly_path)
    nrows, ncols = dv.data_q.shape
    n_securities = len(dv.data_d.columns.levels[0])

    ds = RemoteDataService()
    ds.init_from_config(data_config)
    dv.add_field("debttoassets", ds)
    assert dv.data_q.shape == (nrows, ncols + 1 * n_securities)
Exemplo n.º 2
0
def test_add_field():
    dv = DataView()
    dv.load_dataview(folder_path=daily_path)
    nrows, ncols = dv.data_d.shape
    n_securities = len(dv.data_d.columns.levels[0])

    ds = RemoteDataService()
    ds.init_from_config(data_config)
    dv.add_field('total_share', ds)
    assert dv.data_d.shape == (nrows, ncols + 1 * n_securities)
Exemplo n.º 3
0
def get_dv(start=20170101, end=20180101):
    import jaqs_fxdayu
    jaqs_fxdayu.patch_all()
    from jaqs_fxdayu.data import DataView
    from jaqs_fxdayu.data.dataservice import LocalDataService

    import warnings
    warnings.filterwarnings("ignore")

    #--------------------------------------------------------

    #define
    factor_list = ['fcffps', 'lt_borrow', 'st_borrow', 'LCAP', 'end_bal_cash']
    check_factor = ','.join(factor_list)

    dataview_folder = r'D:/data'
    ds = LocalDataService(fp=dataview_folder)

    ZZ800_id = ds.query_index_member("000906.SH", start, end)
    stock_symbol = list(set(ZZ800_id))

    dv_props = {
        'start_date': start,
        'end_date': end,
        'symbol': ','.join(stock_symbol),
        'fields': check_factor,
        'freq': 1,
        "prepare_fields": True
    }

    dv = DataView()
    dv.init_from_config(dv_props, data_api=ds)
    dv.prepare_data()

    # total market value
    data_config = {
        "remote.data.address":
        "tcp://data.tushare.org:8910",
        "remote.data.username":
        "******",
        "remote.data.password":
        "******"
    }
    from jaqs_fxdayu.data.dataservice import RemoteDataService
    ds1 = RemoteDataService()
    ds1.init_from_config(data_config)
    dv.add_field('total_mv', ds1)
    dv.add_field('ncf_oper_ttm', ds1)

    return dv
ds = LocalDataService(fp=dataview_folder)


factor_list = ['volume']
check_factor = ','.join(factor_list)

dv_props = {'start_date': start, 'end_date': end, 'symbol':','.join(stock_symbol),
         'fields': check_factor,
         'freq': 1,
         "prepare_fields": True}

dv.init_from_config(dv_props, data_api=ds)
dv.prepare_data()

for name in FactorList:
    dv.add_field(name)

import numpy as np

def mask_index_member():
    id_member = dp.daily_index_cons(api, "000906.SH", start, end)
    mask = id_member==0
    return mask

def limit_up_down():
    # 定义可买卖条件——未停牌、未涨跌停
    trade_status = dv.get_ts('trade_status')
    mask_sus = trade_status != 1
    # 涨停
    dv.add_formula('up_limit', '(close - Delay(close, 1)) / Delay(close, 1) > 0.095', is_quarterly=False, add_data=True)
    # 跌停
Exemplo n.º 5
0
from pandas import Series,DataFrame
dataview_folder = 'D:\data'
dv = DataView()
ds = LocalDataService(fp=dataview_folder)

dv_props = {'start_date': start, 'end_date': end, 'symbol':','.join(stock_symbol),
         'fields': check_factor,
         'freq': 1,
         "prepare_fields": True}

dv.init_from_config(dv_props, data_api=ds)
dv.prepare_data()

dv.init_from_config(dv_props, data_api=ds)
dv.prepare_data()
dv.add_field('sw1')

sw1 = dv.get_ts('sw1')
dict_classify = {'480000': '银行', '430000': '房地产', '460000': '休闲服务', '640000': '机械设备', '240000': '有色金属', '510000': '综合', '410000': '公用事业', '450000': '商业贸易', '730000': '通信', '330000': '家用电器', '720000': '传媒', '630000': '电气设备', '270000': '电子', '490000': '非银金融', '370000': '医药生物', '710000': '计算机', '280000': '汽车', '340000': '食品饮料', '220000': '化工', '210000': '采掘', '230000': '钢铁', '650000': '国防军工', '110000': '农林牧渔', '420000': '交通运输', '620000': '建筑装饰', '350000': '纺织服装', '610000': '建筑材料', '360000': '轻工制造'}

sw1_name = sw1.replace(dict_classify)
sw1_name.tail()

dv.add_field('close',ds)
dv.add_field('high',ds)
dv.add_field('low',ds)
dv.add_field('turnover',ds)
dv.add_field('turnover_ratio',ds)
dv.add_field('price_div_dps',ds)
dv.add_field('oper_rev',ds)
dv.add_field('roa',ds)