File: burnside.mod

package info (click to toggle)
dynare 7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,248 kB
  • sloc: cpp: 82,011; ansic: 28,583; objc: 12,573; yacc: 5,105; pascal: 2,374; lex: 1,502; python: 1,118; sh: 1,116; makefile: 605; lisp: 162; xml: 18
file content (171 lines) | stat: -rw-r--r-- 5,185 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
var y x;

varexo e;

parameters beta theta rho xbar;
xbar = 0.0179;
rho =  -0.139;
theta = -1.5;
beta = 0.95;

model;
1 = beta*exp(theta*x(+1))*(1+y(+1))/y;
x = (1-rho)*xbar + rho*x(-1)+e;
end;

shocks;
var e; stderr 0.0348;
end;

initval;
x = xbar;
y = beta*exp(theta*xbar)/(1-beta*exp(theta*xbar));
end;

resid;

steady;

check;

if beta*exp(theta*xbar+.5*theta^2*M_.Sigma_e/(1-rho)^2)>1-eps
   disp('The model doesn''t have a solution!')
   return
end

seed = 31415;

set_dynare_seed(seed);
stoch_simul(order=1,irf=0,periods=200);
e_1 = oo_.exo_simul;

set_dynare_seed(seed);
stoch_simul(order=2,irf=0,periods=200);
e_2 = oo_.exo_simul;

set_dynare_seed(seed);
stoch_simul(order=4,irf=0,periods=200);
e_4 = oo_.exo_simul;


T = 100;

options_.ep.stochastic.algo=1; // Default is to use a sparse tree

tic

options_.ep.stochastic.order = 0;
[ts0, o0] = extended_path([], T, e_1, options_, M_, oo_);

if ~o0.extended_path.status, error('EP failed'), end

options_.ep.stochastic.order = 1;
options_.ep.stochastic.IntegrationAlgorithm='Tensor-Gaussian-Quadrature';
options_.ep.stochastic.quadrature.nodes = 3;
[ts1, o1] = extended_path([], T, e_1, options_, M_, oo_);

if ~o1.extended_path.status, error('SEP(1) failed'), end

options_.ep.stochastic.order = 1;
options_.ep.stochastic.IntegrationAlgorithm='Tensor-Gaussian-Quadrature';
options_.ep.stochastic.quadrature.nodes = 3;
options_.ep.stochastic.hybrid_order = 2;
[ts1h, o1h] = extended_path([], T, e_1, options_, M_, oo_);
options_.ep.stochastic.hybrid_order = 0;

if ~o1h.extended_path.status, error('Hybrid SEP(1) failed'), end

options_.ep.stochastic.order = 2;
options_.ep.stochastic.IntegrationAlgorithm='Tensor-Gaussian-Quadrature';
options_.ep.stochastic.quadrature.nodes = 3;
[ts2, o2] = extended_path([], T, e_1, options_, M_, oo_);

if ~o2.extended_path.status, error('SEP(2) failed'), end

options_.ep.stochastic.order = 2;
options_.ep.stochastic.IntegrationAlgorithm='Tensor-Gaussian-Quadrature';
options_.ep.stochastic.quadrature.nodes = 3;
options_.ep.stochastic.algo=0; // Full tree of future innovations
[ts2__, o2full] = extended_path([], T, e_1, options_, M_, oo_);
options_.ep.stochastic.algo=1;

if ~o2full.extended_path.status,, error('SEP(2) with perfect tree failed'), end

options_.ep.stochastic.order = 2;
options_.ep.stochastic.IntegrationAlgorithm='Tensor-Gaussian-Quadrature';
options_.ep.stochastic.quadrature.nodes = 3;
options_.ep.stochastic.hybrid_order = 2;
[ts2h, o2h] = extended_path([], T, e_1, options_, M_, oo_);

if ~o2h.extended_path.status, error('Hybrid (order 2) SEP(2) failed'), end

options_.ep.stochastic.order = 2;
options_.ep.stochastic.IntegrationAlgorithm='Tensor-Gaussian-Quadrature';
options_.ep.stochastic.quadrature.nodes = 3;
options_.ep.stochastic.hybrid_order = 4;
[ts2hh, o2hh] = extended_path([], T, e_1, options_, M_, oo_);

if ~o2hh.extended_path.status, error('Hybrid (order 4) SEP(2) failed'), end

options_.ep.stochastic.order = 2;
options_.ep.stochastic.IntegrationAlgorithm='Tensor-Gaussian-Quadrature';
options_.ep.stochastic.quadrature.nodes = 3;
options_.ep.stochastic.hybrid_order = 2;
options_.ep.stochastic.algo = 0;
[ts2h__, o2hfull] = extended_path([], T, e_1, options_, M_, oo_);
options_.ep.stochastic.algo = 1;

if ~o2hfull.extended_path.status, error('Hybrid (order 2) SEP(2) with perfect tree failed'), end

toc

testresults = false;

if testresults

   saveresults = false;

   if saveresults
   save('burnside-simulations.mat', 'o0', 'o1', 'o1h', 'o2', 'o2full', 'o2h', 'o2hh', 'o2hfull')
   end

   if isfile('burnside-simulations.mat')
       simulations = load('burnside-simulations.mat');
       errorflag = false;
       if max(abs(o0.endo_simul(:)-simulations.o0.endo_simul(:)))>1e-16
           errorflag = true;
           dprintf('EP simulations are wrong.')
       end
       if max(abs(o1.endo_simul(:)-simulations.o1.endo_simul(:)))>1e-16
           errorflag = true;
           dprintf('SEP(1) simulations are wrong.')
       end
       if max(abs(o1h.endo_simul(:)-simulations.o1h.endo_simul(:)))>1e-16
           errorflag = true;
           dprintf('Hybrid SEP(1) simulations are wrong.')
       end
       if max(abs(o2.endo_simul(:)-simulations.o2.endo_simul(:)))>1e-16
           errorflag = true;
           dprintf('SEP(2) simulations are wrong.')
       end
       if max(abs(o2full.endo_simul(:)-simulations.o2full.endo_simul(:)))>1e-16
           errorflag = true;
           dprintf('SEP(2) with perfect tree simulations are wrong.')
       end
       if max(abs(o2h.endo_simul(:)-simulations.o2h.endo_simul(:)))>1e-16
           errorflag = true;
           dprintf('Hybrid SEP(2) simulations are wrong.')
       end
       if max(abs(o2hh.endo_simul(:)-simulations.o2hh.endo_simul(:)))>1e-16
           errorflag = true;
           dprintf('Hybrid (fourth order) SEP(2) simulations are wrong.')
       end
       if max(abs(o2hfull.endo_simul(:)-simulations.o2hfull.endo_simul(:)))>1e-16
           errorflag = true;
           dprintf('Hybrid SEP(2) with perfect tree simulations are wrong.')
       end
       if errorflag
           error('Some simulations do not match the expected results.')
       end
    end
end