Commit e9f97e74 authored by MichelJuillard's avatar MichelJuillard

backward models: fixing adding explicit solution guess

parent f644f36e
Pipeline #300 failed with stages
in 62 minutes and 29 seconds
......@@ -40,32 +40,36 @@ global options_ M_ oo_
if nargin<3
Innovations = [];
guess = [];
elseif nargin<4
guess = [];
else
exosize = M_.maximum_exo_lag + samplesize + M_.maximum_exo_lead;
if isdseries(innovations)
if isdseries(initialconditions)
if innovations.nobs<samplesize
error('Time span in third argument is too short (should not be less than %s, the value of the second argument)', num2str(samplesize))
end
% Set array holding innovations values.
Innovations = zeros(samplesize, M_.exo_nbr);
Innovations = zeros(exosize, M_.exo_nbr);
exonames = M_.exo_names;
for i=1:M_.exo_nbr
if ismember(exonames{i}, innovations.name)
Innovations(:,i) = innovations{exonames{i}}.data(1:samplesize);
Innovations(:,i) = innovations{exonames{i}}.data(1:exosize);
else
disp(sprintf('Exogenous variable %s is not available in third argument, default value is zero.', exonames{i}));
end
end
else
if isempty(initialconditions)
if innovations.nobs<samplesize
if innovations.nobs < exosize
error('Time span in third argument is too short (should not be less than %s, the value of the second argument)', num2str(samplesize))
end
Innovations = zeros(samplesize, M_.exo_nbr);
exonames = M_.exo_names;
for i=1:M_.exo_nbr
if ismember(exonames{i}, innovations.name)
Innovations(:,i) = innovations{exonames{i}}.data(1:samplesize);
Innovations(:,i) = innovations{exonames{i}}.data(1:exosize);
else
disp(sprintf('Exogenous variable %s is not available in third argument, default value is zero.', exonames{i}));
end
......
......@@ -24,7 +24,7 @@ samplesize = varargin{2};
DynareOptions = varargin{3};
DynareModel = varargin{4};
DynareOutput = varargin{5};
guess = vararing{6};
guess = varargin{7};
% Test if the model is backward.
if DynareModel.maximum_lead
......@@ -180,15 +180,16 @@ else
end
% Initialization of the returned simulations.
if isempty(guess)
DynareOutput.endo_simul = NaN(DynareModel.endo_nbr, samplesize+ ...
initialconditions.nobs);
else
DynareOutput.endo_simul = guess;
end
DynareOutput.endo_simul = NaN(DynareModel.endo_nbr, samplesize+ ...
initialconditions.nobs);
for i=1:length(endonames)
if ismember(endonames{i}, initialconditions.name)
DynareOutput.endo_simul(i,1:initialconditions.nobs) = transpose(initialconditions{endonames{i}}.data);
DynareOutput.endo_simul(i,1:initialconditions.nobs) = ...
transpose(initialconditions{endonames{i}}.data);
if DynareOptions.use_current_guess
DynareOutput.endo_simul(i,initialconditions.nobs + 1) = ...
transpose(guess{endonames{i}}.data(initialconditions.nobs + 1));
end
end
end
......
......@@ -41,14 +41,14 @@ function [ysim, xsim] = simul_backward_nonlinear_model_(initialconditions, sampl
model_dynamic_s = str2func('dynamic_backward_model_for_simulation');
if ~isempty(innovations)
DynareOutput.exo_simul(initialconditions.nobs+(1:samplesize),:) = innovations;
DynareOutput.exo_simul = innovations;
end
% Simulations (call a Newton-like algorithm for each period).
for it = initialconditions.nobs+(1:samplesize)
ylag = DynareOutput.endo_simul(iy1,it-1); % Set lagged variables.
if DynareOptions.use_current_guess
DynareOutput.endo_simul(:,it);
y = DynareOutput.endo_simul(:,it);
else
y = DynareOutput.endo_simul(:,it-1); % A good guess for the initial conditions is the previous values for the endogenous variables.
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment