Debian Codegraph @

tests/optimal_policy/OSR/osr_obj_corr_algo_7.mod

raw
1 // Example of optimal simple rule using opt_algo=2
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 if ~isoctave
45 osr(opt_algo=7,silent_optimizer,order=1);
46 %compute objective function manually
47 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'));
48
49 if abs(oo_.osr.objective_function-objective)>1e-8
50 error('Objective Function is wrong')
51 end
52
53 %redo computation with covariance specified
54 optim_weights;
55 inflation 1;
56 y 1;
57 dummy_var 1;
58 y,inflation 0.5;
59 end;
60
61 osr(silent_optimizer,order=1);
62 %compute objective function manually
63 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'));
64 if abs(oo_.osr.objective_function-objective)>1e-8
65 error('Objective Function is wrong')
66 end
67
68 gammax0=1.35533;
69 gammac0=1.39664;
70 gamma_y_=16.6667;
71 gamma_inf_=9.13199;
72
73 %redo computation with double weight on one covariance
74 optim_weights;
75 inflation 1;
76 y 1;
77 dummy_var 1;
78 y,inflation 1;
79 end;
80
81 osr(silent_optimizer,order=1);
82 %compute objective function manually
83 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'));
84 if abs(oo_.osr.objective_function-objective)>1e-8
85 error('Objective Function is wrong')
86 end
87 oo_covar_single=oo_;
88
89 %redo computation with single weight on both covariances
90
91 optim_weights;
92 inflation 1;
93 y 1;
94 dummy_var 1;
95 y,inflation 0.5;
96 inflation,y 0.5;
97 end;
98
99 osr(silent_optimizer,order=1);
100 %compute objective function manually
101 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'));
102 if abs(oo_.osr.objective_function-objective)>1e-8
103 error('Objective Function is wrong')
104 end
105 if abs(oo_.osr.objective_function-oo_covar_single.osr.objective_function)>1e-8
106 error('Objective Function is wrong')
107 end
108 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
109 error('Parameters should be identical')
110 end
111 end