short_position = -0.5 leverage = 1.0 # end_day = -1 # -1 means till today start_day = '2012-01-01' trading_days = 252.0 interest_rate = 0.0 horizon = 21 * 1 freq = 21 * 1 # rebalance monthly roll = 36 # rolling in x months ben = 'ACWI' # benchmark model_name = ['SVR', 'Lasso'] # model_name = 'Ridge' relative = True normalize = True nor_method = '98%shrink' thre = {'long_thre': (0.0, 0.2), 'short_thre': (0.0, 0.05)} daily = False get_data_method = 'last_date_monthly' # Back-test initialization context = context(ben, start_day, variable_list, freq, leverage, long_position, short_position, \ interest_rate, trading_days, daily=daily, method=get_data_method) # Form training set and you just need run once and after that you can comment it until you change # variable list or other parameters. # context.generate_train(horizon, relative, normalize,method=nor_method) # Name the results using parameters and so on address = 'etf_long_' + str(round(long_position, 1)) + '_' + 'short' + str(round(short_position, 1)) + \ '_' + str(model_name) + '_' + str(thre['long_thre'][1]) + '_' +str(thre['short_thre'][1])+'_'+ \ str(horizon)+ '_' + str(roll) + '_'+nor_method+'.csv' context.back_test(horizon, model_name, address, select_stocks, order_method,roll,\ thre=thre,com_method='score')
trading_days = 252.0 interest_rate = 0.0 horizon = 21 * 1 # prediction horizon freq = 21 * 1 # rebalance monthly roll = 36 # rolling in x months ben = 'ACWI' # benchmark model_name = 'Lasso' relative = True normalize = True nor_method = '98%shrink' thre = {'long_thre': (0.0, 0.2), 'short_thre': (0.0, 0.1)} daily = False get_data_method = 'last_date_monthly' # Back-test initialization context = context(ben, start_day, variable_list, freq, leverage, long_position, short_position, \ interest_rate, trading_days, daily=daily, method=get_data_method) # Form training set and you just need run once and after that you can comment it until you change # variable list or other parameters. # context.generate_train(horizon, relative, normalize, method=nor_method) # Name the results using parameters and so on address = 'etf_T_0.001_long' + str(round(long_position, 1)) + '_' + 'short' + str(round(short_position, 1)) + \ '_' + model_name + '_' + str(thre['long_thre'][1]) + '_' + str(thre['short_thre'][1]) + '_' + \ str(horizon) + '_' + str(roll) + '_' + nor_method + '.csv' context.back_test(horizon, model_name, address, select_stocks, order_method, roll, thre=thre, filter_score=False)
variable_list = ['prr_ttm', 'eps_ttm', 'pb_lf', 'ps_ttm', 'np_growth_1y2'] leverage = 0.95 end_day = -1 start_day = '2008-01-01' trading_days = 12.0 #because it's mnonthly data horizon = 1 istech = 1 large = True freq = 1 roll = 6 model_name = 'Lasso' address = model_name + '_istech_large.csv' relative = True context = context( start_day, leverage, trading_days, ) # context.pre_processing() context.import_trading_data() context.import_features(variable_list) # context.generate_train(horizon,relative,normalize =True) context.back_test(horizon, istech, large, freq, model_name, address, roll, threshold=0.5)