Improved solver for (S)EP.

Use previous solution as an initial condition for the perfect foresight problem.
time-shift
Stéphane Adjemian (Charybdis) 2016-04-29 23:23:07 +02:00
parent 80f1baad7e
commit 8b5b7921f6
2 changed files with 26 additions and 10 deletions

View File

@ -60,12 +60,21 @@ while (t <= samplesize)
% Set period index.
t = t+1;
spfm_exo_simul(2,:) = shocks(t-1,:);
[endogenous_variables_paths(:,t), info_convergence] = extended_path_core(ep.periods, DynareModel.endo_nbr, DynareModel.exo_nbr, innovations.positive_var_indx, ...
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, ...
spfm_exo_simul, ep.init, endogenous_variables_paths(:,t-1), ...
DynareResults.steady_state, ...
ep.verbosity, ep.use_bytecode, ep.stochastic.order, ...
DynareModel, pfm,ep.stochastic.algo, ep.solve_algo, ep.stack_solve_algo, ...
DynareOptions.lmmcp, DynareOptions, DynareResults);
DynareModel, pfm, ep.stochastic.algo, ep.solve_algo, ep.stack_solve_algo, ...
DynareOptions.lmmcp, ...
DynareOptions, ...
DynareResults, initialguess);
if ~info_convergence
msg = sprintf('No convergence of the (stochastic) perfect foresight solver (in period %s)!', int2str(t));
warning(msg)

View File

@ -1,8 +1,8 @@
function [y, info_convergence] = extended_path_core(periods,endo_nbr,exo_nbr,positive_var_indx, ...
function [y, info_convergence, endogenousvariablespaths] = extended_path_core(periods,endo_nbr,exo_nbr,positive_var_indx, ...
exo_simul,init,initial_conditions,...
steady_state, ...
verbosity,bytecode_flag,order,M,pfm,algo,solve_algo,stack_solve_algo,...
olmmcp,options,oo)
debug,bytecode_flag,order,M,pfm,algo,solve_algo,stack_solve_algo,...
olmmcp,options,oo,initialguess)
% Copyright (C) 2016 Dynare Team
%
@ -25,19 +25,26 @@ ep = options.ep;
if init% Compute first order solution (Perturbation)...
endo_simul = simult_(initial_conditions,oo.dr,exo_simul(2:end,:),1);
else
endo_simul = [initial_conditions repmat(steady_state,1,periods+1)];
if nargin==20 && ~isempty(initialguess)
% Note that the first column of initialguess should be equal to initial_conditions.
endo_simul = initialguess;
else
endo_simul = [initial_conditions repmat(steady_state,1,periods+1)];
end
end
oo.endo_simul = endo_simul;
% Solve a perfect foresight model.
% Keep a copy of endo_simul_1
if verbosity
if debug
save ep_test_1 endo_simul exo_simul
end
if bytecode_flag && ~ep.stochastic.order
[flag,tmp] = bytecode('dynamic',endo_simul,exo_simul, M_.params, endo_simul, periods);
else
flag = 1;
end
if flag
if order == 0
options.periods = periods;