Skip to content
Snippets Groups Projects
Verified Commit e21cb1ad authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

LMMCP: fix the purely backward and purely forward cases

Closes: #1720
parent 4ba0f0a9
Branches
Tags
No related merge requests found
Pipeline #4277 canceled
...@@ -75,10 +75,10 @@ else ...@@ -75,10 +75,10 @@ else
oo_.deterministic_simulation.status = false; oo_.deterministic_simulation.status = false;
end end
else else
if M_.maximum_endo_lead == 0 % Purely backward model if M_.maximum_endo_lead == 0 && ~options_.lmmcp.status % Purely backward model
[oo_.endo_simul, oo_.deterministic_simulation] = ... [oo_.endo_simul, oo_.deterministic_simulation] = ...
sim1_purely_backward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); sim1_purely_backward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_);
elseif M_.maximum_endo_lag == 0 % Purely forward model elseif M_.maximum_endo_lag == 0 && ~options_.lmmcp.status % Purely forward model
[oo_.endo_simul, oo_.deterministic_simulation] = ... [oo_.endo_simul, oo_.deterministic_simulation] = ...
sim1_purely_forward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); sim1_purely_forward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_);
else % General case else % General case
......
...@@ -30,7 +30,7 @@ function [options, y0, yT, z, i_cols, i_cols_J1, i_cols_T, i_cols_j, i_cols_1, i ...@@ -30,7 +30,7 @@ function [options, y0, yT, z, i_cols, i_cols_J1, i_cols_T, i_cols_j, i_cols_1, i
% - i_cols_J0 [double] indices of contemporaneous variables appearing in M.lead_lag_incidence (relevant in problems with periods=1) % - i_cols_J0 [double] indices of contemporaneous variables appearing in M.lead_lag_incidence (relevant in problems with periods=1)
% - dynamicmodel [handle] function handle to _dynamic-file % - dynamicmodel [handle] function handle to _dynamic-file
% Copyright (C) 2015-2019 Dynare Team % Copyright (C) 2015-2020 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -73,22 +73,25 @@ end ...@@ -73,22 +73,25 @@ end
if M.maximum_lag > 0 if M.maximum_lag > 0
y0 = endogenousvariables(:, M.maximum_lag); y0 = endogenousvariables(:, M.maximum_lag);
else else
y0 = NaN(ny, 1); y0 = NaN(M.endo_nbr, 1);
end end
if M.maximum_lead > 0 if M.maximum_lead > 0
yT = endogenousvariables(:, M.maximum_lag+periods+1); yT = endogenousvariables(:, M.maximum_lag+periods+1);
else else
yT = NaN(ny, 1); yT = NaN(M.endo_nbr, 1);
end end
z = endogenousvariables(:,M.maximum_lag+(1:periods)); z = endogenousvariables(:,M.maximum_lag+(1:periods));
illi = M.lead_lag_incidence'; illi = M.lead_lag_incidence';
[i_cols,~,i_cols_j] = find(illi(:)); [i_cols,~,i_cols_j] = find(illi(:));
illi = illi(:,2:3); if M.maximum_lag == 0
i_cols = i_cols + M.endo_nbr;
end
illi = illi(:,(1+M.maximum_lag):(1+M.maximum_lag+M.maximum_lead));
[i_cols_J1,~,i_cols_1] = find(illi(:)); [i_cols_J1,~,i_cols_1] = find(illi(:));
i_cols_T = nonzeros(M.lead_lag_incidence(1:2,:)'); i_cols_T = nonzeros(M.lead_lag_incidence(1:(1+M.maximum_lag),:)');
if periods==1 if periods==1
i_cols_0 = nonzeros(M.lead_lag_incidence(2,:)'); i_cols_0 = nonzeros(M.lead_lag_incidence(1+M.maximum_lag,:)');
i_cols_J0 = find(M.lead_lag_incidence(2,:)'); i_cols_J0 = find(M.lead_lag_incidence(1+M.maximum_lag,:)');
else else
i_cols_0 = []; i_cols_0 = [];
i_cols_J0 = []; i_cols_J0 = [];
......
...@@ -4,6 +4,8 @@ MODFILES = \ ...@@ -4,6 +4,8 @@ MODFILES = \
moments/example1_hp_test.mod \ moments/example1_hp_test.mod \
moments/fs2000_post_moments.mod \ moments/fs2000_post_moments.mod \
lmmcp/rbcii.mod \ lmmcp/rbcii.mod \
lmmcp/purely_backward.mod \
lmmcp/purely_forward.mod \
ep/rbc_mc.mod \ ep/rbc_mc.mod \
estimation/TaRB/fs2000_tarb.mod \ estimation/TaRB/fs2000_tarb.mod \
observation_trends_and_prefiltering/MCMC/Trend_loglin_no_prefilt_first_obs_MC.mod \ observation_trends_and_prefiltering/MCMC/Trend_loglin_no_prefilt_first_obs_MC.mod \
......
// Regression test for bug #1720 (in the purely backward case)
var y;
varexo eps;
parameters rho;
rho = 0.9;
model;
[ mcp = 'y>1' ]
y = y(-1)^rho*exp(eps);
end;
initval;
y = 1;
eps = 0;
end;
steady;
check;
shocks;
var eps;
periods 1 10;
values -1 1;
end;
perfect_foresight_setup(periods=20);
perfect_foresight_solver(lmmcp);
if ~oo_.deterministic_simulation.status
error('Perfect foresight simulation failed')
end
if any(oo_.endo_simul < 1)
error('y>1 constraint not enforced')
end
// Regression test for bug #1720 (in the purely forward case)
var y;
varexo eps;
model;
[ mcp='y>1' ]
y = sqrt(y(1))*exp(eps);
end;
initval;
y = 1;
end;
steady;
check;
shocks;
var eps;
periods 1 10;
values 1 -1;
end;
perfect_foresight_setup(periods=20);
perfect_foresight_solver(lmmcp);
if ~oo_.deterministic_simulation.status
error('Perfect foresight simulation failed')
end
if any(oo_.endo_simul < 1)
error('y>1 constraint not enforced')
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment