Preprocessor: replace exogenous with lead/lags by auxiliary variables in deterministic models

Several tests need to be adapted, because they were implicitly making the
assumption that there is no auxiliary variable.

Incidentally, this closes #1731. This commit therefore also removes the
workaround introduced in 0391dbbeb1.
time-shift
Sébastien Villemot 2020-11-09 16:30:54 +01:00
parent 77438198a8
commit fcb52478e4
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
10 changed files with 35 additions and 44 deletions

View File

@ -1137,9 +1137,8 @@ equations using the ``write_latex_static_model`` command.
* Endogenous variables with leads or lags greater or equal
than two will have been removed, replaced by new auxiliary
variables and equations,
* For a stochastic model, exogenous variables with leads or
lags will also have been replaced by new auxiliary variables
and equations.
* Exogenous variables with leads or lags will also have been replaced
by new auxiliary variables and equations.
For the required LaTeX packages, see
:comm:`write_latex_original_model`.
@ -1221,9 +1220,8 @@ auxiliary endogenous variables—along with corresponding auxiliary
equations—which will appear in the final output.
The main transformation concerns leads and lags. Dynare will perform a
transformation of the model so that there is only one lead and one lag
on endogenous variables and, in the case of a stochastic model, no
leads/lags on exogenous variables.
transformation of the model so that there is only one lead and one lag on
endogenous variables and no leads/lags on exogenous variables.
This transformation is achieved by the creation of auxiliary variables
and corresponding equations. For example, if ``x(+2)`` exists in the

View File

