| 1 |
/* Tests perfect_foresight_with_expectation_errors_{setup,solver} |
| 2 |
using the shocks(learnt_in=…), mshocks(learnt_in=…) and endval(learnt_in=…) syntax |
| 3 |
with dates (instead of integer indices) for periods */ |
| 4 |
|
| 5 |
var c k; |
| 6 |
varexo x; |
| 7 |
|
| 8 |
parameters alph gam delt bet aa; |
| 9 |
alph=0.5; |
| 10 |
gam=0.5; |
| 11 |
delt=0.02; |
| 12 |
bet=0.05; |
| 13 |
aa=0.5; |
| 14 |
|
| 15 |
|
| 16 |
model; |
| 17 |
c + k - aa*x*k(-1)^alph - (1-delt)*k(-1); |
| 18 |
c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam); |
| 19 |
end; |
| 20 |
|
| 21 |
initval; |
| 22 |
x = 1; |
| 23 |
k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1)); |
| 24 |
c = aa*k^alph-delt*k; |
| 25 |
end; |
| 26 |
|
| 27 |
steady; |
| 28 |
|
| 29 |
check; |
| 30 |
|
| 31 |
// p contains period indices, either as integer or as dates |
| 32 |
@#if dates |
| 33 |
@# define p = ["2018Y", "2019Y", "2020Y", "2021Y", "2022Y", "2023Y", "2024Y", "2025Y" ] |
| 34 |
@#else |
| 35 |
@# define p = 1:8 |
| 36 |
@#endif |
| 37 |
|
| 38 |
@#if bare_first_info_period |
| 39 |
shocks; |
| 40 |
@#else |
| 41 |
shocks(learnt_in = @{p[1]}); |
| 42 |
@#endif |
| 43 |
var x; |
| 44 |
periods @{p[1]}:@{p[2]}; |
| 45 |
values 1.2; |
| 46 |
end; |
| 47 |
|
| 48 |
@#if bare_first_info_period |
| 49 |
endval; |
| 50 |
@#else |
| 51 |
endval(learnt_in = @{p[1]}); |
| 52 |
@#endif |
| 53 |
x = 1.05; |
| 54 |
end; |
| 55 |
|
| 56 |
shocks(learnt_in = @{p[2]}); |
| 57 |
var x; |
| 58 |
periods @{p[2]}; |
| 59 |
add 0.1; |
| 60 |
end; |
| 61 |
|
| 62 |
endval(learnt_in = @{p[2]}); |
| 63 |
x = 1.1; |
| 64 |
end; |
| 65 |
|
| 66 |
shocks(learnt_in = @{p[3]}); |
| 67 |
var x; |
| 68 |
periods @{p[3]}; |
| 69 |
values 1.4; |
| 70 |
end; |
| 71 |
|
| 72 |
mshocks(learnt_in = @{p[3]}); |
| 73 |
var x; |
| 74 |
periods @{p[7]}; |
| 75 |
values (1.5/1.2); // 1.2 is the terminal steady as anticipated in period 3 |
| 76 |
end; |
| 77 |
|
| 78 |
endval(learnt_in = @{p[3]}); |
| 79 |
x += 0.1; |
| 80 |
end; |
| 81 |
|
| 82 |
// Dummy block, that will be overwritten by the next one |
| 83 |
shocks(learnt_in = @{p[6]}); |
| 84 |
var x; |
| 85 |
periods @{p[6]}:@{p[8]}; |
| 86 |
values 10; |
| 87 |
end; |
| 88 |
|
| 89 |
shocks(learnt_in = @{p[6]}, overwrite); |
| 90 |
var x; |
| 91 |
periods @{p[6]}:@{p[7]}; |
| 92 |
multiply 0.8; |
| 93 |
end; |
| 94 |
|
| 95 |
endval(learnt_in = @{p[6]}); |
| 96 |
x *= 0.75; |
| 97 |
end; |
| 98 |
|
| 99 |
// Save initial steady state (it will be modified by pfwee) |
| 100 |
orig_steady_state = oo_.steady_state; |
| 101 |
orig_exo_steady_state = oo_.exo_steady_state; |
| 102 |
|
| 103 |
perfect_foresight_with_expectation_errors_setup( |
| 104 |
@#if dates |
| 105 |
first_simulation_period = 2018Y, last_simulation_period = 2024Y |
| 106 |
@#else |
| 107 |
periods = 7 |
| 108 |
@#endif |
| 109 |
); |
| 110 |
|
| 111 |
perfect_foresight_with_expectation_errors_solver; |
| 112 |
pfwee_simul = oo_.endo_simul; |
| 113 |
|
| 114 |
// Now compute the solution by hand to verify the results |
| 115 |
verbatim; |
| 116 |
|
| 117 |
oo_.steady_state = orig_steady_state; |
| 118 |
oo_.exo_steady_state = orig_exo_steady_state; |
| 119 |
|
| 120 |
oo_ = make_ex_(M_,options_,oo_); |
| 121 |
oo_ = make_y_(M_,options_,oo_); |
| 122 |
|
| 123 |
@#if dates |
| 124 |
% Reset {first,last}_simulation_period since we’re going to manipulate options_.periods |
| 125 |
options_.simul.first_simulation_period = dates(); |
| 126 |
options_.simul.last_simulation_period = dates(); |
| 127 |
options_.periods = 7; |
| 128 |
@#endif |
| 129 |
|
| 130 |
% Information arriving in period 1 (temp shock now and tomorrow + permanent shock in future) |
| 131 |
oo_.exo_simul(2:3,1) = 1.2; |
| 132 |
oo_.exo_simul(4:end,1) = 1.05; |
| 133 |
oo_.exo_steady_state = 1.05; |
| 134 |
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true); |
| 135 |
oo_.endo_simul(:, end) = oo_.steady_state; |
| 136 |
oo_=perfect_foresight_solver(M_, options_, oo_); |
| 137 |
|
| 138 |
% Information arriving in period 2 (temp shock now + permanent shock in future) |
| 139 |
oo_.exo_simul(3,1) = 1.3; |
| 140 |
oo_.exo_steady_state = 1.1; |
| 141 |
oo_.exo_simul(4:end, 1) = oo_.exo_steady_state; |
| 142 |
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true); |
| 143 |
oo_.endo_simul(:, end) = oo_.steady_state; |
| 144 |
options_.periods = 6; |
| 145 |
saved_endo = oo_.endo_simul(:, 1); |
| 146 |
saved_exo = oo_.exo_simul(1, :); |
| 147 |
oo_.endo_simul = oo_.endo_simul(:, 2:end); |
| 148 |
oo_.exo_simul = oo_.exo_simul(2:end, :); |
| 149 |
oo_=perfect_foresight_solver(M_, options_, oo_); |
| 150 |
oo_.endo_simul = [ saved_endo oo_.endo_simul ]; |
| 151 |
oo_.exo_simul = [ saved_exo; oo_.exo_simul ]; |
| 152 |
|
| 153 |
% Information arriving in period 3 (temp shocks + permanent shock in future) |
| 154 |
oo_.exo_simul(4,1) = 1.4; |
| 155 |
oo_.exo_steady_state = 1.1+0.1; |
| 156 |
oo_.exo_simul(8,1) = (1.5/1.2)*oo_.exo_steady_state; |
| 157 |
oo_.exo_simul(5:7, 1) = oo_.exo_steady_state; |
| 158 |
oo_.exo_simul(9:end, 1) = oo_.exo_steady_state; |
| 159 |
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true); |
| 160 |
oo_.endo_simul(:, end) = oo_.steady_state; |
| 161 |
options_.periods = 5; |
| 162 |
saved_endo = oo_.endo_simul(:, 1:2); |
| 163 |
saved_exo = oo_.exo_simul(1:2, :); |
| 164 |
oo_.endo_simul = oo_.endo_simul(:, 3:end); |
| 165 |
oo_.exo_simul = oo_.exo_simul(3:end, :); |
| 166 |
oo_=perfect_foresight_solver(M_, options_, oo_); |
| 167 |
oo_.endo_simul = [ saved_endo oo_.endo_simul ]; |
| 168 |
oo_.exo_simul = [ saved_exo; oo_.exo_simul ]; |
| 169 |
|
| 170 |
% Information arriving in period 6 (temp shocks + permanent shock) |
| 171 |
oo_.exo_simul(7,1) = (1.1+0.1)*0.8; |
| 172 |
oo_.exo_simul(8,1) = 1.5*0.8; |
| 173 |
oo_.exo_steady_state = (1.1+0.1)*0.75; |
| 174 |
oo_.exo_simul(9:end, 1) = oo_.exo_steady_state; |
| 175 |
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true); |
| 176 |
oo_.endo_simul(:, end) = oo_.steady_state; |
| 177 |
options_.periods = 2; |
| 178 |
saved_endo = oo_.endo_simul(:, 1:5); |
| 179 |
saved_exo = oo_.exo_simul(1:5, :); |
| 180 |
oo_.endo_simul = oo_.endo_simul(:, 6:end); |
| 181 |
oo_.exo_simul = oo_.exo_simul(6:end, :); |
| 182 |
oo_=perfect_foresight_solver(M_, options_, oo_); |
| 183 |
oo_.endo_simul = [ saved_endo oo_.endo_simul ]; |
| 184 |
oo_.exo_simul = [ saved_exo; oo_.exo_simul ]; |
| 185 |
|
| 186 |
% We should have strict equality with first pfwee simulation, because algorithm |
| 187 |
% and guess values are exactly the same. |
| 188 |
if any(any(pfwee_simul-oo_.endo_simul ~= 0)) |
| 189 |
error('Error in perfect_foresight_with_expectation_errors') |
| 190 |
end |
| 191 |
|
| 192 |
@#if dates |
| 193 |
if ~isequal(Simulated_time_series.dates, dates('2017Y'):dates('2025Y')) |
| 194 |
error('Incorrect Simulated_time_series object') |
| 195 |
end |
| 196 |
@#endif |
| 197 |
|
| 198 |
end; // verbatim |