ramsey_policy: implement fully at the preprocessor level
The implementation no longer relies on ramsey_policy.m at the MATLAB/Octave level. By the way, drop ModFileStructure::ramsey_model_present, which is now redundant.master
parent
e9babf0242
commit
a87f536799
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue