Debian Codegraph @

tests/deterministic_simulations/pfwee_constant_sim_length.mod

raw
1 // Tests perfect_foresight_with_expectation_errors_{setup,solver} with constant_simulation_length option
2
3 var c k;
4 varexo x;
5
6 parameters alph gam delt bet aa;
7 alph=0.5;
8 gam=0.5;
9 delt=0.02;
10 bet=0.05;
11 aa=0.5;
12
13
14 model;
15 c + k - aa*x*k(-1)^alph - (1-delt)*k(-1);
16 c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);
17 end;
18
19 initval;
20 x = 1;
21 k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1));
22 c = aa*k^alph-delt*k;
23 end;
24
25 steady;
26
27 check;
28
29 // Save initial steady state (it will be modified by pfwee)
30 orig_steady_state = oo_.steady_state;
31 orig_exo_steady_state = oo_.exo_steady_state;
32
33 perfect_foresight_with_expectation_errors_setup(periods = 7, datafile = 'pfwee.csv');
34
35 perfect_foresight_with_expectation_errors_solver(constant_simulation_length);
36 pfwee_simul = oo_.endo_simul;
37
38 // Now compute the solution by hand to verify the results
39 verbatim;
40
41 oo_.steady_state = orig_steady_state;
42 oo_.exo_steady_state = orig_exo_steady_state;
43
44 oo_ = make_ex_(M_,options_,oo_);
45 oo_ = make_y_(M_,options_,oo_);
46
47 % Information arriving in period 1 (temp shock now)
48 oo_.exo_simul(2,1) = 1.2;
49 oo_=perfect_foresight_solver(M_, options_, oo_);
50
51 % Information arriving in period 2 (temp shock now + permanent shock in future)
52 oo_.exo_simul(3,1) = 1.3;
53 oo_.exo_steady_state = 1.1;
54 oo_.exo_simul(9:10, 1) = repmat(oo_.exo_steady_state', 2, 1);
55 oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true);
56 oo_.endo_simul(:, 10) = oo_.steady_state;
57 saved_endo = oo_.endo_simul(:, 1);
58 saved_exo = oo_.exo_simul(1, :);
59 oo_.endo_simul = oo_.endo_simul(:, 2:end);
60 oo_.exo_simul = oo_.exo_simul(2:end, :);
61 oo_=perfect_foresight_solver(M_, options_, oo_);
62 oo_.endo_simul = [ saved_endo oo_.endo_simul ];
63 oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
64
65 % Information arriving in period 3 (temp shock now + permanent shock in future)
66 oo_.exo_simul(4,1) = 1.4;
67 oo_.exo_steady_state = 1.2;
68 oo_.exo_simul(9:11, 1) = repmat(oo_.exo_steady_state', 3, 1);
69 oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true);
70 oo_.endo_simul(:, 11) = oo_.steady_state;
71 saved_endo = oo_.endo_simul(:, 1:2);
72 saved_exo = oo_.exo_simul(1:2, :);
73 oo_.endo_simul = oo_.endo_simul(:, 3:end);
74 oo_.exo_simul = oo_.exo_simul(3:end, :);
75 oo_=perfect_foresight_solver(M_, options_, oo_);
76 oo_.endo_simul = [ saved_endo oo_.endo_simul ];
77 oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
78
79 % Information arriving in period 6 (permanent shock arriving now)
80 oo_.exo_simul(7,1) = 1.1;
81 oo_.exo_simul(8,1) = 1.1;
82 oo_.exo_steady_state = 1.1;
83 oo_.exo_simul(9:14, 1) = repmat(oo_.exo_steady_state', 6, 1);
84 oo_.endo_simul(:, 12:13) = repmat(oo_.steady_state, 1, 2);
85 oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true);
86 oo_.endo_simul(:, 14) = oo_.steady_state;
87 saved_endo = oo_.endo_simul(:, 1:5);
88 saved_exo = oo_.exo_simul(1:5, :);
89 oo_.endo_simul = oo_.endo_simul(:, 6:end);
90 oo_.exo_simul = oo_.exo_simul(6:end, :);
91 oo_=perfect_foresight_solver(M_, options_, oo_);
92 oo_.endo_simul = [ saved_endo oo_.endo_simul ];
93 oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
94
95 % We should have strict equality with first pfwee simulation, because algorithm
96 % and guess values are exactly the same.
97 if any(any(pfwee_simul-oo_.endo_simul ~= 0))
98 error('Error in perfect_foresight_with_expectation_errors')
99 end
100
101 end; // verbatim