1// Example of optimal simple rule using opt_algo=3 2var y inflation r dummy_var; 3varexo y_ inf_; 4 5parameters delta sigma alpha kappa gammax0 gammac0 gamma_y_ gamma_inf_; 6 7delta = 0.44; 8kappa = 0.18; 9alpha = 0.48; 10sigma = -0.06; 11 12 13model(linear); 14y = delta * y(-1) + (1-delta)*y(+1)+sigma *(r - inflation(+1)) + y_; 15inflation = alpha * inflation(-1) + (1-alpha) * inflation(+1) + kappa*y + inf_; 16dummy_var=0.9*dummy_var(-1)+0.01*y; 17r = gammax0*y(-1)+gammac0*inflation(-1)+gamma_y_*y_+gamma_inf_*inf_; 18end; 19 20shocks; 21var y_; 22stderr 0.63; 23var inf_; 24stderr 0.4; 25end; 26 27options_.nograph=1; 28options_.nocorr=1; 29osr_params gammax0 gammac0 gamma_y_ gamma_inf_; 30 31 32optim_weights; 33inflation 1; 34y 1; 35dummy_var 1; 36end; 37 38 39gammax0 = 0.2; 40gammac0 = 1.5; 41gamma_y_ = 8; 42gamma_inf_ = 3; 43 44osr(opt_algo=9); 45%compute objective function manually 46objective=oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'))+oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+oo_.var(strmatch('dummy_var',M_.endo_names,'exact'),strmatch('dummy_var',M_.endo_names,'exact')); 47 48if abs(oo_.osr.objective_function-objective)>1e-8 49 error('Objective Function is wrong') 50end 51 52%redo computation with covariance specified 53optim_weights; 54inflation 1; 55y 1; 56dummy_var 1; 57y,inflation 0.5; 58end; 59 60osr; 61%compute objective function manually 62objective=oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'))+oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+oo_.var(strmatch('dummy_var',M_.endo_names,'exact'),strmatch('dummy_var',M_.endo_names,'exact'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact')); 63if abs(oo_.osr.objective_function-objective)>1e-8 64 error('Objective Function is wrong') 65end 66 67gammax0=1.35533; 68gammac0=1.39664; 69gamma_y_=16.6667; 70gamma_inf_=9.13199; 71 72%redo computation with double weight on one covariance 73optim_weights; 74inflation 1; 75y 1; 76dummy_var 1; 77y,inflation 1; 78end; 79 80osr; 81%compute objective function manually 82objective=oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'))+oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+oo_.var(strmatch('dummy_var',M_.endo_names,'exact'),strmatch('dummy_var',M_.endo_names,'exact'))+1*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact')); 83if abs(oo_.osr.objective_function-objective)>1e-8 84 error('Objective Function is wrong') 85end 86oo_covar_single=oo_; 87 88%redo computation with single weight on both covariances 89 90optim_weights; 91inflation 1; 92y 1; 93dummy_var 1; 94y,inflation 0.5; 95inflation,y 0.5; 96end; 97 98osr; 99%compute objective function manually 100objective=oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'))+oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+oo_.var(strmatch('dummy_var',M_.endo_names,'exact'),strmatch('dummy_var',M_.endo_names,'exact'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+0.5*oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact')); 101if abs(oo_.osr.objective_function-objective)>1e-8 102 error('Objective Function is wrong') 103end 104if abs(oo_.osr.objective_function-oo_covar_single.osr.objective_function)>1e-8 105 error('Objective Function is wrong') 106end 107if max(abs((cell2mat(struct2cell(oo_.osr.optim_params))-cell2mat(struct2cell(oo_covar_single.osr.optim_params)))./cell2mat(struct2cell(oo_.osr.optim_params))))>1e-4 108 error('Parameters should be identical') 109end 110