for x_var in var_list + ['pc_econ', 'pc_tech', 'pc_all']: if x_var == 'pc_econ': max_k = 3 results = oos_pc_forecast('log_equity_premium', econ_var, df, max_k, beg_date_init, beg_date_oos, end_date_oos) elif x_var == 'pc_tech': max_k = 1 results = oos_pc_forecast('log_equity_premium', tech_var, df, max_k, beg_date_init, beg_date_oos, end_date_oos) elif x_var == 'pc_all': max_k = 4 results = oos_pc_forecast('log_equity_premium', var_list, df, max_k, beg_date_init, beg_date_oos, end_date_oos) else: results = oos_forecast('log_equity_premium', x_var, df, beg_date_init, beg_date_oos, end_date_oos) d['msfe'].append(np.mean(np.power(results['res'], 2))) d['msfe_exp'].append(np.mean(np.power(results['res'][df['recession'] == 0], 2))) d['msfe_rec'].append(np.mean(np.power(results['res'][df['recession'] == 1], 2))) d['sq bias'].append(np.power(np.mean(results['res']), 2)) d['rem term'].append(d['msfe'][-1] - d['sq bias'][-1]) d['r2'].append((1 - d['msfe'][-1] / ha_msfe) * 100) d['r2_exp'].append((1 - d['msfe_exp'][-1] / ha_msfe_exp) * 100) d['r2_rec'].append((1 - d['msfe_rec'][-1] / ha_msfe_rec) * 100) y = df['log_equity_premium'][beg_date_oos:end_date_oos] cw_stat = perform_cw_test(y, ha_forecast[beg_date_oos:end_date_oos], results['y_forecast']) d['msfe_adj'].append(cw_stat['MSPE_adj']) d['p_value'].append(cw_stat['p_value'])
# initialize dictionary of lists d = {} for i in ['CER', 'CER_exp', 'CER_rec', 'Sharpe ratio', 'rel turnover', 'CER w/tc', 'Sharpe w/tc']: d[i] = [] # lag the x variables df[var_list] = df[var_list].shift(1) # to match NRZ, increment beg_date_init by one month beg_date_init = '1951-01' #var_list = ['dp', 'dy', 'ep'] for x_var in var_list: prediction = oos_forecast('equity_premium', x_var, df, beg_date_init, beg_date_oos, end_date_oos) # no transactions costs results = perform_asset_allocation(df_sub['equity_premium']/100, df_sub['Rfree'], prediction['y_forecast']/100, df_sub['ha_var'], gamma_MV, 0) d['CER'].append((results['avg_utility'] - ha_results['avg_utility']) * 1200) d['Sharpe ratio'].append(results['SR']) d['rel turnover'].append(results['avg_turnover'] / ha_results['avg_turnover']) results_exp = perform_asset_allocation(df_exp['equity_premium']/100, df_exp['Rfree'], prediction['y_forecast'][df_sub['recession']==0]/100, df_exp['ha_var'], gamma_MV, 0) d['CER_exp'].append((results_exp['avg_utility'] - ha_results_exp['avg_utility']) * 1200) # Note: CER_rec for techical var do not match NRZ (but do match Rapah's matlab output) results_rec = perform_asset_allocation(df_rec['equity_premium']/100, df_rec['Rfree'], prediction['y_forecast'][df_sub['recession']==1]/100, df_rec['ha_var'], gamma_MV, 0)