From b50424b5528b720b087a79ece9b617de430ea185 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Wed, 22 Jan 2025 15:42:00 +0100
Subject: [PATCH] Perfect foresight w/ expectation errors: improve error
 message for marginal linearization

In situations where the solution cannot be found for an informational period > 1
using the same completion share as for the first informational period, suggest
to decrease the value of the homotopy_max_completion_share option.

(cherry picked from commit 119f92fdef5fae9cc0b82553f57839604c7e96cf)
---
 .../perfect_foresight_with_expectation_errors_solver.m       | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_solver.m b/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_solver.m
index a7b63bfd5a..96cbee6b6f 100644
--- a/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_solver.m
+++ b/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_solver.m
@@ -89,7 +89,10 @@ while info_period <= periods
         homotopy_completion_share = oo_.deterministic_simulation.homotopy_completion_share;
         options_.simul.homotopy_max_completion_share = homotopy_completion_share;
     elseif oo_.deterministic_simulation.homotopy_completion_share ~= homotopy_completion_share
-        error('perfect_foresight_solver_with_expectation_errors: could not find a solution for information available at period %d with the same homotopy completion share as period 1\n', info_period)
+        %% NB: in the following message, we don’t use the %.3f formatter because it may round the
+        %% share to a greater number, which would lead to an incorrect suggestion
+        error('perfect_foresight_solver_with_expectation_errors: could not find a solution for information available at period %d with the same homotopy completion share as period 1; a possible solution is to retry the simulation with homotopy_max_completion_share=%s\n', ...
+              info_period, num2str(floor(oo_.deterministic_simulation.homotopy_completion_share*1000)/1000))
     end
 
     endo_simul(:, info_period:end) = oo_.endo_simul;
-- 
GitLab