From d03b74469afae3dd445bd621bdf2acb039396e87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Tue, 21 Sep 2021 17:17:36 +0200
Subject: [PATCH] ramsey_{model,policy}, discretionary_policy: check that
 instruments are declared endogenous

Closes: #72
(cherry picked from commit b12746190da9574f3ad44e15f72512f0824a8d9a)
---
 src/ParsingDriver.cc | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc
index 9f14c410..ec75edb8 100644
--- a/src/ParsingDriver.cc
+++ b/src/ParsingDriver.cc
@@ -2038,6 +2038,12 @@ ParsingDriver::ramsey_model()
   else if (planner_discount)
     error("ramsey_model: the 'planner_discount' option cannot be used when the 'optimal_policy_discount_factor' parameter is explicitly declared.");
 
+  // Check that instruments are declared endogenous (#72)
+  if (auto it = options_list.symbol_list_options.find("instruments");
+      it != options_list.symbol_list_options.end())
+    for (const auto &s : it->second.getSymbols())
+      check_symbol_is_endogenous(s);
+
   mod_file->addStatement(make_unique<RamseyModelStatement>(options_list));
   options_list.clear();
   planner_discount = nullptr;
@@ -2059,6 +2065,12 @@ ParsingDriver::ramsey_policy()
   else if (planner_discount)
     error("ramsey_policy: the 'planner_discount' option cannot be used when the 'optimal_policy_discount_factor' parameter is explicitly declared.");
 
+  // Check that instruments are declared endogenous (#72)
+  if (auto it = options_list.symbol_list_options.find("instruments");
+      it != options_list.symbol_list_options.end())
+    for (const auto &s : it->second.getSymbols())
+      check_symbol_is_endogenous(s);
+
   mod_file->addStatement(make_unique<RamseyPolicyStatement>(mod_file->symbol_table,
                                                             symbol_list, options_list));
   options_list.clear();
@@ -2114,6 +2126,12 @@ ParsingDriver::discretionary_policy()
     planner_discount = data_tree->One;
   init_param("optimal_policy_discount_factor", planner_discount);
 
+  // Check that instruments are declared endogenous (#72)
+  if (auto it = options_list.symbol_list_options.find("instruments");
+      it != options_list.symbol_list_options.end())
+    for (const auto &s : it->second.getSymbols())
+      check_symbol_is_endogenous(s);
+
   mod_file->addStatement(make_unique<DiscretionaryPolicyStatement>(symbol_list, options_list));
   symbol_list.clear();
   options_list.clear();
-- 
GitLab