diff --git a/preprocessor/ExprNode.cc b/preprocessor/ExprNode.cc index 1705c2f9a..c81a24d32 100644 --- a/preprocessor/ExprNode.cc +++ b/preprocessor/ExprNode.cc @@ -4316,12 +4316,12 @@ BinaryOpNode::substituteAdlAndDiff() const expr_t arg1subst = arg1->substituteAdlAndDiff(); int i = 1; - expr_t retval = datatree.AddTimes(datatree.AddVariable(datatree.symbol_table.addAdlParameter(adlparam, i), 0), - arg1subst->decreaseLeadsLags(i)); + int param_symb_id = datatree.symbol_table.getID(adlparam + "_lag_" + to_string(i)); + expr_t retval = datatree.AddTimes(datatree.AddVariable(param_symb_id, 0), arg1subst->decreaseLeadsLags(i)); i++; for (; i <= (int) arg2->eval(eval_context_t()); i++) retval = datatree.AddPlus(retval, - datatree.AddTimes(datatree.AddVariable(datatree.symbol_table.addAdlParameter(adlparam, i), 0), + datatree.AddTimes(datatree.AddVariable(datatree.symbol_table.getID(adlparam + "_lag_" + to_string(i)), 0), arg1subst->decreaseLeadsLags(i))); return retval; } diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index cb7e82e85..9072fc3b8 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -2596,6 +2596,11 @@ ParsingDriver::add_adl(expr_t arg1, string *name, string *lag) { expr_t id = data_tree->AddAdl(arg1, *name, data_tree->AddNonNegativeConstant(*lag)); + + // Declare parameters here so that parameters can be initialized after the model block + for (int i = 0; i < atoi(lag->c_str()); i++) + declare_parameter(new string(*name + "_lag_" + to_string(i+1))); + delete name; delete lag; return id; diff --git a/preprocessor/SymbolTable.cc b/preprocessor/SymbolTable.cc index dff6b9e1b..9a04d4cae 100644 --- a/preprocessor/SymbolTable.cc +++ b/preprocessor/SymbolTable.cc @@ -649,29 +649,6 @@ SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_le return symb_id; } -int -SymbolTable::addAdlParameter(const string &basename, int lag) throw (FrozenException) -{ - ostringstream varname; - varname << basename << "_lag_" << lag; - - try - { - int symb_id = addSymbol(varname.str(), eParameter); - adl_params.push_back(symb_id); - return symb_id; - } - catch (AlreadyDeclaredException &e) - { - int symb_id = getID(varname.str()); - if (find(adl_params.begin(), adl_params.end(), symb_id) != adl_params.end()) - return symb_id; - - cerr << "ERROR: you should rename your variable called " << varname.str() << ", this name is internally used by Dynare" << endl; - exit(EXIT_FAILURE); - } -} - int SymbolTable::addEndoLeadAuxiliaryVar(int index, expr_t expr_arg) throw (FrozenException) { diff --git a/preprocessor/SymbolTable.hh b/preprocessor/SymbolTable.hh index 81070b00c..cf09c59a5 100644 --- a/preprocessor/SymbolTable.hh +++ b/preprocessor/SymbolTable.hh @@ -153,9 +153,6 @@ private: //! Stores the list of observed exogenous variables vector varexobs; - //! Stores list of parameters declared in adl substitution - vector adl_params; - public: SymbolTable(); //! Thrown when trying to access an unknown symbol (by name) @@ -287,10 +284,6 @@ public: //! Adds an auxiliary variable when var_model is used with an order that is greater in absolute value //! than the largest lag present in the model. int addVarModelEndoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag, expr_t expr_arg) throw (AlreadyDeclaredException, FrozenException); - /* - // Adds a parameter for the transformation of the adl operator - */ - int addAdlParameter(const string &basename, int lag) throw (FrozenException); //! Returns the number of auxiliary variables int AuxVarsSize() const diff --git a/tests/ecb/contribution-plots/var.mod b/tests/ecb/contribution-plots/var.mod index 5f487ca7b..026e1a518 100644 --- a/tests/ecb/contribution-plots/var.mod +++ b/tests/ecb/contribution-plots/var.mod @@ -15,20 +15,16 @@ model; end; +// Must be calibrated after the model block +p_ffr_ffr_lag_1 = 1; +p_ffr_ffr_lag_2 = p_ffr_ffr_lag_1*.5; +p_ffr_unrate_lag_1 = 2; +p_ffr_cpi_lag_1 = 3; + // Actual paths for the variables. ds1 = dseries(randn(30, 3), 1, {'ffr', 'unrate', 'cpi'}); // Baseline paths for the variables. ds0 = dseries(zeros(30, 3), 1, {'ffr', 'unrate', 'cpi'}); -// Calibration of some ADL parameters, we need to fix the preprocessor in oder to allow the usual syntax. -idp = strmatch('p_ffr_ffr_lag_1', M_.param_names, 'exact'); -M_.params(idp) = 1; -idp = strmatch('p_ffr_ffr_lag_2', M_.param_names, 'exact'); -M_.params(idp) = 2; -idp = strmatch('p_ffr_unrate_lag_1', M_.param_names, 'exact'); -M_.params(idp) = 3; -idp = strmatch('p_ffr_cpi_lag_1', M_.param_names, 'exact'); -M_.params(idp) = 4; - plot_contributions('eqnum', 'ffr', ds1, ds0); \ No newline at end of file