return pool_long, pool_short if __name__ == "__main__": # parameters initialization variable_list = ['quant_technical_st','quant_technical_it','quant_technical_lt','quant_sentiment_iv',\ 'quant_sentiment_si','quant_sentiment_pc','quant_fundamental_pe','quant_fundamental_pb',\ 'quant_fundamental_pcf','quant_fundamental_div','quant_global_sector','quant_global_country',\ 'quant_quality_diversification','quant_quality_firm','quant_quality_liquidity'] start_day = '2012-01-01' horizon = 21 * 1 freq = 21 * 1 # rebalance monthly roll = 36 # rolling in x months ben = 'ACWI' # benchmark model_name = 'StepWise' relative = True # Back-test initialization context = context( ben, start_day, variable_list, freq, ) # 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=True,method='98%shrink') context.feature_selection(horizon,method=model_name,freq=freq,model_name = model_name,\ select_method=select_stocks,roll=roll)
start_day = '2012-01-01' 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)