From da9e0acc2d038da49bf0b7ac576c75e9366410d5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Mon, 19 Jul 2021 12:37:17 +0200
Subject: [PATCH] VAR models: add a parameter representing the constant in the
 development of the var_expectation operator

---
 src/ModFile.cc | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/ModFile.cc b/src/ModFile.cc
index 6346c820..036cec41 100644
--- a/src/ModFile.cc
+++ b/src/ModFile.cc
@@ -579,6 +579,15 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, bool
       /* Create auxiliary parameters and the expression to be substituted into
          the var_expectations statement */
       expr_t subst_expr = dynamic_model.Zero;
+      if (var_model_table.isExistingVarModelName(vems->aux_model_name))
+        {
+          /* If the auxiliary model is a VAR, add a parameter corresponding to
+             the constant. */
+          string constant_param_name = "var_expectation_model_" + model_name + "_constant";
+          int constant_param_id = symbol_table.addSymbol(constant_param_name, SymbolType::parameter);
+          vems->aux_params_ids.push_back(constant_param_id);
+          subst_expr = dynamic_model.AddPlus(subst_expr, dynamic_model.AddVariable(constant_param_id));
+        }
       for (int lag = 0; lag < max_lag; lag++)
         for (auto variable : lhs)
           {
-- 
GitLab