Debian Codegraph @

tests/ep/burnside.mod

raw
1 var y x;
2
3 varexo e;
4
5 parameters beta theta rho xbar;
6 xbar = 0.0179;
7 rho = -0.139;
8 theta = -1.5;
9 beta = 0.95;
10
11 model;
12 1 = beta*exp(theta*x(+1))*(1+y(+1))/y;
13 x = (1-rho)*xbar + rho*x(-1)+e;
14 end;
15
16 shocks;
17 var e; stderr 0.0348;
18 end;
19
20 initval;
21 x = xbar;
22 y = beta*exp(theta*xbar)/(1-beta*exp(theta*xbar));
23 end;
24
25 resid;
26
27 steady;
28
29 check;
30
31 if beta*exp(theta*xbar+.5*theta^2*M_.Sigma_e/(1-rho)^2)>1-eps
32 disp('The model doesn''t have a solution!')
33 return
34 end
35
36 seed = 31415;
37
38 set_dynare_seed(seed);
39 stoch_simul(order=1,irf=0,periods=200);
40 e_1 = oo_.exo_simul;
41
42 set_dynare_seed(seed);
43 stoch_simul(order=2,irf=0,periods=200);
44 e_2 = oo_.exo_simul;
45
46 set_dynare_seed(seed);
47 stoch_simul(order=4,irf=0,periods=200);
48 e_4 = oo_.exo_simul;
49
50
51 T = 100;
52
53 options_.ep.stochastic.algo=1; // Default is to use a sparse tree
54
55 tic
56
57 options_.ep.stochastic.order = 0;
58 [ts0, o0] = extended_path([], T, e_1, options_, M_, oo_);
59
60 if ~o0.extended_path.status, error('EP failed'), end
61
62 options_.ep.stochastic.order = 1;
63 options_.ep.stochastic.IntegrationAlgorithm='Tensor-Gaussian-Quadrature';
64 options_.ep.stochastic.quadrature.nodes = 3;
65 [ts1, o1] = extended_path([], T, e_1, options_, M_, oo_);
66
67 if ~o1.extended_path.status, error('SEP(1) failed'), end
68
69 options_.ep.stochastic.order = 1;
70 options_.ep.stochastic.IntegrationAlgorithm='Tensor-Gaussian-Quadrature';
71 options_.ep.stochastic.quadrature.nodes = 3;
72 options_.ep.stochastic.hybrid_order = 2;
73 [ts1h, o1h] = extended_path([], T, e_1, options_, M_, oo_);
74 options_.ep.stochastic.hybrid_order = 0;
75
76 if ~o1h.extended_path.status, error('Hybrid SEP(1) failed'), end
77
78 options_.ep.stochastic.order = 2;
79 options_.ep.stochastic.IntegrationAlgorithm='Tensor-Gaussian-Quadrature';
80 options_.ep.stochastic.quadrature.nodes = 3;
81 [ts2, o2] = extended_path([], T, e_1, options_, M_, oo_);
82
83 if ~o2.extended_path.status, error('SEP(2) failed'), end
84
85 options_.ep.stochastic.order = 2;
86 options_.ep.stochastic.IntegrationAlgorithm='Tensor-Gaussian-Quadrature';
87 options_.ep.stochastic.quadrature.nodes = 3;
88 options_.ep.stochastic.algo=0; // Full tree of future innovations
89 [ts2__, o2full] = extended_path([], T, e_1, options_, M_, oo_);
90 options_.ep.stochastic.algo=1;
91
92 if ~o2full.extended_path.status,, error('SEP(2) with perfect tree failed'), end
93
94 options_.ep.stochastic.order = 2;
95 options_.ep.stochastic.IntegrationAlgorithm='Tensor-Gaussian-Quadrature';
96 options_.ep.stochastic.quadrature.nodes = 3;
97 options_.ep.stochastic.hybrid_order = 2;
98 [ts2h, o2h] = extended_path([], T, e_1, options_, M_, oo_);
99
100 if ~o2h.extended_path.status, error('Hybrid (order 2) SEP(2) failed'), end
101
102 options_.ep.stochastic.order = 2;
103 options_.ep.stochastic.IntegrationAlgorithm='Tensor-Gaussian-Quadrature';
104 options_.ep.stochastic.quadrature.nodes = 3;
105 options_.ep.stochastic.hybrid_order = 4;
106 [ts2hh, o2hh] = extended_path([], T, e_1, options_, M_, oo_);
107
108 if ~o2hh.extended_path.status, error('Hybrid (order 4) SEP(2) failed'), end
109
110 options_.ep.stochastic.order = 2;
111 options_.ep.stochastic.IntegrationAlgorithm='Tensor-Gaussian-Quadrature';
112 options_.ep.stochastic.quadrature.nodes = 3;
113 options_.ep.stochastic.hybrid_order = 2;
114 options_.ep.stochastic.algo = 0;
115 [ts2h__, o2hfull] = extended_path([], T, e_1, options_, M_, oo_);
116 options_.ep.stochastic.algo = 1;
117
118 if ~o2hfull.extended_path.status, error('Hybrid (order 2) SEP(2) with perfect tree failed'), end
119
120 toc
121
122 testresults = false;
123
124 if testresults
125
126 saveresults = false;
127
128 if saveresults
129 save('burnside-simulations.mat', 'o0', 'o1', 'o1h', 'o2', 'o2full', 'o2h', 'o2hh', 'o2hfull')
130 end
131
132 if isfile('burnside-simulations.mat')
133 simulations = load('burnside-simulations.mat');
134 errorflag = false;
135 if max(abs(o0.endo_simul(:)-simulations.o0.endo_simul(:)))>1e-16
136 errorflag = true;
137 dprintf('EP simulations are wrong.')
138 end
139 if max(abs(o1.endo_simul(:)-simulations.o1.endo_simul(:)))>1e-16
140 errorflag = true;
141 dprintf('SEP(1) simulations are wrong.')
142 end
143 if max(abs(o1h.endo_simul(:)-simulations.o1h.endo_simul(:)))>1e-16
144 errorflag = true;
145 dprintf('Hybrid SEP(1) simulations are wrong.')
146 end
147 if max(abs(o2.endo_simul(:)-simulations.o2.endo_simul(:)))>1e-16
148 errorflag = true;
149 dprintf('SEP(2) simulations are wrong.')
150 end
151 if max(abs(o2full.endo_simul(:)-simulations.o2full.endo_simul(:)))>1e-16
152 errorflag = true;
153 dprintf('SEP(2) with perfect tree simulations are wrong.')
154 end
155 if max(abs(o2h.endo_simul(:)-simulations.o2h.endo_simul(:)))>1e-16
156 errorflag = true;
157 dprintf('Hybrid SEP(2) simulations are wrong.')
158 end
159 if max(abs(o2hh.endo_simul(:)-simulations.o2hh.endo_simul(:)))>1e-16
160 errorflag = true;
161 dprintf('Hybrid (fourth order) SEP(2) simulations are wrong.')
162 end
163 if max(abs(o2hfull.endo_simul(:)-simulations.o2hfull.endo_simul(:)))>1e-16
164 errorflag = true;
165 dprintf('Hybrid SEP(2) with perfect tree simulations are wrong.')
166 end
167 if errorflag
168 error('Some simulations do not match the expected results.')
169 end
170 end
171 end