예제 #1
0
def run_formula(dv):
    import pandas as pd
    import numpy as np
    from jaqs_fxdayu.data.dataservice import LocalDataService
    dataview_folder = r'D:\my_data\量化云实习\data'
    ds = LocalDataService(fp=dataview_folder)
    rm=ds.index_daily(['000300.SH'], 20130101,  20180101,'trade_date,close')[0].set_index('trade_date')['close']
    
    Rm80=rm.pct_change(80)
    r80=dv.get_ts('close').pct_change(80)

    Index_var80=(Rm80.rolling(80).std())**2
    cov_r80=r80.rolling(80).cov(Rm80)
    beta80=cov_r80.apply(lambda x:x/Index_var80,axis=0)
    
    r_adj80=beta80.apply(lambda x:x*Rm80*100,axis=0)
    dv.append_df(r_adj80,'r_adj80')

    return r_adj80
예제 #2
0
def get_dv(start=20170101, end=20180101):
    import jaqs_fxdayu
    jaqs_fxdayu.patch_all()
    from jaqs.data import DataView
    from jaqs_fxdayu.data.dataservice import LocalDataService

    import warnings

    warnings.filterwarnings("ignore")

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

    # define
    factor_list = [
        'np_parent_comp_ttm', 'tot_cur_liab', 'cogstosales', 'oper_rev_ttm',
        'tangibleasset', 'interestdebt'
    ]
    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))

    ben_ret = list(ds.index_daily(['000300.SH'], start, end, 'close'))[0]

    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()
    return dv
vema12 = pd.DataFrame(index=volume.index)
for col in volume.columns:
    inter = pd.DataFrame(pd.Series(ta.EMA(np.array(list(volume[col])), 12)),
                         columns=[col])
    for i in range(1215):
        vema12.loc[vema12.index[i], col] = inter.iloc[i, 0]
temp = []
test = list(vema12.columns)
for i in stock_symbol:
    if i not in test:
        temp = temp + [i]
for i in temp:
    vema12[i] = np.nan
dv.append_df(vema12, "vema12")
#informationratio60
hs300 = ds.index_daily(['000300.SH'], 20130101, 20180101,
                       "close")[0].pct_change()
close = dv.get_ts("close")
hs300 = hs300.set_index(close.index)
hs300 = hs300['close']
close = close.dropna(axis=1)
close = close.pct_change()
close = close.sub(hs300, axis=0)  #计算出了每日的超额收益,下面计算60日IC
ret = close.rolling(window=60).mean()
std = close.rolling(window=60).std()
ir60 = close.copy()
for col in ir60.columns:
    ir60[col] = ret[col].div(std[col], axis=0)  #计算出60日信息比率
dv.append_df(ir60, "ir60")
#adminiexpenserate
adminiexpenserate = dv.add_formula(
    'adminiexpenserate',