diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc
index 81afb452aede7bca7899b3dbd96eb309cee95364..9d79ef1d7fe9efd3f25c7a57b26b5bfb71844daa 100644
--- a/src/DynamicModel.cc
+++ b/src/DynamicModel.cc
@@ -4735,13 +4735,13 @@ DynamicModel::computeRamseyPolicyFOCs(const StaticModel &static_model)
       if (symbol_table.getType(symb_id) == SymbolType::endogenous && lag == 0)
         {
           neweqs.push_back(AddEqual(equations[0]->getNonZeroPartofEquation()->getDerivative(deriv_id), Zero));
-          if (int i = symbol_table.getEquationNumberForMultiplier(symb_id);
-              i != -1)
+          if (optional<int> i = symbol_table.getEquationNumberForMultiplier(symb_id);
+              i)
             {
               // This is a derivative w.r.t. a Lagrange multiplier
-              neweqs_lineno.push_back(old_equations_lineno[i]);
+              neweqs_lineno.push_back(old_equations_lineno[*i]);
               map<string, string> tags;
-              auto tmp = old_equation_tags.getTagsByEqn(i);
+              auto tmp = old_equation_tags.getTagsByEqn(*i);
               for (const auto &[key, value] : tmp)
                 tags[key] = value;
               neweqs_tags[neweqs.size()-1] = tags;
diff --git a/src/SymbolTable.cc b/src/SymbolTable.cc
index dae16a237768d302c85626994e217c08a5352532..0900016f69c04ccda4b72f01b28597360f054a7c 100644
--- a/src/SymbolTable.cc
+++ b/src/SymbolTable.cc
@@ -1087,13 +1087,13 @@ SymbolTable::getUltimateOrigSymbID(int symb_id) const
   return symb_id;
 }
 
-int
+optional<int>
 SymbolTable::getEquationNumberForMultiplier(int symb_id) const
 {
   for (const auto &aux_var : aux_vars)
     if (aux_var.get_symb_id() == symb_id && aux_var.get_type() == AuxVarType::multiplier)
       return aux_var.get_equation_number_for_multiplier();
-  return -1;
+  return nullopt;
 }
 
 const set<int> &
diff --git a/src/SymbolTable.hh b/src/SymbolTable.hh
index e5b21442fe205e6f4180e523bbefe90711c1cb61..50d451d9d939f87c842b2a028ba18196d6154d6c 100644
--- a/src/SymbolTable.hh
+++ b/src/SymbolTable.hh
@@ -464,8 +464,8 @@ public:
      no original variable (e.g. aux var for lead, Lagrange Multiplier or diff
      associated to a complex expression). */
   int getUltimateOrigSymbID(int symb_id) const;
-  //! If this is a Lagrange multiplier, return its associated equation number; otherwise return -1
-  int getEquationNumberForMultiplier(int symb_id) const;
+  //! If this is a Lagrange multiplier, return its associated equation number; otherwise return nullopt
+  optional<int> getEquationNumberForMultiplier(int symb_id) const;
   /* Return all the information about a given auxiliary variable. Throws
      UnknownSymbolIDException if it is not an aux var */
   const AuxVarInfo &getAuxVarInfo(int symb_id) const;