Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • giovanma/dynare
  • giorgiomas/dynare
  • Vermandel/dynare
  • Dynare/dynare
  • normann/dynare
  • MichelJuillard/dynare
  • wmutschl/dynare
  • FerhatMihoubi/dynare
  • sebastien/dynare
  • lnsongxf/dynare
  • rattoma/dynare
  • CIMERS/dynare
  • FredericKarame/dynare
  • SumuduK/dynare
  • MinjeJeon/dynare
  • camilomrch/dynare
  • DoraK/dynare
  • avtishin/dynare
  • selma/dynare
  • claudio_olguin/dynare
  • jeffjiang07/dynare
  • EthanSystem/dynare
  • stepan-a/dynare
  • wjgatt/dynare
  • JohannesPfeifer/dynare
  • gboehl/dynare
  • chskcau/dynare-doc-fixes
27 results
Select Git revision
Show changes
Showing
with 478 additions and 289 deletions
......@@ -78,5 +78,22 @@ end;
conditional_forecast(parameter_set=calibration, controlled_varexo=(e_a,e_m));
results_1=struct2array(oo_.conditional_forecast.cond.Mean);
plot_conditional_forecast(periods=10) gy_obs gp_obs;
xx=[0.01 -0.02 0 0 0];
conditional_forecast_paths;
var gy_obs;
periods 1:5;
values (xx);
var gp_obs;
periods 1:5;
values 0.05;
end;
conditional_forecast(parameter_set=calibration, controlled_varexo=(e_a,e_m));
results_2=struct2array(oo_.conditional_forecast.cond.Mean);
if max(max(abs(results_1-results_2)))>1e-10
error('Interface wrong')
end
......@@ -31,8 +31,6 @@ steady_state_model;
Consumption = exp(LoggedProductivity)*Capital^alpha-delta*Capital;
end;
set_time(1Q1);
initval;
LoggedProductivityInnovation = 0;
end;
......@@ -45,7 +43,7 @@ end;
steady;
perfect_foresight_setup(periods=200);
perfect_foresight_setup(periods=200, first_simulation_period = 1Q2);
perfect_foresight_solver;
if ~oo_.deterministic_simulation.status
......
// Example that triggers homotopy in perfect foresight simulation.
// Tests the endval_steady, homotopy_linearization_fallback options, and a few more.
var Consumption, Capital, LoggedProductivity;
varexo LoggedProductivityInnovation;
parameters beta, alpha, delta, rho;
beta = .985;
alpha = 1/3;
delta = alpha/10;
rho = .9;
model;
1/Consumption = beta/Consumption(1)*(alpha*exp(LoggedProductivity(1))*Capital^(alpha-1)+1-delta);
Capital = exp(LoggedProductivity)*Capital(-1)^alpha+(1-delta)*Capital(-1)-Consumption;
LoggedProductivity = rho*LoggedProductivity(-1)+LoggedProductivityInnovation;
end;
initval;
LoggedProductivityInnovation = 0;
end;
steady;
endval;
LoggedProductivityInnovation = 1;
Consumption = 0.1;
Capital = 1;
end;
@#include "homotopy_linearization.inc"
perfect_foresight_setup(periods=200, endval_steady);
......
......@@ -31,8 +31,6 @@ steady_state_model;
Consumption = exp(LoggedProductivity)*Capital^alpha-delta*Capital;
end;
set_time(1Q1);
initval;
LoggedProductivityInnovation = 0;
LoggedProductivity = 10;
......@@ -46,7 +44,7 @@ histval;
LoggedProductivity(0)=10;
end;
perfect_foresight_setup(periods=200);
perfect_foresight_setup(periods=200, first_simulation_period = 1Q2);
perfect_foresight_solver;
if ~oo_.deterministic_simulation.status
......
var Consumption, Capital, LoggedProductivity;
varexo LoggedProductivityInnovation;
parameters beta, alpha, delta, rho;
beta = .985;
alpha = 1/3;
delta = alpha/10;
rho = .9;
model;
1/Consumption = beta/Consumption(1)*(alpha*exp(LoggedProductivity(1))*Capital^(alpha-1)+1-delta);
Capital = exp(LoggedProductivity)*Capital(-1)^alpha+(1-delta)*Capital(-1)-Consumption;
LoggedProductivity = rho*LoggedProductivity(-1)+LoggedProductivityInnovation;
end;
initval;
LoggedProductivityInnovation = 0;
end;
steady;
endval;
LoggedProductivityInnovation = 1;
Consumption = 0.1;
Capital = 1;
end;
// Example that triggers homotopy in perfect foresight simulation.
// Tests homotopy_linearization_fallback with perfect_foresight_controlled_paths
@#include "homotopy_linearization.inc"
perfect_foresight_controlled_paths;
exogenize LoggedProductivity;
periods 8:9;
values 5;
endogenize LoggedProductivityInnovation;
end;
perfect_foresight_setup(periods=200, endval_steady);
perfect_foresight_solver(homotopy_max_completion_share = 0.7,
homotopy_linearization_fallback,
steady_solve_algo = 13);
if ~oo_.deterministic_simulation.status
error('Perfect foresight simulation failed')
end
if ~(all(abs(oo_.endo_simul(3, 9:10) - 5) < 1e-15) && abs(oo_.exo_simul(10) - 0.5) < 1e-15)
error('Homotopy with linearization and controlled paths failed')
end
// Example that triggers homotopy in perfect foresight simulation.
// Tests the homotopy_marginal_linearization_fallback and homotopy_step_size_increase_success_count options
var Consumption, Capital, LoggedProductivity;
varexo LoggedProductivityInnovation;
parameters beta, alpha, delta, rho;
beta = .985;
alpha = 1/3;
delta = alpha/10;
rho = .9;
model;
1/Consumption = beta/Consumption(1)*(alpha*exp(LoggedProductivity(1))*Capital^(alpha-1)+1-delta);
Capital = exp(LoggedProductivity)*Capital(-1)^alpha+(1-delta)*Capital(-1)-Consumption;
LoggedProductivity = rho*LoggedProductivity(-1)+LoggedProductivityInnovation;
end;
initval;
LoggedProductivityInnovation = 0;
end;
steady;
endval;
LoggedProductivityInnovation = 1;
Consumption = 0.1;
Capital = 1;
end;
@#include "homotopy_linearization.inc"
perfect_foresight_setup(periods=200, endval_steady);
......
// Example that triggers homotopy in perfect foresight simulation.
// Tests homotopy_marginal_linearization_fallback with perfect_foresight_controlled_paths
@#include "homotopy_linearization.inc"
perfect_foresight_controlled_paths;
exogenize LoggedProductivity;
periods 8:9;
values 5;
endogenize LoggedProductivityInnovation;
end;
perfect_foresight_setup(periods=200, endval_steady);
perfect_foresight_solver(homotopy_max_completion_share = 0.7,
homotopy_marginal_linearization_fallback,
steady_solve_algo = 13);
if ~oo_.deterministic_simulation.status
error('Perfect foresight simulation failed')
end
if ~(all(abs(oo_.endo_simul(3, 9:10) - 5) < 1e-14) && abs(oo_.exo_simul(10) - 0.5) < 1e-13)
error('Homotopy with marginal linearization and controlled paths failed')
end
% Tests perfect simulation of linear model (sim1_linear.m) with controlled paths
var x
y
z;
varexo u
v;
parameters a1 a2 a3 a4
b1 b2 b3
c1;
a1 = .50;
a2 = .00;
a3 = .70;
a4 = .40;
b1 = .90;
b2 = .00;
b3 = .80;
c1 = .95;
model(linear);
y = a1*x(-1) + a2*x(+1) + a3*z + a4*y(-1);
z = b1*z(-1) + b2*z(+1) + b3*x + u;
x = c1*x(-1) + v +v(-1)+v(+1);
end;
initval;
y=-1;
x=-1;
z=-1;
end;
endval;
y=0;
x=0;
z=0;
end;
perfect_foresight_controlled_paths;
exogenize z;
periods 50;
values 0.5;
endogenize u;
end;
steady;
perfect_foresight_setup(periods=100);
perfect_foresight_solver;
if ~oo_.deterministic_simulation.status
error('Perfect foresight simulation failed')
end
if ~(oo_.endo_simul(3, 51) == 0.5 && isequal(find(oo_.exo_simul ~= 0), 51))
error('Linear perfect foresight simulation with controlled paths failed')
end
......@@ -37,29 +37,30 @@ perfect_foresight_with_expectation_errors_solver;
pfwee_simul = oo_.endo_simul;
// Now compute the solution by hand to verify the results
verbatim;
oo_.steady_state = orig_steady_state;
oo_.exo_steady_state = orig_exo_steady_state;
perfect_foresight_setup;
verbatim;
oo_ = make_ex_(M_,options_,oo_);
oo_ = make_y_(M_,options_,oo_);
% Information arriving in period 1 (temp shock now)
oo_.exo_simul(2,1) = 1.2;
oo_=perfect_foresight_solver(M_, options_, oo_, true);
oo_=perfect_foresight_solver(M_, options_, oo_);
% Information arriving in period 2 (temp shock now + permanent shock in future)
oo_.exo_simul(3,1) = 1.3;
oo_.exo_steady_state = 1.1;
oo_.exo_simul(end, 1) = oo_.exo_steady_state;
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true);
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_);
oo_.endo_simul(:, end) = oo_.steady_state;
options_.periods = 6;
saved_endo = oo_.endo_simul(:, 1);
saved_exo = oo_.exo_simul(1, :);
oo_.endo_simul = oo_.endo_simul(:, 2:end);
oo_.exo_simul = oo_.exo_simul(2:end, :);
oo_=perfect_foresight_solver(M_, options_, oo_, true);
oo_=perfect_foresight_solver(M_, options_, oo_);
oo_.endo_simul = [ saved_endo oo_.endo_simul ];
oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
......@@ -67,14 +68,14 @@ oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
oo_.exo_simul(4,1) = 1.4;
oo_.exo_steady_state = 1.2;
oo_.exo_simul(end, 1) = oo_.exo_steady_state;
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true);
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_);
oo_.endo_simul(:, end) = oo_.steady_state;
options_.periods = 5;
saved_endo = oo_.endo_simul(:, 1:2);
saved_exo = oo_.exo_simul(1:2, :);
oo_.endo_simul = oo_.endo_simul(:, 3:end);
oo_.exo_simul = oo_.exo_simul(3:end, :);
oo_=perfect_foresight_solver(M_, options_, oo_, true);
oo_=perfect_foresight_solver(M_, options_, oo_);
oo_.endo_simul = [ saved_endo oo_.endo_simul ];
oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
......@@ -83,14 +84,14 @@ oo_.exo_simul(7,1) = 1.1;
oo_.exo_simul(8,1) = 1.1;
oo_.exo_steady_state = 1.1;
oo_.exo_simul(end, 1) = oo_.exo_steady_state;
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true);
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_);
oo_.endo_simul(:, end) = oo_.steady_state;
options_.periods = 2;
saved_endo = oo_.endo_simul(:, 1:5);
saved_exo = oo_.exo_simul(1:5, :);
oo_.endo_simul = oo_.endo_simul(:, 6:end);
oo_.exo_simul = oo_.exo_simul(6:end, :);
oo_=perfect_foresight_solver(M_, options_, oo_,true);
oo_=perfect_foresight_solver(M_, options_, oo_);
oo_.endo_simul = [ saved_endo oo_.endo_simul ];
oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
......
......@@ -36,16 +36,17 @@ perfect_foresight_with_expectation_errors_solver(constant_simulation_length);
pfwee_simul = oo_.endo_simul;
// Now compute the solution by hand to verify the results
verbatim;
oo_.steady_state = orig_steady_state;
oo_.exo_steady_state = orig_exo_steady_state;
perfect_foresight_setup;
verbatim;
oo_ = make_ex_(M_,options_,oo_);
oo_ = make_y_(M_,options_,oo_);
% Information arriving in period 1 (temp shock now)
oo_.exo_simul(2,1) = 1.2;
oo_=perfect_foresight_solver(M_, options_, oo_, true);
oo_=perfect_foresight_solver(M_, options_, oo_);
% Information arriving in period 2 (temp shock now + permanent shock in future)
oo_.exo_simul(3,1) = 1.3;
......@@ -57,7 +58,7 @@ saved_endo = oo_.endo_simul(:, 1);
saved_exo = oo_.exo_simul(1, :);
oo_.endo_simul = oo_.endo_simul(:, 2:end);
oo_.exo_simul = oo_.exo_simul(2:end, :);
oo_=perfect_foresight_solver(M_, options_, oo_, true);
oo_=perfect_foresight_solver(M_, options_, oo_);
oo_.endo_simul = [ saved_endo oo_.endo_simul ];
oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
......@@ -71,7 +72,7 @@ saved_endo = oo_.endo_simul(:, 1:2);
saved_exo = oo_.exo_simul(1:2, :);
oo_.endo_simul = oo_.endo_simul(:, 3:end);
oo_.exo_simul = oo_.exo_simul(3:end, :);
oo_=perfect_foresight_solver(M_, options_, oo_, true);
oo_=perfect_foresight_solver(M_, options_, oo_);
oo_.endo_simul = [ saved_endo oo_.endo_simul ];
oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
......@@ -87,7 +88,7 @@ saved_endo = oo_.endo_simul(:, 1:5);
saved_exo = oo_.exo_simul(1:5, :);
oo_.endo_simul = oo_.endo_simul(:, 6:end);
oo_.exo_simul = oo_.exo_simul(6:end, :);
oo_=perfect_foresight_solver(M_, options_, oo_, true);
oo_=perfect_foresight_solver(M_, options_, oo_);
oo_.endo_simul = [ saved_endo oo_.endo_simul ];
oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
......
var Consumption, Capital, LoggedProductivity;
varexo LoggedProductivityInnovation;
parameters beta, alpha, delta, rho;
beta = .985;
alpha = 1/3;
delta = alpha/10;
rho = .9;
model;
1/Consumption = beta/Consumption(1)*(alpha*exp(LoggedProductivity(1))*Capital^(alpha-1)+1-delta);
Capital = exp(LoggedProductivity)*Capital(-1)^alpha+(1-delta)*Capital(-1)-Consumption;
LoggedProductivity = rho*LoggedProductivity(-1)+LoggedProductivityInnovation;
end;
initval;
LoggedProductivityInnovation = 0;
end;
steady;
endval;
LoggedProductivityInnovation = 0.6;
end;
endval(learnt_in = 5);
LoggedProductivityInnovation = 1;
end;
shocks(learnt_in = 3);
var LoggedProductivityInnovation;
periods 4;
values 0.2;
end;
/* Example that triggers homotopy in perfect foresight simulation with
expectation errors, and tests linearization. */
var Consumption, Capital, LoggedProductivity;
varexo LoggedProductivityInnovation;
parameters beta, alpha, delta, rho;
beta = .985;
alpha = 1/3;
delta = alpha/10;
rho = .9;
model;
1/Consumption = beta/Consumption(1)*(alpha*exp(LoggedProductivity(1))*Capital^(alpha-1)+1-delta);
Capital = exp(LoggedProductivity)*Capital(-1)^alpha+(1-delta)*Capital(-1)-Consumption;
LoggedProductivity = rho*LoggedProductivity(-1)+LoggedProductivityInnovation;
end;
initval;
LoggedProductivityInnovation = 0;
end;
steady;
endval;
LoggedProductivityInnovation = 0.6;
end;
endval(learnt_in = 5);
LoggedProductivityInnovation = 1;
end;
@#include "pfwee_homotopy.inc"
perfect_foresight_with_expectation_errors_setup(periods=200);
perfect_foresight_with_expectation_errors_solver(homotopy_max_completion_share = 0.8, homotopy_linearization_fallback, steady_solve_algo = 13);
......
/* Example that triggers homotopy in perfect foresight simulation with
expectation errors + controlled paths, and tests linearization. */
@#include "pfwee_homotopy.inc"
perfect_foresight_controlled_paths(learnt_in = 7);
exogenize LoggedProductivity;
periods 8:9;
values 5;
endogenize LoggedProductivityInnovation;
end;
perfect_foresight_with_expectation_errors_setup(periods=200);
perfect_foresight_with_expectation_errors_solver(homotopy_max_completion_share = 0.8, homotopy_linearization_fallback, steady_solve_algo = 13);
if ~oo_.deterministic_simulation.status
error('Perfect foresight simulation failed')
end
if ~(all(abs(oo_.endo_simul(3, 9:10) - 5) < 1e-15) && abs(oo_.exo_simul(10) - 0.5) < 1e-15)
error('Homotopy with linearization and controlled paths failed')
end
/* Example that triggers homotopy in perfect foresight simulation with
expectation errors, and tests marginal linearization. */
var Consumption, Capital, LoggedProductivity;
varexo LoggedProductivityInnovation;
parameters beta, alpha, delta, rho;
beta = .985;
alpha = 1/3;
delta = alpha/10;
rho = .9;
model;
1/Consumption = beta/Consumption(1)*(alpha*exp(LoggedProductivity(1))*Capital^(alpha-1)+1-delta);
Capital = exp(LoggedProductivity)*Capital(-1)^alpha+(1-delta)*Capital(-1)-Consumption;
LoggedProductivity = rho*LoggedProductivity(-1)+LoggedProductivityInnovation;
end;
initval;
LoggedProductivityInnovation = 0;
end;
steady;
endval;
LoggedProductivityInnovation = 0.6;
end;
endval(learnt_in = 5);
LoggedProductivityInnovation = 1;
end;
@#include "pfwee_homotopy.inc"
perfect_foresight_with_expectation_errors_setup(periods=200);
perfect_foresight_with_expectation_errors_solver(homotopy_max_completion_share = 0.8, homotopy_marginal_linearization_fallback, steady_solve_algo = 13);
......
/* Example that triggers homotopy in perfect foresight simulation with
expectation errors + controlled paths, and tests marginal linearization. */
@#include "pfwee_homotopy.inc"
perfect_foresight_controlled_paths(learnt_in = 7);
exogenize LoggedProductivity;
periods 8:9;
values 5;
endogenize LoggedProductivityInnovation;
end;
perfect_foresight_with_expectation_errors_setup(periods=200);
perfect_foresight_with_expectation_errors_solver(homotopy_max_completion_share = 0.8, homotopy_marginal_linearization_fallback, steady_solve_algo = 13);
if ~oo_.deterministic_simulation.status
error('Perfect foresight simulation failed')
end
if ~(all(abs(oo_.endo_simul(3, 9:10) - 5) < 1e-14) && abs(oo_.exo_simul(10) - 0.5) < 1e-14)
error('Homotopy with marginal linearization and controlled paths failed')
end
/* Tests perfect_foresight_with_expectation_errors_{setup,solver}
using the shocks(learnt_in=…), mshocks(learnt_in=…) and endval(learnt_in=…) syntax
with dates (instead of integer indices) for periods */
var c k;
varexo x;
parameters alph gam delt bet aa;
alph=0.5;
gam=0.5;
delt=0.02;
bet=0.05;
aa=0.5;
model;
c + k - aa*x*k(-1)^alph - (1-delt)*k(-1);
c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);
end;
initval;
x = 1;
k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1));
c = aa*k^alph-delt*k;
end;
steady;
check;
// p contains period indices, either as integer or as dates
@#if dates
@# define p = ["2018Y", "2019Y", "2020Y", "2021Y", "2022Y", "2023Y", "2024Y", "2025Y" ]
@#else
@# define p = 1:8
@#endif
@#if bare_first_info_period
shocks;
@#else
shocks(learnt_in = @{p[1]});
@#endif
var x;
periods @{p[1]}:@{p[2]};
values 1.2;
end;
@#if bare_first_info_period
endval;
@#else
endval(learnt_in = @{p[1]});
@#endif
x = 1.05;
end;
shocks(learnt_in = @{p[2]});
var x;
periods @{p[2]};
add 0.1;
end;
endval(learnt_in = @{p[2]});
x = 1.1;
end;
shocks(learnt_in = @{p[3]});
var x;
periods @{p[3]};
values 1.4;
end;
mshocks(learnt_in = @{p[3]});
var x;
periods @{p[7]};
values (1.5/1.2); // 1.2 is the terminal steady as anticipated in period 3
end;
endval(learnt_in = @{p[3]});
x += 0.1;
end;
// Dummy block, that will be overwritten by the next one
shocks(learnt_in = @{p[6]});
var x;
periods @{p[6]}:@{p[8]};
values 10;
end;
shocks(learnt_in = @{p[6]}, overwrite);
var x;
periods @{p[6]}:@{p[7]};
multiply 0.8;
end;
endval(learnt_in = @{p[6]});
x *= 0.75;
end;
// Save initial steady state (it will be modified by pfwee)
orig_steady_state = oo_.steady_state;
orig_exo_steady_state = oo_.exo_steady_state;
perfect_foresight_with_expectation_errors_setup(
@#if dates
first_simulation_period = 2018Y, last_simulation_period = 2024Y
@#else
periods = 7
@#endif
);
perfect_foresight_with_expectation_errors_solver;
pfwee_simul = oo_.endo_simul;
// Now compute the solution by hand to verify the results
verbatim;
oo_.steady_state = orig_steady_state;
oo_.exo_steady_state = orig_exo_steady_state;
oo_ = make_ex_(M_,options_,oo_);
oo_ = make_y_(M_,options_,oo_);
@#if dates
% Reset {first,last}_simulation_period since were going to manipulate options_.periods
options_.simul.first_simulation_period = dates();
options_.simul.last_simulation_period = dates();
options_.periods = 7;
@#endif
% Information arriving in period 1 (temp shock now and tomorrow + permanent shock in future)
oo_.exo_simul(2:3,1) = 1.2;
oo_.exo_simul(4:end,1) = 1.05;
oo_.exo_steady_state = 1.05;
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true);
oo_.endo_simul(:, end) = oo_.steady_state;
oo_=perfect_foresight_solver(M_, options_, oo_);
% Information arriving in period 2 (temp shock now + permanent shock in future)
oo_.exo_simul(3,1) = 1.3;
oo_.exo_steady_state = 1.1;
oo_.exo_simul(4:end, 1) = oo_.exo_steady_state;
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true);
oo_.endo_simul(:, end) = oo_.steady_state;
options_.periods = 6;
saved_endo = oo_.endo_simul(:, 1);
saved_exo = oo_.exo_simul(1, :);
oo_.endo_simul = oo_.endo_simul(:, 2:end);
oo_.exo_simul = oo_.exo_simul(2:end, :);
oo_=perfect_foresight_solver(M_, options_, oo_);
oo_.endo_simul = [ saved_endo oo_.endo_simul ];
oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
% Information arriving in period 3 (temp shocks + permanent shock in future)
oo_.exo_simul(4,1) = 1.4;
oo_.exo_steady_state = 1.1+0.1;
oo_.exo_simul(8,1) = (1.5/1.2)*oo_.exo_steady_state;
oo_.exo_simul(5:7, 1) = oo_.exo_steady_state;
oo_.exo_simul(9:end, 1) = oo_.exo_steady_state;
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true);
oo_.endo_simul(:, end) = oo_.steady_state;
options_.periods = 5;
saved_endo = oo_.endo_simul(:, 1:2);
saved_exo = oo_.exo_simul(1:2, :);
oo_.endo_simul = oo_.endo_simul(:, 3:end);
oo_.exo_simul = oo_.exo_simul(3:end, :);
oo_=perfect_foresight_solver(M_, options_, oo_);
oo_.endo_simul = [ saved_endo oo_.endo_simul ];
oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
% Information arriving in period 6 (temp shocks + permanent shock)
oo_.exo_simul(7,1) = (1.1+0.1)*0.8;
oo_.exo_simul(8,1) = 1.5*0.8;
oo_.exo_steady_state = (1.1+0.1)*0.75;
oo_.exo_simul(9:end, 1) = oo_.exo_steady_state;
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true);
oo_.endo_simul(:, end) = oo_.steady_state;
options_.periods = 2;
saved_endo = oo_.endo_simul(:, 1:5);
saved_exo = oo_.exo_simul(1:5, :);
oo_.endo_simul = oo_.endo_simul(:, 6:end);
oo_.exo_simul = oo_.exo_simul(6:end, :);
oo_=perfect_foresight_solver(M_, options_, oo_);
oo_.endo_simul = [ saved_endo oo_.endo_simul ];
oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
% We should have strict equality with first pfwee simulation, because algorithm
% and guess values are exactly the same.
if any(any(pfwee_simul-oo_.endo_simul ~= 0))
error('Error in perfect_foresight_with_expectation_errors')
end
@#if dates
if ~isequal(Simulated_time_series.dates, dates('2017Y'):dates('2025Y'))
error('Incorrect Simulated_time_series object')
end
@#endif
end; // verbatim
/* Tests perfect_foresight_with_expectation_errors_{setup,solver}
using the shocks(learnt_in=…), mshocks(learnt_in=…) and endval(learnt_in=…) syntax */
var c k;
varexo x;
@#define bare_first_info_period = false
@#define dates = false
parameters alph gam delt bet aa;
alph=0.5;
gam=0.5;
delt=0.02;
bet=0.05;
aa=0.5;
model;
c + k - aa*x*k(-1)^alph - (1-delt)*k(-1);
c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);
end;
initval;
x = 1;
k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1));
c = aa*k^alph-delt*k;
end;
steady;
check;
shocks(learnt_in = 1);
var x;
periods 1:2;
values 1.2;
end;
shocks(learnt_in = 2);
var x;
periods 2;
add 0.1;
end;
endval(learnt_in = 2);
x = 1.1;
end;
shocks(learnt_in = 3);
var x;
periods 3;
values 1.4;
end;
mshocks(learnt_in = 3);
var x;
periods 7;
values (1.5/1.2); // 1.2 is the terminal steady as anticipated in period 3
end;
endval(learnt_in = 3);
x += 0.1;
end;
// Dummy block, that will be overwritten by the next one
shocks(learnt_in = 6);
var x;
periods 6:8;
values 10;
end;
shocks(learnt_in = 6, overwrite);
var x;
periods 6:7;
multiply 0.8;
end;
endval(learnt_in = 6);
x *= 0.75;
end;
// Save initial steady state (it will be modified by pfwee)
orig_steady_state = oo_.steady_state;
orig_exo_steady_state = oo_.exo_steady_state;
perfect_foresight_with_expectation_errors_setup(periods = 7);
perfect_foresight_with_expectation_errors_solver;
pfwee_simul = oo_.endo_simul;
// Now compute the solution by hand to verify the results
oo_.steady_state = orig_steady_state;
oo_.exo_steady_state = orig_exo_steady_state;
perfect_foresight_setup;
verbatim;
% Information arriving in period 1 (temp shock now and tomorrow)
oo_.exo_simul(2:3,1) = 1.2;
oo_=perfect_foresight_solver(M_, options_, oo_, true);
% Information arriving in period 2 (temp shock now + permanent shock in future)
oo_.exo_simul(3,1) = 1.3;
oo_.exo_steady_state = 1.1;
oo_.exo_simul(4:end, 1) = oo_.exo_steady_state;
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true);
oo_.endo_simul(:, end) = oo_.steady_state;
options_.periods = 6;
saved_endo = oo_.endo_simul(:, 1);
saved_exo = oo_.exo_simul(1, :);
oo_.endo_simul = oo_.endo_simul(:, 2:end);
oo_.exo_simul = oo_.exo_simul(2:end, :);
oo_=perfect_foresight_solver(M_, options_, oo_, true);
oo_.endo_simul = [ saved_endo oo_.endo_simul ];
oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
% Information arriving in period 3 (temp shocks + permanent shock in future)
oo_.exo_simul(4,1) = 1.4;
oo_.exo_steady_state = 1.1+0.1;
oo_.exo_simul(8,1) = (1.5/1.2)*oo_.exo_steady_state;
oo_.exo_simul(5:7, 1) = oo_.exo_steady_state;
oo_.exo_simul(9:end, 1) = oo_.exo_steady_state;
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true);
oo_.endo_simul(:, end) = oo_.steady_state;
options_.periods = 5;
saved_endo = oo_.endo_simul(:, 1:2);
saved_exo = oo_.exo_simul(1:2, :);
oo_.endo_simul = oo_.endo_simul(:, 3:end);
oo_.exo_simul = oo_.exo_simul(3:end, :);
oo_=perfect_foresight_solver(M_, options_, oo_, true);
oo_.endo_simul = [ saved_endo oo_.endo_simul ];
oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
% Information arriving in period 6 (temp shocks + permanent shock)
oo_.exo_simul(7,1) = (1.1+0.1)*0.8;
oo_.exo_simul(8,1) = 1.5*0.8;
oo_.exo_steady_state = (1.1+0.1)*0.75;
oo_.exo_simul(9:end, 1) = oo_.exo_steady_state;
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true);
oo_.endo_simul(:, end) = oo_.steady_state;
options_.periods = 2;
saved_endo = oo_.endo_simul(:, 1:5);
saved_exo = oo_.exo_simul(1:5, :);
oo_.endo_simul = oo_.endo_simul(:, 6:end);
oo_.exo_simul = oo_.exo_simul(6:end, :);
oo_=perfect_foresight_solver(M_, options_, oo_, true);
oo_.endo_simul = [ saved_endo oo_.endo_simul ];
oo_.exo_simul = [ saved_exo; oo_.exo_simul ];
% We should have strict equality with first pfwee simulation, because algorithm
% and guess values are exactly the same.
if any(any(pfwee_simul-oo_.endo_simul ~= 0))
error('Error in perfect_foresight_with_expectation_errors')
end
end; // verbatim
@#include "pfwee_learnt_in.inc"
/* Tests perfect_foresight_with_expectation_errors_{setup,solver}
using the shocks(learnt_in=…), mshocks(learnt_in=…) and endval(learnt_in=…) syntax,
except for the first informational period where the learnt_in keyword is omitted */
@#define bare_first_info_period = true
@#define dates = false
@#include "pfwee_learnt_in.inc"
/* Tests perfect_foresight_with_expectation_errors_{setup,solver}
using the shocks(learnt_in=…), mshocks(learnt_in=…) and endval(learnt_in=…) syntax
with dates (instead of integer indices) for periods */
@#define bare_first_info_period = false
@#define dates = true
@#include "pfwee_learnt_in.inc"