Commit 3e92f410 authored by Houtan Bastani's avatar Houtan Bastani
Browse files

ramsey_policy: allow discount factor to be an expression

parent 4e9f5e02
......@@ -4411,7 +4411,7 @@ This command accepts all options of @code{stoch_simul}, plus:
@table @code
@item planner_discount = @var{DOUBLE}
@item planner_discount = @var{EXPRESSION}
Declares the discount factor of the central planner. Default: @code{1.0}
@end table
......
......@@ -216,15 +216,6 @@ RamseyPolicyStatement::writeOutput(ostream &output, const string &basename) cons
output << "ramsey_policy(var_list_);\n";
}
string
RamseyPolicyStatement::getPlannerDiscount() const
{
OptionsList::num_options_t::const_iterator it = options_list.num_options.find("planner_discount");
if (it != options_list.num_options.end())
return it->second;
return "1.0";
}
DiscretionaryPolicyStatement::DiscretionaryPolicyStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg) :
symbol_list(symbol_list_arg),
......
......@@ -101,7 +101,6 @@ public:
const OptionsList &options_list_arg);
virtual void checkPass(ModFileStructure &mod_file_struct);
virtual void writeOutput(ostream &output, const string &basename) const;
virtual string getPlannerDiscount() const;
};
class DiscretionaryPolicyStatement : public Statement
......
......@@ -3016,7 +3016,7 @@ DynamicModel::replaceMyEquations(DynamicModel &dynamic_model) const
}
void
DynamicModel::computeRamseyPolicyFOCs(const StaticModel &static_model, const string &discount_factor)
DynamicModel::computeRamseyPolicyFOCs(const StaticModel &static_model)
{
// Add aux LM to constraints in equations
// equation[i]->lhs = rhs becomes equation[i]->AUX_LAMBDA_i*(lhs-rhs) = 0
......@@ -3051,9 +3051,14 @@ DynamicModel::computeRamseyPolicyFOCs(const StaticModel &static_model, const str
max_eq_lag = -lag;
}
// Get Discount Factor
assert(symbol_table.exists("ramsey_policy_discount_factor"));
int symb_id = symbol_table.getID("ramsey_policy_discount_factor");
assert(symbol_table.getType(symb_id) == eParameter);
expr_t discount_factor_node = AddVariable(symb_id, 0);
// Create (modified) Lagrangian (so that we can take the derivative once at time t)
expr_t lagrangian = Zero;
expr_t discount_factor_node = AddNonNegativeConstant(discount_factor);
for (i = 0; i < (int) equations.size(); i++)
for (int lag = -max_eq_lag; lag <= max_eq_lead; lag++)
{
......
......@@ -285,7 +285,7 @@ public:
void cloneDynamic(DynamicModel &dynamic_model) const;
//! Replaces model equations with derivatives of Lagrangian w.r.t. endogenous
void computeRamseyPolicyFOCs(const StaticModel &static_model, const string &discount_factor);
void computeRamseyPolicyFOCs(const StaticModel &static_model);
//! Replaces the model equations in dynamic_model with those in this model
void replaceMyEquations(DynamicModel &dynamic_model) const;
......
......@@ -1771,7 +1771,7 @@ o_plot_priors: PLOT_PRIORS EQUAL INT_NUMBER {driver.option_num("plot_priors", $3
o_aim_solver: AIM_SOLVER {driver.option_num("aim_solver", "1"); };
o_partial_information : PARTIAL_INFORMATION {driver.option_num("partial_information", "1"); };
o_planner_discount : PLANNER_DISCOUNT EQUAL non_negative_number { driver.option_num("planner_discount",$3); };
o_planner_discount : PLANNER_DISCOUNT EQUAL expression { driver.declare_ramsey_policy_discount_factor_parameter($3); };
o_bvar_prior_tau : BVAR_PRIOR_TAU EQUAL signed_number { driver.option_num("bvar_prior_tau", $3); };
o_bvar_prior_decay : BVAR_PRIOR_DECAY EQUAL non_negative_number { driver.option_num("bvar_prior_decay", $3); };
......
......@@ -243,18 +243,13 @@ ModFile::transformPass()
if (mod_file_struct.ramsey_policy_present)
{
StaticModel *planner_objective = NULL;
string planner_discount = "";
for (vector<Statement *>::iterator it = statements.begin(); it != statements.end(); it++)
{
PlannerObjectiveStatement *pos = dynamic_cast<PlannerObjectiveStatement *>(*it);
if (pos != NULL)
planner_objective = pos->getPlannerObjective();
RamseyPolicyStatement *rps = dynamic_cast<RamseyPolicyStatement *>(*it);
if (rps != NULL)
planner_discount = rps->getPlannerDiscount();
}
assert(planner_objective != NULL && !planner_discount.empty());
assert(planner_objective != NULL);
ramsey_policy_orig_eqn_nbr = dynamic_model.equation_number();
/*
......@@ -262,7 +257,7 @@ ModFile::transformPass()
we have to call computeDerivIDs (in computeRamseyPolicyFOCs and computingPass)
*/
dynamic_model.cloneDynamic(ramsey_FOC_equations_dynamic_model);
ramsey_FOC_equations_dynamic_model.computeRamseyPolicyFOCs(*planner_objective, planner_discount);
ramsey_FOC_equations_dynamic_model.computeRamseyPolicyFOCs(*planner_objective);
ramsey_FOC_equations_dynamic_model.replaceMyEquations(dynamic_model);
}
......
......@@ -166,6 +166,17 @@ ParsingDriver::declare_parameter(string *name, string *tex_name)
delete tex_name;
}
void
ParsingDriver::declare_ramsey_policy_discount_factor_parameter(expr_t exprnode)
{
string *ramseyParName_declare = new string("ramsey_policy_discount_factor");
string *ramseyParName_init = new string("ramsey_policy_discount_factor");
if (mod_file->symbol_table.exists(*ramseyParName_declare))
error("Symbol ramsey_policy_discount_factor is needed by Dynare when using a ramsey_policy Statement");
declare_parameter(ramseyParName_declare, NULL);
init_param(ramseyParName_init, exprnode);
}
void
ParsingDriver::begin_trend()
{
......@@ -1238,6 +1249,8 @@ ParsingDriver::end_planner_objective(expr_t expr)
void
ParsingDriver::ramsey_policy()
{
if (!mod_file->symbol_table.exists("ramsey_policy_discount_factor"))
declare_ramsey_policy_discount_factor_parameter(data_tree->One);
mod_file->addStatement(new RamseyPolicyStatement(symbol_list, options_list));
symbol_list.clear();
options_list.clear();
......
......@@ -213,6 +213,8 @@ public:
void declare_exogenous_det(string *name, string *tex_name = NULL);
//! Declares a parameter
void declare_parameter(string *name, string *tex_name = NULL);
//! Declares declare_ramsey_policy_discount_factor as a parameter and initializes it to exprnode
void declare_ramsey_policy_discount_factor_parameter(expr_t exprnode);
//! Adds a predetermined_variable
void add_predetermined_variable(string *name);
//! Declares and initializes a local parameter
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment