def part_test_fun(instrument): adj_close_df = FutData().load_act_adj_fut_data(instrument, 'Close', active_df, aadj_factor_df) adj_high_df = FutData().load_act_adj_fut_data(instrument, 'High', active_df, aadj_factor_df) adj_low_df = FutData().load_act_adj_fut_data(instrument, 'Low', active_df, aadj_factor_df) adj_return_df = adj_close_df/adj_close_df.shift(1) - 1 for n in window_list: raw_factor = FutIndex.boll_fun(adj_close_df, n) for limit in limit_list: signal = Signal.fun_1(raw_factor, limit) pos = Position.fun_1(signal) pnl_df = (pos.shift(2) * adj_return_df).fillna(0) sp = bt.AZ_Sharpe_y(pnl_df) pot = bt.AZ_Pot(pos, pnl_df.sum()) print(instrument, sp, pot, n, limit) if abs(sp) > 1.4: print('!!!!!!!!!!!!!!!!')
import sys sys.path.append('/mnt/mfs') from work_whs.loc_lib.pre_load import * from work_whs.loc_lib.pre_load import log from work_whs.loc_lib.pre_load.plt import savfig_send from work_whs.test_future.FutDataLoad import FutData, FutClass from work_whs.test_future.signal_fut_fun import FutIndex, Signal, Position fut_data = FutData() def plot_send(con_id, begin_time, end_time, n=15): data_df = fut_data.load_intra_data(con_id, ['Close'])['Close'] part_df = data_df.truncate(begin_time, end_time) plt.figure(figsize=[80, 10]) plt.plot(range(len(part_df)), part_df.values) plt.xticks([ int(len(part_df.index.strftime('%Y-%m-%d %H:%M')) / (n - 1)) * i for i in range(n) ], part_df.index.strftime('%Y-%m-%d %H:%M')[[[ int(len(part_df.index) / (n - 1)) * i for i in range(n) ]]], rotation=45) plt.grid() savfig_send() plot_send('I2001.DCE', datetime(2019, 8, 10), datetime(2019, 11, 28), 80)
SignalAnalysis.CDF_c(signal_df, raw_return_df, hold_time=1, title=f'{fut_name} {col_name} CDF Figure', lag=0) ana_fun(data_df, fut_name, 'Volume_zscore') ana_fun(data_df, fut_name, 'past_min_pct_change') ana_fun(data_df, fut_name, 'trend_signal') return data_df if __name__ == '__main__': root_path = '/mnt/mfs/DAT_FUT' fut_data = FutData(root_path) fut_name_list = FutClass['黑色'] ban_name_list = [ 'WR', 'BB', 'ZC', 'SF', 'SM', 'FU', 'TA', 'SC', 'MA', 'OI', 'RS', 'IC' ] data_df = main() for x, part_data_df in data_df.groupby(['weekday']): part_pnl = part_data_df['pnl'].fillna(0).values print(x, part_pnl.sum()) plt.plot(part_pnl.cumsum()) savfig_send(subject=f'{x} {bt.AZ_Sharpe_y(part_pnl)}') for x, part_data_df in data_df.groupby(['month']): part_pnl = part_data_df['pnl'].fillna(0).values print(x, part_pnl.sum())
for limit in limit_list: signal = Signal.fun_1(raw_factor, limit) pos = Position.fun_1(signal) pnl_df = (pos.shift(2) * adj_return_df).fillna(0) sp = bt.AZ_Sharpe_y(pnl_df) pot = bt.AZ_Pot(pos, pnl_df.sum()) print(instrument, sp, pot, n, limit) if abs(sp) > 1.4: print('!!!!!!!!!!!!!!!!') window_list = [10, 20, 40, 100] limit_list = [1, 1.5, 2] for instrument in instrument_list: # part_test_fun(instrument) adj_close_df = FutData().load_act_adj_fut_data(instrument, 'Close', active_df, aadj_factor_df) adj_high_df = FutData().load_act_adj_fut_data(instrument, 'High', active_df, aadj_factor_df) adj_low_df = FutData().load_act_adj_fut_data(instrument, 'Low', active_df, aadj_factor_df) adj_return_df = adj_close_df / adj_close_df.shift(1) - 1 month_signal = pd.DataFrame(adj_return_df.index.strftime('%m'), index=adj_return_df.index, columns=['month']) for n in window_list: raw_factor = FutIndex.boll_fun(adj_close_df, n) for limit in limit_list: signal = Signal.fun_1(raw_factor, limit) pos = Position.fun_1(signal) pnl_df = (pos.shift(2) * adj_return_df).fillna(0) sp = bt.AZ_Sharpe_y(pnl_df) pot = bt.AZ_Pot(pos, pnl_df.sum())
'RS', 'OI', 'ZC', 'SM', 'BB', 'FB', 'B', ] instrument_list = sorted(list(set(instrument_list) - set(error_list))) data_name = 'OpenInterest' active_df, aadj_factor_df = get_active_df(data_name) # FutIndex.CCI_fun(high, low, close, n) # FutIndex.boll_fun(close, n) fut_data = FutData() act_info_df = fut_data.act_info_df # instrument_list = ['SC', 'C', 'J', 'JD'] # for fut_name in ['FG']: for fut_name in instrument_list: c12 = act_info_df[[fut_name + '01', fut_name + '02']] OI_01 = fut_data.load_act_fut_data_r(fut_name, 'OpenInterest', act_info_df, active_num='01') OI_02 = fut_data.load_act_fut_data_r(fut_name, 'OpenInterest', act_info_df,
import sys sys.path.append('/mnt/mfs') import string from work_whs.loc_lib.pre_load import * from work_whs.loc_lib.pre_load.plt import plot_send_result from work_whs.test_future.FutDataLoad import FutData fut_data = FutData('/mnt/mfs/DAT_FUT') # data_df = fut_data.load_intra_data('IC1906.CFE', ['Close', 'Volume']) data = fut_data.load_intra_data('IC1906.CFE', ['Close']) class FutReport: def __init__(self): self.fut_pos_bkt_path = '/mnt/mfs/AAFUTPOS/BKT' self.fut_pos_exe_path = '/mnt/mfs/AAFUTPOS/EXE' # all_pos_file = os.listdir(fut_pos_root_path) # all_pos_file = ['RZJ19Q10101.pos'] def deal_contract(self, part_pos_sr, contract_id): close_df = fut_data.load_intra_data(contract_id, ['Close']) if close_df is not None: diff_sr = close_df.reindex(index=part_pos_sr.index)['Close'].diff() part_pnl_sr = part_pos_sr * diff_sr part_pnl_sr.name = contract_id return part_pnl_sr else: return pd.Series(index=part_pos_sr.index, name=contract_id) def generation(self, begin_time=None, end_time=None):