2016-04-04 22:55:33 +02:00
|
|
|
function [ts, DynareResults] = extended_path(initialconditions, samplesize, exogenousvariables, DynareOptions, DynareModel, DynareResults)
|
|
|
|
|
2011-12-05 10:58:39 +01:00
|
|
|
% Stochastic simulation of a non linear DSGE model using the Extended Path method (Fair and Taylor 1983). A time
|
2012-01-27 18:24:24 +01:00
|
|
|
% series of size T is obtained by solving T perfect foresight models.
|
|
|
|
%
|
2016-04-04 22:55:33 +02:00
|
|
|
% INPUTS
|
|
|
|
% o initialconditions [double] m*1 array, where m is the number of endogenous variables in the model.
|
|
|
|
% o samplesize [integer] scalar, size of the sample to be simulated.
|
|
|
|
% o exogenousvariables [double] T*n array, values for the structural innovations.
|
|
|
|
% o DynareOptions [struct] options_
|
|
|
|
% o DynareModel [struct] M_
|
|
|
|
% o DynareResults [struct] oo_
|
2012-01-27 18:24:24 +01:00
|
|
|
%
|
2016-04-04 22:55:33 +02:00
|
|
|
% OUTPUTS
|
|
|
|
% o ts [dseries] m*samplesize array, the simulations.
|
|
|
|
% o results [cell]
|
2012-01-27 18:24:24 +01:00
|
|
|
%
|
2011-12-05 10:58:39 +01:00
|
|
|
% ALGORITHM
|
2012-01-27 18:24:24 +01:00
|
|
|
%
|
2011-12-05 10:58:39 +01:00
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
|
2016-03-11 16:22:42 +01:00
|
|
|
% Copyright (C) 2009-2016 Dynare Team
|
2011-12-05 10:58:39 +01:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
|
|
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
2012-01-21 14:13:31 +01:00
|
|
|
|
2016-04-19 12:16:31 +02:00
|
|
|
[initialconditions, innovations, pfm, ep, verbosity, DynareOptions, DynareResults] = ...
|
2016-04-04 22:55:33 +02:00
|
|
|
extended_path_initialization(initialconditions, samplesize, exogenousvariables, DynareOptions, DynareModel, DynareResults);
|
2012-02-10 12:56:52 +01:00
|
|
|
|
2016-05-30 17:36:01 +02:00
|
|
|
[shocks, spfm_exo_simul, innovations, DynareResults] = extended_path_shocks(innovations, ep, exogenousvariables, samplesize,DynareModel,DynareOptions,DynareResults);
|
2012-02-04 16:26:22 +01:00
|
|
|
|
2016-04-04 22:55:33 +02:00
|
|
|
% Initialize the matrix for the paths of the endogenous variables.
|
|
|
|
endogenous_variables_paths = NaN(DynareModel.endo_nbr,samplesize+1);
|
|
|
|
endogenous_variables_paths(:,1) = initialconditions;
|
2012-01-27 18:24:24 +01:00
|
|
|
|
2011-12-12 14:48:26 +01:00
|
|
|
% Set waitbar (graphic or text mode)
|
2012-01-11 16:00:42 +01:00
|
|
|
hh = dyn_waitbar(0,'Please wait. Extended Path simulations...');
|
|
|
|
set(hh,'Name','EP simulations.');
|
2011-12-12 14:01:17 +01:00
|
|
|
|
2016-04-04 22:55:33 +02:00
|
|
|
% Initialize while-loop index.
|
|
|
|
t = 1;
|
2016-03-14 20:22:07 +01:00
|
|
|
|
2011-12-05 10:58:39 +01:00
|
|
|
% Main loop.
|
2016-04-04 22:55:33 +02:00
|
|
|
while (t <= samplesize)
|
2011-12-12 14:01:17 +01:00
|
|
|
if ~mod(t,10)
|
2016-04-04 22:55:33 +02:00
|
|
|
dyn_waitbar(t/samplesize,hh,'Please wait. Extended Path simulations...');
|
2011-12-12 14:01:17 +01:00
|
|
|
end
|
2011-12-05 10:58:39 +01:00
|
|
|
% Set period index.
|
|
|
|
t = t+1;
|
2016-04-04 22:55:33 +02:00
|
|
|
spfm_exo_simul(2,:) = shocks(t-1,:);
|
2016-04-29 23:23:07 +02:00
|
|
|
if t>2
|
|
|
|
% Set initial guess for the solver (using the solution of the
|
|
|
|
% previous period problem).
|
|
|
|
initialguess = [endogenousvariablespaths(:, 2:end), DynareResults.steady_state];
|
|
|
|
else
|
|
|
|
initialguess = [];
|
|
|
|
end
|
|
|
|
[endogenous_variables_paths(:,t), info_convergence, endogenousvariablespaths] = extended_path_core(ep.periods, DynareModel.endo_nbr, DynareModel.exo_nbr, innovations.positive_var_indx, ...
|
2016-04-04 22:55:33 +02:00
|
|
|
spfm_exo_simul, ep.init, endogenous_variables_paths(:,t-1), ...
|
|
|
|
DynareResults.steady_state, ...
|
2016-05-04 14:33:49 +02:00
|
|
|
verbosity, ep.use_bytecode, ep.stochastic.order, ...
|
2016-04-29 23:23:07 +02:00
|
|
|
DynareModel, pfm, ep.stochastic.algo, ep.solve_algo, ep.stack_solve_algo, ...
|
|
|
|
DynareOptions.lmmcp, ...
|
|
|
|
DynareOptions, ...
|
|
|
|
DynareResults, initialguess);
|
2016-04-04 22:55:33 +02:00
|
|
|
if ~info_convergence
|
|
|
|
msg = sprintf('No convergence of the (stochastic) perfect foresight solver (in period %s)!', int2str(t));
|
|
|
|
warning(msg)
|
|
|
|
break
|
2015-01-11 19:37:46 +01:00
|
|
|
end
|
2012-02-03 11:24:14 +01:00
|
|
|
end% (while) loop over t
|
2011-12-12 14:01:17 +01:00
|
|
|
|
2016-04-04 22:55:33 +02:00
|
|
|
% Close waitbar.
|
2012-01-11 16:00:42 +01:00
|
|
|
dyn_waitbar_close(hh);
|
2011-12-19 18:04:54 +01:00
|
|
|
|
2016-04-04 22:55:33 +02:00
|
|
|
% Set the initial period.
|
2016-03-11 13:54:15 +01:00
|
|
|
if isnan(DynareOptions.initial_period)
|
2014-08-12 18:59:10 +02:00
|
|
|
initial_period = dates(1,1);
|
|
|
|
else
|
2016-03-11 13:54:15 +01:00
|
|
|
initial_period = DynareOptions.initial_period;
|
2014-08-12 18:59:10 +02:00
|
|
|
end
|
2016-04-04 22:55:33 +02:00
|
|
|
|
|
|
|
% Return the simulated time series.
|
|
|
|
if any(isnan(endogenous_variables_paths(:)))
|
|
|
|
sl = find(~isnan(endogenous_variables_paths));
|
|
|
|
nn = size(endogenous_variables_paths, 1);
|
|
|
|
endogenous_variables_paths = reshape(endogenous_variables_paths(sl), nn, length(sl)/nn);
|
2013-12-09 12:32:20 +01:00
|
|
|
end
|
2016-04-04 22:55:33 +02:00
|
|
|
ts = dseries(transpose(endogenous_variables_paths), initial_period, cellstr(DynareModel.endo_names));
|
|
|
|
|
|
|
|
DynareResults.endo_simul = transpose(ts.data);
|
|
|
|
assignin('base', 'Simulated_time_series', ts);
|
2013-12-09 12:32:20 +01:00
|
|
|
|
2016-04-04 22:55:33 +02:00
|
|
|
if ~nargout || nargout<2
|
|
|
|
assignin('base', 'oo_', DynareResults);
|
|
|
|
end
|