From e173ad938bb09a7268bb78efb6b737ce42f2e7af Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Tue, 2 Nov 2021 18:19:43 +0100
Subject: [PATCH] evaluate_planner_objective.m: gracefully exit if decision
 rules are missing

---
 matlab/evaluate_planner_objective.m | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/matlab/evaluate_planner_objective.m b/matlab/evaluate_planner_objective.m
index 6f4fb89599..c37764ab6c 100644
--- a/matlab/evaluate_planner_objective.m
+++ b/matlab/evaluate_planner_objective.m
@@ -99,7 +99,11 @@ if options_.ramsey_policy
         planner_objective_value = struct('conditional', W, 'unconditional', EW);
     else
         planner_objective_value = struct('conditional', struct('zero_initial_multiplier', 0., 'steady_initial_multiplier', 0.), 'unconditional', 0.);
-        ys = oo_.dr.ys;
+        if isempty(oo_.dr) || ~isfield(oo_.dr,'ys')
+            error('evaluate_planner_objective requires decision rules to have previously been computed (e.g. by stoch_simul)')
+        else
+            ys = oo_.dr.ys;
+        end
         if options_.order == 1 || M_.hessian_eq_zero
             [U,Uy] = feval([M_.fname '.objective.static'],ys,zeros(1,exo_nbr), M_.params);
 
-- 
GitLab