From 8b5b7921f61682574ef9bafbfb7793e410f15553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 29 Apr 2016 23:23:07 +0200 Subject: [PATCH] Improved solver for (S)EP. Use previous solution as an initial condition for the perfect foresight problem. --- matlab/ep/extended_path.m | 15 ++++++++++++--- matlab/ep/extended_path_core.m | 21 ++++++++++++++------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/matlab/ep/extended_path.m b/matlab/ep/extended_path.m index 012292adc..7891373a1 100644 --- a/matlab/ep/extended_path.m +++ b/matlab/ep/extended_path.m @@ -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) diff --git a/matlab/ep/extended_path_core.m b/matlab/ep/extended_path_core.m index a1ffc76bb..f2bc8392d 100644 --- a/matlab/ep/extended_path_core.m +++ b/matlab/ep/extended_path_core.m @@ -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;