Debian Codegraph @

tests/minimal_state_space_system/as2007_minimal.mod

raw
1 % this is the Smets and Wouters (2007) model for which Komunjer and Ng (2011)
2 % derived the minimal state space system. In Dynare, however, we use more
3 % powerful minreal function
4 % created by Willi Mutschler (@wmutschl, [email protected])
5 % =========================================================================
6 % Copyright © 2020 Dynare Team
7 %
8 % This file is part of Dynare.
9 %
10 % Dynare is free software: you can redistribute it and/or modify
11 % it under the terms of the GNU General Public License as published by
12 % the Free Software Foundation, either version 3 of the License, or
13 % (at your option) any later version.
14 %
15 % Dynare is distributed in the hope that it will be useful,
16 % but WITHOUT ANY WARRANTY; without even the implied warranty of
17 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 % GNU General Public License for more details.
19 %
20 % You should have received a copy of the GNU General Public License
21 % along with Dynare. If not, see <https://www.gnu.org/licenses/>.
22 % =========================================================================
23
24 var y R g z c dy p YGR INFL INT;
25 varobs y R p c YGR INFL INT;
26 varexo e_r e_g e_z;
27 parameters tau phi psi1 psi2 rhor rhog rhoz rrst pist gamst nu cyst;
28
29 rrst = 1.0000;
30 pist = 3.2000;
31 gamst= 0.5500;
32 tau = 2.0000;
33 nu = 0.1000;
34 kap = 0.3300;
35 phi = tau*(1-nu)/nu/kap/exp(pist/400)^2;
36 cyst = 0.8500;
37 psi1 = 1.5000;
38 psi2 = 0.1250;
39 rhor = 0.7500;
40 rhog = 0.9500;
41 rhoz = 0.9000;
42
43
44 model;
45 #pist2 = exp(pist/400);
46 #rrst2 = exp(rrst/400);
47 #bet = 1/rrst2;
48 #gst = 1/cyst;
49 #cst = (1-nu)^(1/tau);
50 #yst = cst*gst;
51 1 = exp(-tau*c(+1)+tau*c+R-z(+1)-p(+1));
52 (1-nu)/nu/phi/(pist2^2)*(exp(tau*c)-1) = (exp(p)-1)*((1-1/2/nu)*exp(p)+1/2/nu) - bet*(exp(p(+1))-1)*exp(-tau*c(+1)+tau*c+dy(+1)+p(+1));
53 exp(c-y) = exp(-g) - phi*pist2^2*gst/2*(exp(p)-1)^2;
54 R = rhor*R(-1) + (1-rhor)*psi1*p + (1-rhor)*psi2*(y-g) + e_r;
55 g = rhog*g(-1) + e_g;
56 z = rhoz*z(-1) + e_z;
57 YGR = gamst+100*(dy+z);
58 INFL = pist+400*p;
59 INT = pist+rrst+4*gamst+400*R;
60 dy = y - y(-1);
61 end;
62
63 shocks;
64 var e_r; stderr 0.2/100;
65 var e_g; stderr 0.6/100;
66 var e_z; stderr 0.3/100;
67 end;
68
69 steady_state_model;
70 z=0; g=0; c=0; y=0; p=0; R=0; dy=0;
71 YGR=gamst; INFL=pist; INT=pist+rrst+4*gamst;
72 end;
73 stoch_simul(order=1,irf=0,periods=0);
74 options_.qz_criterium = 1;
75
76 indx = [M_.nstatic+(1:M_.nspred)]';
77 indy = 1:M_.endo_nbr';
78
79 SS.A = oo_.dr.ghx(indx,:);
80 SS.B = oo_.dr.ghu(indx,:);
81 SS.C = oo_.dr.ghx(indy,:);
82 SS.D = oo_.dr.ghu(indy,:);
83
84 [CheckCO,minnx,minSS] = identification.get_minimal_state_representation(SS,0);
85
86 Sigmax_full = lyapunov_symm(SS.A, SS.B*M_.Sigma_e*SS.B', options_.lyapunov_fixed_point_tol, options_.qz_criterium, options_.lyapunov_complex_threshold, 1, options_.debug);
87 Sigmay_full = SS.C*Sigmax_full*SS.C' + SS.D*M_.Sigma_e*SS.D';
88
89 Sigmax_min = lyapunov_symm(minSS.A, minSS.B*M_.Sigma_e*minSS.B', options_.lyapunov_fixed_point_tol, options_.qz_criterium, options_.lyapunov_complex_threshold, 1, options_.debug);
90 Sigmay_min = minSS.C*Sigmax_min*minSS.C' + minSS.D*M_.Sigma_e*minSS.D';
91
92 ([Sigmay_full(:) - Sigmay_min(:)]')
93 sqrt(([diag(Sigmay_full), diag(Sigmay_min)]'))
94 dx = norm( Sigmay_full - Sigmay_min, Inf);
95 if dx > 1e-12
96 error('something wrong with minimal state space computations')
97 else
98 fprintf('numerical error for moments computed from minimal state system is %d\n',dx)
99 end
100