@ -38,7 +38,7 @@ function [endogenousvariables, info] = sim1_linear(endogenousvariables, exogenou
% to center the variables around the deterministic steady state to solve the
% perfect foresight model.
% Copyright (C) 2015-2017 Dynare Team
% Copyright (C) 2015-2020 Dynare Team
%
% This file is part of Dynare.
%
@ -159,16 +159,9 @@ for it = (maximum_lag+1):(maximum_lag+periods)
nv = length(vv);
iA(iv+m,:) = [i_rows(rr),i_cols_A(cc),vv];
end
if M.maximum_exo_lag > 0
% needed as jacobian for lagged exogenous variables is wrong
% in current version of Dynare
zz = Y(i_cols);
res(i_rows) = dynamicmodel(zz, exogenousvariables, params, steadystate_y, it);
else
z(jendo) = Y(i_cols);
z(jexog) = transpose(exogenousvariables(it,:));
res(i_rows) = jacobian*z;
end
z(jendo) = Y(i_cols);
z(jexog) = transpose(exogenousvariables(it,:));
res(i_rows) = jacobian*z;
m = m + nv;
i_rows = i_rows + ny;
i_cols = i_cols + ny;
@ -251,4 +244,4 @@ end
if verbose
skipline();
end
end

@ -1 +1 @@
Subproject commit 5d564eed071b009ae382440435ede70be163ca39
Subproject commit 9bca65c7e525a2415fe46b27e8760208b22aba9d

View File

@ -1,4 +1,4 @@
// Same model as sim_exo_lead_lag_aux_vars.mod, but no auxiliary variables to deal with leads and lags
// Same model as sim_exo_lead_lag_aux_vars.mod, but no user-crafted auxiliary variables to deal with leads and lags
var c k z_forward z_backward;
varexo x;
@ -53,7 +53,7 @@ end
clear base_results
base_results_aux_vars=load('sim_exo_lead_lag_aux_vars_results.mat');
if max(abs(base_results_aux_vars.oo_.endo_simul(strmatch('x_lag_3',base_results_aux_vars.M_.endo_names,'exact'),1:end-base_results_aux_vars.M_.maximum_lead-1)' -...
oo_.exo_simul(1:end-M_.maximum_lead-M_.maximum_lag,strmatch('x', M_.exo_names, 'exact'))))>1e-8
if max(abs(base_results_aux_vars.oo_.endo_simul(strmatch('x_lag_3',base_results_aux_vars.M_.endo_names,'exact'),base_results_aux_vars.M_.maximum_lag+3:end-base_results_aux_vars.M_.maximum_lead)' -...
oo_.exo_simul(M_.maximum_lag:end-M_.maximum_lead-3,strmatch('x', M_.exo_names, 'exact'))))>1e-8
error('Translation of aux vars is wrong')
end
end

View File

@ -1,4 +1,4 @@
// Same model as sim_lead_lag_aux_vars.mod, but no auxiliary variables to deal with leads and lags
// Same model as sim_lead_lag_aux_vars.mod, but no user-crafted auxiliary variables to deal with leads and lags
var c k z_forward z_backward;
varexo x;
@ -57,7 +57,7 @@ end
clear base_results
base_results_aux_vars=load('sim_lead_lag_aux_vars_results.mat');
if max(abs(base_results_aux_vars.oo_.endo_simul(strmatch('x_lag_3',base_results_aux_vars.M_.endo_names,'exact'),1:end-base_results_aux_vars.M_.maximum_lead-1)' -...
oo_.exo_simul(1:end-M_.maximum_lead-M_.maximum_lag,strmatch('x', M_.exo_names, 'exact'))))>1e-8
if max(abs(base_results_aux_vars.oo_.endo_simul(strmatch('x_lag_3',base_results_aux_vars.M_.endo_names,'exact'),base_results_aux_vars.M_.maximum_lag+3:end-base_results_aux_vars.M_.maximum_lead)' -...
oo_.exo_simul(M_.maximum_lag:end-M_.maximum_lead-3,strmatch('x', M_.exo_names, 'exact'))))>1e-8
error('Translation of aux vars is wrong')
end
end

View File

@ -81,4 +81,4 @@ rplot Capital;
O=load('rbc_det_exo_lag_2a_results');
fataltest(oo_.endo_simul(:,2:end),O.oo_.endo_simul,1);
fataltest(oo_.endo_simul(1:M_.orig_endo_nbr,:),O.oo_.endo_simul(1:O.M_.orig_endo_nbr,:),1);

View File

@ -81,4 +81,4 @@ rplot Capital;
O=load('rbc_det_exo_lag_2a_results');
fataltest(oo_.endo_simul(:,2:end),O.oo_.endo_simul,1);
fataltest(oo_.endo_simul(1:M_.orig_endo_nbr,:),O.oo_.endo_simul(1:O.M_.orig_endo_nbr,:),1);

View File

@ -83,8 +83,8 @@ rplot Capital;
D = load('rbc_det_results');
if norm(D.oo_.endo_simul(:,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(:,M_.maximum_lag+1:end-M_.maximum_lead)) > 1e-30;
disp(D.oo_.endo_simul(:,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(:,M_.maximum_lag+1:end-M_.maximum_lead));
if norm(D.oo_.endo_simul(1:D.M_.orig_endo_nbr,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(1:M_.orig_endo_nbr,M_.maximum_lag+1:end-M_.maximum_lead)) > 1e-30;
disp(D.oo_.endo_simul(1:D.M_.orig_endo_nbr,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(1:M_.orig_endo_nbr,M_.maximum_lag+1:end-M_.maximum_lead));
error('rbc_det_stack_solve_algo_7 failed');
end;
@ -109,8 +109,8 @@ if isoctave && options_.solve_algo==0
else
tol_crit=1e-8;
end
if norm(D.oo_.endo_simul(:,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(:,M_.maximum_lag+1:end-M_.maximum_lead)) > tol_crit;
disp(D.oo_.endo_simul(:,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(:,M_.maximum_lag+1:end-M_.maximum_lead));
if norm(D.oo_.endo_simul(1:D.M_.orig_endo_nbr,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(1:M_.orig_endo_nbr,M_.maximum_lag+1:end-M_.maximum_lead)) > tol_crit;
disp(D.oo_.endo_simul(1:D.M_.orig_endo_nbr,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(1:M_.orig_endo_nbr,M_.maximum_lag+1:end-M_.maximum_lead));
error(sprintf('rbc_det_stack_solve_algo_7 failed with solve_algo=%u',options_.solve_algo));
end;
@#endfor
@#endfor

View File

@ -83,8 +83,8 @@ rplot Capital;
D = load('rbc_det_results');
if norm(D.oo_.endo_simul(:,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(:,M_.maximum_lag+1:end-M_.maximum_lead)) > 1e-30;
disp(D.oo_.endo_simul(:,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(:,M_.maximum_lag+1:end-M_.maximum_lead));
if norm(D.oo_.endo_simul(1:D.M_.orig_endo_nbr,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(1:M_.orig_endo_nbr,M_.maximum_lag+1:end-M_.maximum_lead)) > 1e-30;
disp(D.oo_.endo_simul(1:D.M_.orig_endo_nbr,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(1:M_.orig_endo_nbr,M_.maximum_lag+1:end-M_.maximum_lead));
error('rbc_det_stack_solve_algo_7 failed');
end;
@ -109,8 +109,8 @@ if isoctave && options_.solve_algo==0
else
tol_crit=1e-8;
end
if norm(D.oo_.endo_simul(:,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(:,M_.maximum_lag+1:end-M_.maximum_lead)) > tol_crit;
disp(D.oo_.endo_simul(:,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(:,M_.maximum_lag+1:end-M_.maximum_lead));
if norm(D.oo_.endo_simul(1:D.M_.orig_endo_nbr,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(1:M_.orig_endo_nbr,M_.maximum_lag+1:end-M_.maximum_lead)) > tol_crit;
disp(D.oo_.endo_simul(1:D.M_.orig_endo_nbr,D.M_.maximum_lag+1:end-D.M_.maximum_lead) - oo_.endo_simul(1:M_.orig_endo_nbr,M_.maximum_lag+1:end-M_.maximum_lead));
error(sprintf('rbc_det_stack_solve_algo_7 failed with solve_algo=%u',options_.solve_algo));
end;
@#endfor
@#endfor

View File

@ -36,8 +36,8 @@ perfect_foresight_solver;
fh = fopen('ramst_data.m', 'w');
fprintf(fh, 'INIT__ = ''1Y'';\n');
fprintf(fh, 'NAMES__ = {''c'', ''k'', ''x''};\n');
fprintf(fh, 'TEX__ = {''c'', ''k'', ''x''};\n');
fprintf(fh, 'NAMES__ = {''c''; ''k''; ''x''};\n');
fprintf(fh, 'TEX__ = {''c''; ''k''; ''x''};\n');
fprintf(fh, 'c = [');
fprintf(fh, '%f ', oo_.endo_simul(1,:));
fprintf(fh, '];\n');
@ -50,8 +50,8 @@ fprintf(fh, '];\n');
fclose(fh);
INIT__ = '1Y';
NAMES__ = {'c', 'k', 'x'};
TEX__ = {'c', 'k', 'x'};
NAMES__ = {'c'; 'k'; 'x'};
TEX__ = {'c'; 'k'; 'x'};
eval('c = oo_.endo_simul(1,:);');
eval('k = oo_.endo_simul(2,:);');
eval('x = oo_.exo_simul'';');
@ -61,7 +61,7 @@ save('ramst_data.mat', 'INIT__', 'NAMES__', ...
fh = fopen('ramst_data.csv', 'w');
fprintf(fh, 'c,k,x\n');
for i = 1:size(oo_.endo_simul, 2);
fprintf(fh, '%f, ', oo_.endo_simul(:, i));
fprintf(fh, '%f, ', oo_.endo_simul(1:M_.orig_endo_nbr, i));
fprintf(fh, '%f\n', oo_.exo_simul(i));
end;
fclose(fh);