Debian Codegraph @

tests/model-inversion/bk-9/msm2.mod

raw
1 // --+ options: stochastic +--
2
3 /* © 2022 Dynare Team
4 *
5 * This file is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * It is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with the file. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 @#define linearproblem = 0
20
21 var y1 y2 y3 ;
22
23 varexo e1 e2 e3 ;
24
25 parameters a b c ;
26
27 a = .1;
28 b = .2;
29 c = .3;
30
31 model;
32
33 @#if linearproblem
34
35 y1 = .5*y2 + y3 + e1 ;
36
37 y2 = 1 + y1 + e2 ;
38
39 y3 = e3;
40
41 @#else
42
43 y1 = y2*y3+exp(e1) ;
44
45 y2 = 1 + y1*exp(e2) ;
46
47 y3 = e3 ;
48
49 @#endif
50
51 end;
52
53 shocks;
54 var e1 = .01;
55 var e2 = .01;
56 var e3 = .02;
57 end;
58
59 TrueData = simul_static_model(1000);
60
61 // Set the periods where some of the endogenous variables will be constrained.
62 initperiod = 501Y;
63 lastperiod = 600Y;
64 subsample = initperiod:lastperiod;
65
66 // Load the generated data
67 SimulatedData = copy(TrueData);
68
69 // Set the constrained paths for the endogenous variables.
70 constrainedpaths = SimulatedData{'y1','y2','y3'}(subsample);
71
72 // Set the instruments (innovations used to control the paths for the endogenous variables).
73 exogenousvariables = dseries([NaN(100, 3)], initperiod, M_.exo_names);
74
75 /* REMARK
76 **
77 ** Here we will control y1, y2, and y3 with e1, e2 and e3.
78 **
79 */
80
81 // Invert the model by calling the model_inversion routine.
82 options_.dynatol.f = 1e-9;
83 [endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, [], M_, options_, oo_);
84
85 // Check that all the constraints are satisfied.
86 if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
87 error('Constraint on y1 path is not satisfied!')
88 end
89
90 if max(abs(constrainedpaths(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
91 error('Constraint on y2 path is not satisfied!')
92 end
93
94 if max(abs(constrainedpaths(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
95 error('Constraint on y3 path is not satisfied!')
96 end
97
98 // Check consistency of the results.
99 if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-8
100 dprintf('Model inversion is not consistent with true innovations (e1)')
101 end
102
103 if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-8
104 dprintf('Model inversion is not consistent with true innovations (e2)')
105 end
106
107 if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-8
108 dprintf('Model inversion is not consistent with true innovations (e3)')
109 end
110
111 TrueData2 = simul_static_model(100, exogenousvariables(subsample));
112
113 if max(abs(TrueData2(subsample).y1.data-TrueData(subsample).y1.data))>1e-5
114 error('Model inversion is wrong.')
115 end