LMMCP: fix the purely backward and purely forward cases

Closes: #1720
time-shift
Sébastien Villemot 2020-10-21 16:30:40 +02:00
parent 4ba0f0a9c3
commit e21cb1ad6b
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
5 changed files with 90 additions and 9 deletions

View File

@ -75,10 +75,10 @@ else
oo_.deterministic_simulation.status = false;
end
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] = ...
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] = ...
sim1_purely_forward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_);
else % General case

View File

@ -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)
% - 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.
%
@ -73,22 +73,25 @@ end
if M.maximum_lag > 0
y0 = endogenousvariables(:, M.maximum_lag);
else
y0 = NaN(ny, 1);
y0 = NaN(M.endo_nbr, 1);
end
if M.maximum_lead > 0
yT = endogenousvariables(:, M.maximum_lag+periods+1);
else
yT = NaN(ny, 1);
yT = NaN(M.endo_nbr, 1);
end
z = endogenousvariables(:,M.maximum_lag+(1:periods));
illi = M.lead_lag_incidence';
[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_T = nonzeros(M.lead_lag_incidence(1:2,:)');
i_cols_T = nonzeros(M.lead_lag_incidence(1:(1+M.maximum_lag),:)');
if periods==1
i_cols_0 = nonzeros(M.lead_lag_incidence(2,:)');
i_cols_J0 = find(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(1+M.maximum_lag,:)');
else
i_cols_0 = [];
i_cols_J0 = [];

View File

@ -4,6 +4,8 @@ MODFILES = \
moments/example1_hp_test.mod \
moments/fs2000_post_moments.mod \
lmmcp/rbcii.mod \
lmmcp/purely_backward.mod \
lmmcp/purely_forward.mod \
ep/rbc_mc.mod \
estimation/TaRB/fs2000_tarb.mod \
observation_trends_and_prefiltering/MCMC/Trend_loglin_no_prefilt_first_obs_MC.mod \

View File

@ -0,0 +1,40 @@
// 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

View File

@ -0,0 +1,36 @@
// 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