Debian Codegraph @

tests/stochastic_simulations/example_seeds.mod

raw
1 // Example 1 from Collard's guide to Dynare
2 var y, c, k, a, h, b;
3 varexo e, u;
4
5 parameters beta, rho, alpha, delta, theta, psi, tau;
6
7 alpha = 0.36;
8 rho = 0.95;
9 tau = 0.025;
10 beta = 0.99;
11 delta = 0.025;
12 psi = 0;
13 theta = 2.95;
14
15 phi = 0.1;
16
17 model;
18 c*theta*h^(1+psi)=(1-alpha)*y;
19 k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))
20 *(exp(b(+1))*alpha*y(+1)+(1-delta)*k));
21 y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
22 k = exp(b)*(y-c)+(1-delta)*k(-1);
23 a = rho*a(-1)+tau*b(-1) + e;
24 b = tau*a(-1)+rho*b(-1) + u;
25 end;
26
27 initval;
28 y = 1.08068253095672;
29 c = 0.80359242014163;
30 h = 0.29175631001732;
31 k = 11.08360443260358;
32 a = 0;
33 b = 0;
34 e = 0;
35 u = 0;
36 end;
37
38 shocks;
39 var e; stderr 0.009;
40 var u; stderr 0.009;
41 var e, u = phi*0.009*0.009;
42 end;
43
44 stoch_simul(periods=1000,irf=0,nomoments);
45 endo_simul_1 = oo_.endo_simul;
46
47 set_dynare_seed('reset')
48 stoch_simul(periods=1000,irf=0,nomoments);
49 endo_simul_2 = oo_.endo_simul;
50
51 set_dynare_seed('default')
52 stoch_simul(periods=1000,irf=0,nomoments);
53 endo_simul_3 = oo_.endo_simul;
54
55 t1 = endo_simul_1-endo_simul_2;
56 t2 = endo_simul_1-endo_simul_3;
57
58 if any(abs(t1(:))>1e-12) || any(abs(t2(:))>1e-12)
59 disp('Test 1.')
60 error('Test failure:: Problem with the seed of the random number algorithm')
61 end
62
63 set_dynare_seed(57)
64 stoch_simul(periods=1000,irf=0,nomoments);
65 endo_simul_4 = oo_.endo_simul;
66
67 set_dynare_seed('reset')
68 stoch_simul(periods=1000,irf=0,nomoments);
69 endo_simul_5 = oo_.endo_simul;
70
71 t3 = endo_simul_4-endo_simul_5;
72
73 if any(abs(t3(:))>1e-12)
74 disp('Test 2.')
75 error('Test failure:: Problem with the seed of the random number algorithm')
76 end
77
78 set_dynare_seed('default')
79 stoch_simul(periods=1000,irf=0,nomoments);
80 endo_simul_6 = oo_.endo_simul;
81
82 t4 = endo_simul_6-endo_simul_1;
83
84 if any(abs(t4(:))>1e-12)
85 disp('Test 3.')
86 error('Test failure:: Problem with the seed of the random number algorithm')
87 end
88
89 if ~isoctave
90
91 set_dynare_seed('mlfg6331_64',0)
92 stoch_simul(periods=1000,irf=0,nomoments);
93 endo_simul_7 = oo_.endo_simul;
94
95 set_dynare_seed('reset')
96 stoch_simul(periods=1000,irf=0,nomoments);
97 endo_simul_8 = oo_.endo_simul;
98
99 t5 = endo_simul_7-endo_simul_8;
100
101 if any(abs(t5(:))>1e-12)
102 disp('Test 4.')
103 error('Test failure:: Problem with the seed of the random number algorithm')
104 end
105
106 set_dynare_seed('default')
107 stoch_simul(periods=1000,irf=0,nomoments);
108 endo_simul_9 = oo_.endo_simul;
109
110 t6 = endo_simul_9-endo_simul_1;
111
112 if any(abs(t6(:))>1e-12)
113 disp('Test 5.')
114 error('Test failure:: Problem with the seed of the random number algorithm')
115 end
116
117 end