Debian Codegraph @

tests/block_bytecode/ls2003.mod

raw
1 /*
2 The model in this file is used to test all combinations of algorithms with
3 block and bytecode options.
4
5 It is designed is such a way that it includes the 8 possible types of blocks:
6 – Solve {forward, backward, two boundaries} {simple, complete}
7 – Evaluate {forward, backward}
8
9 All the “Solve” blocks are also present in both linear and nonlinear forms
10 (since the codepaths are typically different depending on the linearity of
11 the block).
12
13 Note that there is no such thing as a nonlinear “Evaluate” block, since the
14 endogenous variables of the block always enter linearly (on the LHS).
15 */
16
17 var y y_s R pie dq pie_s de A;
18 var eb sfc1 sfc2 sbc1 sbc2 sbc3 stbs sfs sbs;
19 var nsfc1 nsfc2 nsbc1 nsbc2 nsbc3 nstbs nsfs nsbs;
20 var nstbc_c nstbc_y nstbc_k nstbc_h;
21
22 varexo e_R e_q e_ys e_pies e_A;
23 varexo e_eb e_sfc1 e_sfc2 e_sbc e_stbs e_sbs e_sfs;
24 varexo e_nsfc1 e_nsfc2 e_nsbc e_nstbs e_nsbs e_nsfs;
25 varexo e_nstbc;
26
27 parameters psi1 psi2 psi3 rho_R tau alpha rr k rho_q rho_A rho_ys rho_pies;
28 parameters nstbc_beta nstbc_alpha nstbc_delta nstbc_theta nstbc_psi;
29
30 psi1 = 1.54;
31 psi2 = 0.25;
32 psi3 = 0.25;
33 rho_R = 0.5;
34 alpha = 0.3;
35 rr = 2.51;
36 k = 0.5;
37 tau = 0.5;
38 rho_q = 0.4;
39 rho_A = 0.2;
40 rho_ys = 0.9;
41 rho_pies = 0.7;
42
43 nstbc_alpha = 0.36;
44 nstbc_beta = 0.99;
45 nstbc_delta = 0.025;
46 nstbc_psi = 0;
47 nstbc_theta = 2.95;
48
49
50 @#if block
51 model_options(block);
52 @#endif
53 @#if bytecode
54 model_options(bytecode);
55 @#endif
56 @#if use_dll
57 model_options(use_dll);
58 @#endif
59
60 model;
61 // Block of type “Solve two boundaries complete” (linear)
62 y = y(+1) - (tau +alpha*(2-alpha)*(1-tau))*(R-pie(+1))-alpha*(tau +alpha*(2-alpha)*(1-tau))*dq(+1) + alpha*(2-alpha)*((1-tau)/tau)*(y_s-y_s(+1))-A(+1);
63 pie = exp(-rr/400)*pie(+1)+alpha*exp(-rr/400)*dq(+1)-alpha*dq+(k/(tau+alpha*(2-alpha)*(1-tau)))*y+alpha*(2-alpha)*(1-tau)/(tau*(tau+alpha*(2-alpha)*(1-tau)))*y_s;
64 pie = de+(1-alpha)*dq+pie_s;
65 R = rho_R*R(-1)+(1-rho_R)*(psi1*pie+psi2*(y+alpha*(2-alpha)*((1-tau)/tau)*y_s)+psi3*de)+e_R;
66
67 // Block of type “Evaluate forward”
68 dq = rho_q*dq(-1)+e_q;
69 y_s = rho_ys*y_s(-1)+e_ys;
70 pie_s = rho_pies*pie_s(-1)+e_pies;
71 A = rho_A*A(-1)+e_A;
72
73 // Block of type “Solve forward complete” (linear)
74 sfc1 = 0.2*sfc2+0.5*sfc1(-1)+e_sfc1;
75 sfc2 = 0.1*sfc1+0.5*sfc2(-1)+e_sfc2;
76
77 // Block of type “Solve backward complete” (linear)
78 sbc1 = sbc1(1)-0.5*(sbc3-sbc2(1))+e_sbc;
79 sbc2 = 0.1*sbc1 + 0.9*sbc2(1);
80 sbc3 = 1.5*sbc2+0.5*sbc1;
81
82 // Block of type “Evaluate backward”, see #1727
83 eb = 0.9*eb(+1) + e_eb;
84
85 // Block of type “Solve two boundaries simple” (linear)
86 stbs - 0.8*stbs(-1) = 0.9*(stbs(+1)-0.8*stbs) + e_stbs;
87
88 // Block of type “Solve backward simple” (linear)
89 // NB: The LHS is deliberately not a single variable, otherwise is would be classified as “Evaluate backward”
90 sbs - 0.8*sbs(1) = e_sbs;
91
92 // Block of type “Solve forward simple” (linear)
93 // NB: The LHS is deliberately not a single variable, otherwise is would be classified as “Evaluate forward”
94 sfs - 0.8*sfs(-1) = e_sfs;
95
96
97 // Block of type “Solve forward complete” (nonlinear)
98 log(nsfc1) = 0.2*log(nsfc2)+0.5*log(nsfc1(-1))+e_nsfc1;
99 log(nsfc2) = 0.1*log(nsfc1)+0.5*log(nsfc2(-1))+e_nsfc2;
100
101 // Block of type “Solve backward complete” (nonlinear)
102 log(nsbc1) = log(nsbc1(1))-0.5*(log(nsbc3)-log(nsbc2(1)))+e_nsbc;
103 log(nsbc2) = 0.1*log(nsbc1) + 0.9*log(nsbc2(1));
104 log(nsbc3) = 1.5*log(nsbc2)+0.5*log(nsbc1);
105
106 // Block of type “Solve two boundaries simple” (nonlinear)
107 log(nstbs) - 0.8*log(nstbs(-1)) = 0.9*(log(nstbs(+1))-0.8*log(nstbs)) + e_nstbs;
108
109 // Block of type “Solve backward simple” (nonlinear)
110 log(nsbs) = 0.8*log(nsbs(1)) + e_nsbs;
111
112 // Block of type “Solve forward simple” (nonlinear)
113 log(nsfs) = 0.8*log(nsfs(-1)) + e_nsfs;
114
115 // Block of type “Solve two boundaries complete” (nonlinear)
116 // NB: This is a variation of example1.mod
117 nstbc_c*nstbc_theta*nstbc_h^(1+nstbc_psi)=(1-nstbc_alpha)*nstbc_y;
118 nstbc_k = nstbc_beta*(((exp(e_nstbc)*nstbc_c)/(exp(e_nstbc(+1))*nstbc_c(+1)))*(exp(e_nstbc(+1))*nstbc_alpha*nstbc_y(+1)+(1-nstbc_delta)*nstbc_k));
119 nstbc_y = (nstbc_k(-1)^nstbc_alpha)*(nstbc_h^(1-nstbc_alpha));
120 nstbc_k = exp(e_nstbc)*(nstbc_y-nstbc_c)+(1-nstbc_delta)*nstbc_k(-1);
121 end;
122
123 initval;
124 nsfc1=1;
125 nsfc2=1;
126 nsbc1=1;
127 nsbc2=1;
128 nsbc3=1;
129 nstbs=1;
130 nsfs=1;
131 nsbs=1;
132 nstbc_y = 1.1;
133 nstbc_c = 0.8;
134 nstbc_h = 0.3;
135 nstbc_k = 11.1;
136 end;
137
138 steady(solve_algo = @{solve_algo}, tolf = 1e-11);
139
140 @#if block
141 model_info;
142 @#endif
143
144 @#if bytecode
145 print_bytecode_static_model;
146 print_bytecode_dynamic_model;
147 @#endif
148
149 check;
150
151 shocks;
152 var e_R;
153 periods 3;
154 values 0.01;
155
156 var e_q;
157 periods 1;
158 values 0.5;
159
160 var e_eb;
161 periods 19;
162 values 1;
163
164 var e_sfc1;
165 periods 9;
166 values 0.2;
167
168 var e_sfc2;
169 periods 12;
170 values -0.4;
171
172 var e_sbc;
173 periods 17 18;
174 values 0.3 -0.1;
175
176 var e_stbs;
177 periods 15;
178 values -0.15;
179
180 var e_sbs;
181 periods 5;
182 values 0.2;
183
184 var e_sfs;
185 periods 7;
186 values -0.2;
187
188 var e_nsfc1;
189 periods 9;
190 values 0.2;
191
192 var e_nsfc2;
193 periods 12;
194 values -0.4;
195
196 var e_nsbc;
197 periods 17 18;
198 values 0.3 -0.1;
199
200 var e_nstbs;
201 periods 15;
202 values -0.15;
203
204 var e_nsbs;
205 periods 5;
206 values 0.2;
207
208 var e_nsfs;
209 periods 7;
210 values -0.2;
211
212 var e_nstbc;
213 periods 3;
214 values 0.009;
215 end;
216
217 perfect_foresight_setup(periods=20);
218 perfect_foresight_solver(no_homotopy, stack_solve_algo = @{stack_solve_algo}
219 @#if length(preconditioner) > 0
220 , preconditioner = @{preconditioner}
221 @#endif
222 @#if preconditioner == "block_diagonal_lu"
223 @# if !(block && stack_solve_algo == 3)
224 // Ensure that problem is not too small for block_diagonal_lu, and also that there is a “residual” in the block diagonal matrix (since 3 does not divide 20)
225 , block_diagonal_lu_nperiods = 3
226 @# else
227 // For some reason block_diagonal_lu can’t solve this model with block decomposition + BiCGStab
228 // Hence do the equivalent of a full LU
229 , block_diagonal_lu_nperiods = 20
230 @# endif
231 @#endif
232 );