Debian Codegraph @

tests/deterministic_simulations/pfwee.mod

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