def create_data(root_path, info_path, sector_df, mode='bkt'): info = pd.read_pickle(info_path) root_path = pt._BinFiles(mode) args = info['args'] fun_list = info['fun'].split('.') raw_data_path = info['raw_data_path'] raw_data_list = load_raw_data(root_path, raw_data_path) target_fun = find_fun(fun_list) target_df = target_fun(*raw_data_list, sector_df, *args) return target_df
def indexDailyVwap(mode): root_path = pt._BinFiles(mode) index_TVAL_path = root_path.EM_Funda.INDEX_TD_DAILY / 'TVAL.csv' index_TVOL_path = root_path.EM_Funda.INDEX_TD_DAILY / 'TVOL.csv' index_TVOL_df = pd.read_table(index_TVOL_path, sep='|', index_col=0, parse_dates=True) index_TVAL_df = pd.read_table(index_TVAL_path, sep='|', index_col=0, parse_dates=True) index_vwap = (index_TVAL_df / index_TVOL_df) index_vwap_return = index_vwap.pct_change().round(4) return index_vwap, index_vwap_return
def DailyVwap(mode): root_path = pt._BinFiles(mode) tafactor_path = root_path.EM_Funda.TRAD_SK_FACTOR1 / 'TAFACTOR.csv' TVOL_path = root_path.EM_Funda.TRAD_SK_DAILY_JC / 'TVOL.csv' TVALCNY_path = root_path.EM_Funda.TRAD_SK_DAILY_JC / 'TVALCNY.csv' TVOL_df = pd.read_table(TVOL_path, sep='|', index_col=0, parse_dates=True) TVALCNY_df = pd.read_table(TVALCNY_path, sep='|', index_col=0, parse_dates=True) tafactor_df = pd.read_table(tafactor_path, sep='|', index_col=0, parse_dates=True) \ .reindex(columns=TVALCNY_df.columns, index=TVALCNY_df.index) daily_vwap = (TVALCNY_df / TVOL_df) daily_vwap_adj_price = daily_vwap / tafactor_df daily_vwap_adj_return = daily_vwap_adj_price.pct_change().round(4) return daily_vwap_adj_price, daily_vwap_adj_return
suspendday_df_c.iloc[-1] = 1 # 排除入场场涨跌停的影响 order_df = order_df * sector_df * limit_buy_sell_df_c * suspendday_df_c daily_pos = pos_daily_fun(order_df, n=hold_time) # 排除出场涨跌停的影响 daily_pos = daily_pos * limit_buy_sell_df * suspendday_df daily_pos.fillna(method='ffill', inplace=True) # 获得最终仓位信息 return daily_pos if __name__ == '__main__': a = time.time() mode = 'pro' root_path = pt._BinFiles(mode) sector_name = 'market_top_2000' alpha_name = '018AUG' config_info_path = f'/mnt/mfs/alpha_whs/{alpha_name}.pkl' if mode == 'pro': root_factor_path = '/media/hdd1/DAT_PreCalc/PreCalc_whs/{}'.format( sector_name) elif mode == 'bkt': root_factor_path = '/mnt/mfs/dat_whs/data/new_factor_data/{}'.format( sector_name) else: print('mode error !') exit() end_date = datetime.now() begin_date = end_date - timedelta(3)