diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc index fdba1fdeb1d34768569d2b383bb7e79ec3cce9e6..ee3f07f5de6584cc9c77e95573b272beb588f7b3 100644 --- a/src/ComputingTasks.cc +++ b/src/ComputingTasks.cc @@ -604,31 +604,35 @@ RamseyPolicyStatement::RamseyPolicyStatement(SymbolList symbol_list_arg, void RamseyPolicyStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) { - // ramsey_model_present indicates that the model is augmented with the FOC of the planner problem + // Copied from RamseyModelStatement::checkPass() mod_file_struct.ramsey_model_present = true; - // ramsey_policy_present indicates that ramsey_policy instruction for computation of first order approximation - // of a stochastic Ramsey problem if present in the *.mod file - mod_file_struct.ramsey_policy_present = true; - /* Fill in option_order of mod_file_struct - Since ramsey policy needs one further order of derivation (for example, for 1st order - approximation, it needs 2nd derivatives), we add 1 to the order declared by user */ + if (auto opt = options_list.get_if<OptionsList::SymbolListVal>("instruments")) + mod_file_struct.instruments = *opt; + + // Copied from StochSimulStatement::checkPass() + mod_file_struct.stoch_simul_present = true; + if (auto opt = options_list.get_if<OptionsList::NumVal>("order")) mod_file_struct.order_option = max(mod_file_struct.order_option, stoi(*opt)); - // Fill in mod_file_struct.partial_information if (auto opt = options_list.get_if<OptionsList::NumVal>("partial_information"); opt && *opt == "true") mod_file_struct.partial_information = true; - // Option k_order_solver (implicit when order >= 3) if (auto opt = options_list.get_if<OptionsList::NumVal>("k_order_solver"); (opt && *opt == "true") || mod_file_struct.order_option >= 3) mod_file_struct.k_order_solver = true; - // Fill list of instruments - if (auto opt = options_list.get_if<OptionsList::SymbolListVal>("instruments")) - mod_file_struct.instruments = *opt; + if (bool hp = options_list.contains("hp_filter"), + bandpass = options_list.contains("bandpass.indicator"), + one_sided_hp = options_list.contains("one_sided_hp_filter"); + (hp && bandpass) || (hp && one_sided_hp) || (bandpass && one_sided_hp)) + { + cerr << "ERROR: ramsey_policy: can only use one of hp, one-sided hp, and bandpass filters" + << endl; + exit(EXIT_FAILURE); + } try { @@ -653,7 +657,9 @@ RamseyPolicyStatement::writeOutput(ostream &output, [[maybe_unused]] const strin options_list.writeOutput(output); symbol_list.writeOutput("var_list_", output); - output << "ramsey_policy(var_list_);" << endl; + output << "[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_);" << endl + << "oo_.steady_state = oo_.dr.ys;" << endl + << "oo_.planner_objective_value = evaluate_planner_objective(M_, options_, oo_);" << endl; } void diff --git a/src/ModFile.cc b/src/ModFile.cc index 1a800a9a8dd14f303a4587bcfd3d134e3a3b97cc..da331f8e8b80cbf43e843e91e4d78aa49d8a1a7b 100644 --- a/src/ModFile.cc +++ b/src/ModFile.cc @@ -132,7 +132,6 @@ ModFile::checkPass(bool nostrict, bool stochastic) bool stochastic_statement_present = mod_file_struct.stoch_simul_present || mod_file_struct.estimation_present || mod_file_struct.osr_present - || mod_file_struct.ramsey_policy_present || mod_file_struct.discretionary_policy_present || mod_file_struct.calib_smoother_present || mod_file_struct.identification_present @@ -151,8 +150,7 @@ ModFile::checkPass(bool nostrict, bool stochastic) exit(EXIT_FAILURE); } - if ((mod_file_struct.ramsey_model_present || mod_file_struct.ramsey_policy_present) - && mod_file_struct.discretionary_policy_present) + if (mod_file_struct.ramsey_model_present && mod_file_struct.discretionary_policy_present) { cerr << "ERROR: You cannot use the discretionary_policy command when you use either ramsey_model or ramsey_policy and vice versa" << endl; exit(EXIT_FAILURE); @@ -167,7 +165,7 @@ ModFile::checkPass(bool nostrict, bool stochastic) exit(EXIT_FAILURE); } - if (mod_file_struct.ramsey_constraints_present && !mod_file_struct.ramsey_model_present && !mod_file_struct.ramsey_policy_present) + if (mod_file_struct.ramsey_constraints_present && !mod_file_struct.ramsey_model_present) { cerr << "ERROR: A ramsey_constraints block requires the presence of a ramsey_model or ramsey_policy statement" << endl; exit(EXIT_FAILURE); @@ -513,7 +511,6 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, bool bool deterministic_model = !(mod_file_struct.stoch_simul_present || mod_file_struct.estimation_present || mod_file_struct.osr_present - || mod_file_struct.ramsey_policy_present || mod_file_struct.discretionary_policy_present || mod_file_struct.calib_smoother_present || mod_file_struct.identification_present @@ -575,8 +572,7 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, bool exit(EXIT_FAILURE); } - if ((mod_file_struct.ramsey_model_present || mod_file_struct.ramsey_policy_present) - && symbol_table.exo_det_nbr() > 0) + if (mod_file_struct.ramsey_model_present && symbol_table.exo_det_nbr() > 0) { cerr << "ERROR: ramsey_model and ramsey_policy are incompatible with deterministic exogenous variables" << endl; exit(EXIT_FAILURE); @@ -590,7 +586,7 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, bool if (mod_file_struct.occbin_constraints_present && (mod_file_struct.osr_present || mod_file_struct.mom_estimation_present - || mod_file_struct.ramsey_model_present || mod_file_struct.ramsey_policy_present + || mod_file_struct.ramsey_model_present || mod_file_struct.discretionary_policy_present || mod_file_struct.extended_path_present || mod_file_struct.identification_present || mod_file_struct.sensitivity_present)) { @@ -898,7 +894,7 @@ ModFile::writeMOutput(const string &basename, bool clear_all, bool clear_global, << "options_.block = " << block << ";" << endl << "options_.bytecode = " << bytecode << ";" << endl << "options_.use_dll = " << use_dll << ";" << endl - << "options_.ramsey_policy = " << (mod_file_struct.ramsey_model_present || mod_file_struct.ramsey_policy_present) << ";" << endl + << "options_.ramsey_policy = " << mod_file_struct.ramsey_model_present << ";" << endl << "options_.discretionary_policy = " << mod_file_struct.discretionary_policy_present << ";" << endl; if (mod_file_struct.discretionary_policy_present) diff --git a/src/ModelEquationBlock.cc b/src/ModelEquationBlock.cc index 8b410ba0ead071200ce0a6f78cc0273b5c019c2b..d2a0c1d804a1044a801882a9cd9ea508b016293a 100644 --- a/src/ModelEquationBlock.cc +++ b/src/ModelEquationBlock.cc @@ -150,7 +150,7 @@ SteadyStateModel::checkPass(ModFileStructure &mod_file_struct, WarningConsolidat Ramsey model, since the steady_state_block should give the steady state *conditional* to those instruments) */ set<int> should_be_defined = symbol_table.getOrigEndogenous(); - if (mod_file_struct.ramsey_policy_present || mod_file_struct.ramsey_model_present) + if (mod_file_struct.ramsey_model_present) for (const auto &s : mod_file_struct.instruments.getSymbols()) should_be_defined.erase(symbol_table.getID(s)); for (int v : should_be_defined) diff --git a/src/Statement.hh b/src/Statement.hh index ce8e1eed592f3beeb37408babaaac4e8a78358a5..cd1585ffc009a56f9e6f021e77683601a90ec659 100644 --- a/src/Statement.hh +++ b/src/Statement.hh @@ -52,8 +52,6 @@ struct ModFileStructure bool optim_weights_present{false}; //! Whether a ramsey_model statement is present bool ramsey_model_present{false}; - //! Whether a ramsey_policy statement is present - bool ramsey_policy_present{false}; //! Whether a discretionary_objective statement is present bool discretionary_policy_present{false}; //! Whether a planner_objective statement is present