| 1 |
/* Test that perfect foresight simulation with expectation errors gives correct |
| 2 |
results with marginal linearization. Homotopy is not really triggered, but |
| 3 |
the use of homotopy_max_completion_share is enough to test the computations. |
| 4 |
|
| 5 |
This test is similar to pfwee_homotopy_marginal_linearization.mod, except that |
| 6 |
the numerical values are different (the shock is smaller to facilitate computations). |
| 7 |
*/ |
| 8 |
|
| 9 |
var Consumption, Capital, LoggedProductivity; |
| 10 |
|
| 11 |
varexo LoggedProductivityInnovation; |
| 12 |
|
| 13 |
parameters beta, alpha, delta, rho; |
| 14 |
|
| 15 |
beta = .985; |
| 16 |
alpha = 1/3; |
| 17 |
delta = alpha/10; |
| 18 |
rho = .4; |
| 19 |
|
| 20 |
model; |
| 21 |
1/Consumption = beta/Consumption(1)*(alpha*exp(LoggedProductivity(1))*Capital^(alpha-1)+1-delta); |
| 22 |
Capital = exp(LoggedProductivity)*Capital(-1)^alpha+(1-delta)*Capital(-1)-Consumption; |
| 23 |
LoggedProductivity = rho*LoggedProductivity(-1)+LoggedProductivityInnovation; |
| 24 |
end; |
| 25 |
|
| 26 |
initval; |
| 27 |
LoggedProductivityInnovation = 0.1; |
| 28 |
end; |
| 29 |
|
| 30 |
steady; |
| 31 |
|
| 32 |
endval; |
| 33 |
LoggedProductivityInnovation = 0.3; |
| 34 |
end; |
| 35 |
|
| 36 |
shocks(learnt_in = 5); |
| 37 |
var LoggedProductivityInnovation; |
| 38 |
periods 7; |
| 39 |
values -0.5; |
| 40 |
end; |
| 41 |
|
| 42 |
endval(learnt_in = 10); |
| 43 |
LoggedProductivityInnovation = 0.6; |
| 44 |
end; |
| 45 |
|
| 46 |
// Save initial steady state (it will be modified by pfwee) |
| 47 |
orig_steady_state = oo_.steady_state; |
| 48 |
orig_exo_steady_state = oo_.exo_steady_state; |
| 49 |
|
| 50 |
perfect_foresight_with_expectation_errors_setup(periods = 50); |
| 51 |
perfect_foresight_with_expectation_errors_solver(homotopy_max_completion_share = 0.8, homotopy_marginal_linearization_fallback, steady_solve_algo = 13); |
| 52 |
|
| 53 |
verbatim; |
| 54 |
|
| 55 |
if ~oo_.deterministic_simulation.status |
| 56 |
error('Perfect foresight simulation failed') |
| 57 |
end |
| 58 |
|
| 59 |
pfwee_endo_simul = oo_.endo_simul; |
| 60 |
pfwee_exo_simul = oo_.exo_simul; |
| 61 |
|
| 62 |
oo_.steady_state = orig_steady_state; |
| 63 |
oo_.exo_steady_state = orig_exo_steady_state; |
| 64 |
|
| 65 |
oo_ = make_ex_(M_,options_,oo_); |
| 66 |
oo_ = make_y_(M_,options_,oo_); |
| 67 |
|
| 68 |
options_.simul.homotopy_marginal_linearization_fallback = 0; |
| 69 |
options_.simul.homotopy_max_completion_share = 1; |
| 70 |
options_.solve_algo = 13; |
| 71 |
|
| 72 |
%% Information arriving in period 1 (permanent shock now) |
| 73 |
% Simulation at 80% |
| 74 |
disp('*** info_period=1, share=80%') |
| 75 |
oo_.exo_steady_state = 0.1+0.2*0.8; |
| 76 |
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true); |
| 77 |
oo_.endo_simul(:,end) = oo_.steady_state; |
| 78 |
oo_.exo_simul(2:end,:) = oo_.exo_steady_state; |
| 79 |
sim1_1 = perfect_foresight_solver(M_, options_, oo_); |
| 80 |
% Simulation at 79% |
| 81 |
disp('*** info_period=1, share=79%') |
| 82 |
oo_.exo_steady_state = 0.1+0.2*0.79; |
| 83 |
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true); |
| 84 |
oo_.endo_simul(:,end) = oo_.steady_state; |
| 85 |
oo_.exo_simul(2:end,:) = oo_.exo_steady_state; |
| 86 |
sim2_1 = perfect_foresight_solver(M_, options_, oo_); |
| 87 |
|
| 88 |
%% Information arriving in period 5 (temporary shock in period 7) |
| 89 |
options_.periods = 46; |
| 90 |
% Simulation at 80% |
| 91 |
disp('*** info_period=5, share=80%') |
| 92 |
oo_.endo_simul = sim1_1.endo_simul(:,5:end); |
| 93 |
oo_.exo_simul = sim1_1.exo_simul(5:end,:); |
| 94 |
oo_.steady_state = sim1_1.steady_state; |
| 95 |
oo_.exo_steady_state = sim1_1.exo_steady_state; |
| 96 |
oo_.exo_simul(4,1) = 0.1-0.6*0.8; |
| 97 |
sim1_5 = perfect_foresight_solver(M_, options_, oo_); |
| 98 |
% Simulation at 79% |
| 99 |
disp('*** info_period=5, share=79%') |
| 100 |
oo_.endo_simul = sim2_1.endo_simul(:,5:end); |
| 101 |
oo_.exo_simul = sim2_1.exo_simul(5:end,:); |
| 102 |
oo_.steady_state = sim2_1.steady_state; |
| 103 |
oo_.exo_steady_state = sim2_1.exo_steady_state; |
| 104 |
oo_.exo_simul(4,1) = 0.1-0.6*0.79; |
| 105 |
sim2_5 = perfect_foresight_solver(M_, options_, oo_); |
| 106 |
|
| 107 |
%% Information arriving in period 10 (permanent shock now) |
| 108 |
options_.periods = 41; |
| 109 |
% Simulation at 80% |
| 110 |
disp('*** info_period=10, share=80%') |
| 111 |
oo_.endo_simul = sim1_5.endo_simul(:,6:end); |
| 112 |
oo_.exo_simul = sim1_5.exo_simul(6:end,:); |
| 113 |
oo_.exo_steady_state = 0.1+0.5*0.8; |
| 114 |
oo_.steady_state = evaluate_steady_state(sim1_5.steady_state, oo_.exo_steady_state, M_, options_, true); |
| 115 |
oo_.endo_simul(:,end) = oo_.steady_state; |
| 116 |
oo_.exo_simul(2:end,:) = oo_.exo_steady_state; |
| 117 |
sim1_10 = perfect_foresight_solver(M_, options_, oo_); |
| 118 |
% Simulation at 79% |
| 119 |
disp('*** info_period=10, share=79%') |
| 120 |
oo_.endo_simul = sim2_5.endo_simul(:,6:end); |
| 121 |
oo_.exo_simul = sim2_5.exo_simul(6:end,:); |
| 122 |
oo_.exo_steady_state = 0.1+0.5*0.79; |
| 123 |
oo_.steady_state = evaluate_steady_state(sim2_5.steady_state, oo_.exo_steady_state, M_, options_, true); |
| 124 |
oo_.endo_simul(:,end) = oo_.steady_state; |
| 125 |
oo_.exo_simul(2:end,:) = oo_.exo_steady_state; |
| 126 |
sim2_10 = perfect_foresight_solver(M_, options_, oo_); |
| 127 |
|
| 128 |
%% Reconstruct the two simulations |
| 129 |
sim1_endo_simul = [ sim1_1.endo_simul(:,1:5), sim1_5.endo_simul(:,2:6), sim1_10.endo_simul(:,2:end);]; |
| 130 |
sim2_endo_simul = [ sim2_1.endo_simul(:,1:5), sim2_5.endo_simul(:,2:6), sim2_10.endo_simul(:,2:end);]; |
| 131 |
sim1_exo_simul = [ sim1_1.exo_simul(1:5,:); sim1_5.exo_simul(2:6,:); sim1_10.exo_simul(2:end,:);]; |
| 132 |
sim2_exo_simul = [ sim2_1.exo_simul(1:5,:); sim2_5.exo_simul(2:6,:); sim2_10.exo_simul(2:end,:);]; |
| 133 |
|
| 134 |
%% Compute marginal linearization |
| 135 |
endo_simul = sim1_endo_simul + 20*(sim1_endo_simul - sim2_endo_simul); |
| 136 |
exo_simul = sim1_exo_simul + 20*(sim1_exo_simul - sim2_exo_simul); |
| 137 |
|
| 138 |
endo_abs_diff = max(max(abs(pfwee_endo_simul-endo_simul))); |
| 139 |
endo_rel_diff = max(max(abs(endo_simul./pfwee_endo_simul-1))); |
| 140 |
|
| 141 |
fprintf('Max absolute difference on endogenous: %g\nMax relative difference on endogenous: %g%%\n', endo_abs_diff, 100*endo_rel_diff) |
| 142 |
|
| 143 |
exo_abs_diff = max(max(abs(pfwee_exo_simul-exo_simul))); |
| 144 |
exo_rel_diff = max(max(abs(exo_simul./pfwee_exo_simul-1))); |
| 145 |
|
| 146 |
fprintf('Max absolute difference on exogenous: %g\nMax relative difference on exogenous: %g%%\n', exo_abs_diff, 100*exo_rel_diff) |
| 147 |
|
| 148 |
if endo_abs_diff > 1e-3 || endo_rel_diff > 3e-3 || exo_abs_diff > 1e-15 || exo_rel_diff > 1e-13 |
| 149 |
error('perfect foresight with expectation errors + marginal linearization gives wrong result') |
| 150 |
end |
| 151 |
|
| 152 |
end; // verbatim |