diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc index 955d5bbbc8f8f6a3d239d83536080037876382f7..3e97a23ff6275897bc781496dd26f2da8005924a 100644 --- a/src/ComputingTasks.cc +++ b/src/ComputingTasks.cc @@ -34,6 +34,7 @@ using namespace std; #pragma GCC diagnostic pop #include <utility> +#include <algorithm> SteadyStatement::SteadyStatement(OptionsList options_list_arg) : options_list{move(options_list_arg)} @@ -1134,8 +1135,10 @@ DiscretionaryPolicyStatement::writeJsonOutput(ostream &output) const output << "}"; } -EstimationStatement::EstimationStatement(SymbolList symbol_list_arg, +EstimationStatement::EstimationStatement(const SymbolTable &symbol_table_arg, + SymbolList symbol_list_arg, OptionsList options_list_arg) : + symbol_table{symbol_table_arg}, symbol_list{move(symbol_list_arg)}, options_list{move(options_list_arg)} { @@ -1212,6 +1215,22 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli exit(EXIT_FAILURE); } + /* Check that we are not trying to estimate a parameter appearing in the + planner discount factor (see dynare#1173) */ + vector<int> estimated_params_in_planner_discount; + set_intersection(mod_file_struct.estimated_parameters.begin(), + mod_file_struct.estimated_parameters.end(), + mod_file_struct.parameters_in_planner_discount.begin(), + mod_file_struct.parameters_in_planner_discount.end(), + back_inserter(estimated_params_in_planner_discount)); + if (!estimated_params_in_planner_discount.empty()) + { + cerr << "ERROR: It is not possible to estimate a parameter (" + << symbol_table.getName(estimated_params_in_planner_discount[0]) + << ") that appears in the discount factor of the planner (i.e. in the 'planner_discount' option)." << endl; + exit(EXIT_FAILURE); + } + try { symbol_list.checkPass(warnings, { SymbolType::endogenous }); diff --git a/src/ComputingTasks.hh b/src/ComputingTasks.hh index 09d2fef85edc0eb12f4853bcfeb2fd49729e3104..53c6a96e8a2e0a30aa93d818b8a09a6e310b80a5 100644 --- a/src/ComputingTasks.hh +++ b/src/ComputingTasks.hh @@ -1,5 +1,5 @@ /* - * Copyright © 2003-2019 Dynare Team + * Copyright © 2003-2020 Dynare Team * * This file is part of Dynare. * @@ -314,10 +314,12 @@ public: class EstimationStatement : public Statement { private: + const SymbolTable &symbol_table; const SymbolList symbol_list; const OptionsList options_list; public: - EstimationStatement(SymbolList symbol_list_arg, + EstimationStatement(const SymbolTable &symbol_table_arg, + SymbolList symbol_list_arg, OptionsList options_list_arg); void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) override; void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override; diff --git a/src/NumericalInitialization.cc b/src/NumericalInitialization.cc index 3f7446c376315fdb9fa5b6ef3ae2fd5433de1f50..12eeb420428817e6570503a2adceef249ddb2f36 100644 --- a/src/NumericalInitialization.cc +++ b/src/NumericalInitialization.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2003-2019 Dynare Team + * Copyright © 2003-2020 Dynare Team * * This file is part of Dynare. * @@ -39,6 +39,10 @@ InitParamStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid { if (symbol_table.getName(symb_id) == "dsge_prior_weight") mod_file_struct.dsge_prior_weight_initialized = true; + + // Needed for the workaround discussed in dynare#1173 + if (symbol_table.getName(symb_id) == "optimal_policy_discount_factor") + param_value->collectVariables(SymbolType::parameter, mod_file_struct.parameters_in_planner_discount); } void diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc index 1207f43b7805264ae53e62ced6ad0a3b56937c05..316e79390c4bd2d100b5605e403c8edf81f2a247 100644 --- a/src/ParsingDriver.cc +++ b/src/ParsingDriver.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2003-2019 Dynare Team + * Copyright © 2003-2020 Dynare Team * * This file is part of Dynare. * @@ -1931,7 +1931,7 @@ ParsingDriver::set_corr_options(const string &name1, const string &name2, const void ParsingDriver::run_estimation() { - mod_file->addStatement(make_unique<EstimationStatement>(symbol_list, options_list)); + mod_file->addStatement(make_unique<EstimationStatement>(mod_file->symbol_table, symbol_list, options_list)); symbol_list.clear(); options_list.clear(); } diff --git a/src/Statement.hh b/src/Statement.hh index 908260b9d1fa3308edc23b6f6ef4a0edd392c5c3..efc293cfc66679b25fdef74e49e37418e2afe420 100644 --- a/src/Statement.hh +++ b/src/Statement.hh @@ -1,5 +1,5 @@ /* - * Copyright © 2006-2019 Dynare Team + * Copyright © 2006-2020 Dynare Team * * This file is part of Dynare. * @@ -134,6 +134,9 @@ public: /* Whether any of shock_decomposition, realtime_shock_decomposition and initial_condition_decomposition has the “with_epilogue” option */ bool with_epilogue_option{false}; + /* Lists symbol IDs of parameters that appear in a “planner_discount” option. + See dynare#1173 for more details. */ + set<int> parameters_in_planner_discount; }; class Statement