Debian Codegraph @

tests/optimal_policy/OSR/osr_obj_corr_algo_9.mod

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