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[all_var] = df[all_var].shift(1) #______________________________________________________________________________ # to match NRZ, increment beg_date_init by one month (since we lag the X vars) beg_date_init = '1951-01' for var_list in ['pc_econ', 'pc_tech', 'pc_all']: if var_list == 'pc_econ': max_k = 3 prediction = oos_pc_forecast('equity_premium', econ_var, df, max_k, beg_date_init, beg_date_oos, end_date_oos) elif var_list == 'pc_tech': max_k = 1 prediction = oos_pc_forecast('equity_premium', tech_var, df, max_k, beg_date_init, beg_date_oos, end_date_oos) elif var_list == 'pc_all': max_k = 4 prediction = oos_pc_forecast('equity_premium', all_var, df, max_k, beg_date_init, beg_date_oos, end_date_oos) 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'])
# initialize dictionary of lists d = {} for i in ['msfe', 'msfe_exp', 'msfe_rec', 'msfe_adj', 'p_value', 'r2', 'r2_exp', 'r2_rec', 'sq bias', 'rem term']: 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' 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)))