Skip to content
Snippets Groups Projects
Commit b3ed7901 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Fixed bug in homotopy for perfect foresight models.

Homotopy was not working if nans or complex numbers were present in oo_.endo_simul.
parent 3b41aa0e
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,9 @@ if options_.debug ...@@ -55,6 +55,9 @@ if options_.debug
end end
end end
initperiods = 1:M_.maximum_lag;
lastperiods = (M_.maximum_endo_lag+options_.periods+1):(M_.maximum_endo_lag+options_.periods+M_.maximum_endo_lead);
% Disable warnings if homotopy % Disable warnings if homotopy
if ~options_.no_homotopy if ~options_.no_homotopy
warning off all warning off all
...@@ -69,6 +72,7 @@ if ~oo_.deterministic_simulation.status && ~options_.no_homotopy ...@@ -69,6 +72,7 @@ if ~oo_.deterministic_simulation.status && ~options_.no_homotopy
exosim = oo_.exo_simul; exosim = oo_.exo_simul;
exoinit = repmat(oo_.exo_steady_state',M_.maximum_lag+options_.periods+M_.maximum_lead,1); exoinit = repmat(oo_.exo_steady_state',M_.maximum_lag+options_.periods+M_.maximum_lead,1);
endosim = oo_.endo_simul; endosim = oo_.endo_simul;
endoinit = repmat(oo_.steady_state, 1,M_.maximum_lag+options_.periods+M_.maximum_lead); endoinit = repmat(oo_.steady_state, 1,M_.maximum_lag+options_.periods+M_.maximum_lead);
...@@ -79,6 +83,7 @@ if ~oo_.deterministic_simulation.status && ~options_.no_homotopy ...@@ -79,6 +83,7 @@ if ~oo_.deterministic_simulation.status && ~options_.no_homotopy
fprintf('Iter. \t | Lambda \t | status \t | Max. residual\n') fprintf('Iter. \t | Lambda \t | status \t | Max. residual\n')
fprintf('++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n') fprintf('++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n')
while (step > options_.dynatol.x) while (step > options_.dynatol.x)
if ~isequal(step,1) if ~isequal(step,1)
...@@ -96,9 +101,18 @@ if ~oo_.deterministic_simulation.status && ~options_.no_homotopy ...@@ -96,9 +101,18 @@ if ~oo_.deterministic_simulation.status && ~options_.no_homotopy
% Compute convex combination for exo path and initial/terminal endo conditions % Compute convex combination for exo path and initial/terminal endo conditions
% But take care of not overwriting the computed part of oo_.endo_simul % But take care of not overwriting the computed part of oo_.endo_simul
oo_.exo_simul = exosim*new_weight + exoinit*(1-new_weight); oo_.exo_simul = exosim*new_weight + exoinit*(1-new_weight);
endocombi = endosim*new_weight + endoinit*(1-new_weight);
oo_.endo_simul(:,1:M_.maximum_endo_lag) = endocombi(:,1:M_.maximum_endo_lag); oo_.endo_simul(:,[initperiods, lastperiods]) = ...
oo_.endo_simul(:,(end-M_.maximum_endo_lead):end) = endocombi(:,(end-M_.maximum_endo_lead):end); new_weight*oo_.endo_simul(:,[initperiods, lastperiods])+(1-new_weight)*endoinit(:,[initperiods, lastperiods]);
path_with_nans = any(any(isnan(oo_.endo_simul)));
path_with_cplx = any(any(~isreal(oo_.endo_simul)));
if isequal(iteration,1) && (path_with_nans || path_with_cplx)
oo_.endo_simul(:,M_.maximum_lag+1:end-M_.maximum_lead) = endoinit(:,1:options_.periods);
elseif path_with_nans || path_with_cplx
oo_.endo_simul(:,M_.maximum_lag+1:end-M_.maximum_lead) = saved_endo_simul(:,1+M_.maximum_endo_lag:end-M_.maximum_endo_lead);
end
saved_endo_simul = oo_.endo_simul; saved_endo_simul = oo_.endo_simul;
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment