finishing ramsey_model implementation

time-shift
Michel Juillard 2014-03-09 09:52:44 +01:00
parent d945395a15
commit fabcbb7042
10 changed files with 229 additions and 30 deletions

View File

@ -202,6 +202,10 @@ RamseyModelStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol
void
RamseyModelStatement::writeOutput(ostream &output, const string &basename) const
{
// options_.ramsey_policy indicates that a Ramsey model is present in the *.mod file
// this affects the computation of the steady state that uses a special algorithm
// It should probably rather be a M_ field, but we leave it in options_ for historical reason
output << "options_.ramsey_policy = 1;\n";
}
RamseyPolicyStatement::RamseyPolicyStatement(const SymbolList &symbol_list_arg,
@ -214,6 +218,10 @@ RamseyPolicyStatement::RamseyPolicyStatement(const 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
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

View File

@ -39,7 +39,7 @@ ModFile::ModFile(WarningConsolidation &warnings_arg)
steady_state_model(symbol_table, num_constants, external_functions_table, static_model),
linear(false), block(false), byte_code(false), use_dll(false), no_static(false),
differentiate_forward_vars(false),
nonstationary_variables(false), ramsey_policy_orig_eqn_nbr(0),
nonstationary_variables(false), ramsey_model_orig_eqn_nbr(0),
warnings(warnings_arg)
{
}
@ -113,7 +113,7 @@ ModFile::checkPass()
(*it)->checkPass(mod_file_struct, warnings);
// Check the steady state block
steady_state_model.checkPass(mod_file_struct.ramsey_policy_present, warnings);
steady_state_model.checkPass(mod_file_struct.ramsey_model_present, warnings);
// If order option has not been set, default to 2
if (!mod_file_struct.order_option)
@ -136,12 +136,12 @@ ModFile::checkPass()
exit(EXIT_FAILURE);
}
if (((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)
&& !mod_file_struct.planner_objective_present)
|| (!(mod_file_struct.ramsey_policy_present || mod_file_struct.discretionary_policy_present)
|| (!(mod_file_struct.ramsey_model_present || mod_file_struct.discretionary_policy_present)
&& mod_file_struct.planner_objective_present))
{
cerr << "ERROR: A planner_objective statement must be used with a ramsey_policy or a discretionary_policy statement and vice versa." << endl;
cerr << "ERROR: A planner_objective statement must be used with a ramsey_model, a ramsey_policy or a discretionary_policy statement and vice versa." << endl;
exit(EXIT_FAILURE);
}
@ -246,9 +246,9 @@ ModFile::checkPass()
}
if (dynamic_model.staticOnlyEquationsNbr() > 0 &&
(mod_file_struct.ramsey_policy_present || mod_file_struct.discretionary_policy_present))
(mod_file_struct.ramsey_model_present || mod_file_struct.discretionary_policy_present))
{
cerr << "ERROR: marking equations as [static] or [dynamic] is not possible with ramsey_policy or discretionary_policy" << endl;
cerr << "ERROR: marking equations as [static] or [dynamic] is not possible with ramsey_model, ramsey_policy or discretionary_policy" << endl;
exit(EXIT_FAILURE);
}
@ -330,7 +330,7 @@ ModFile::transformPass(bool nostrict)
dynamic_model.removeTrendVariableFromEquations();
}
if (mod_file_struct.ramsey_policy_present)
if (mod_file_struct.ramsey_model_present)
{
StaticModel *planner_objective = NULL;
for (vector<Statement *>::iterator it = statements.begin(); it != statements.end(); it++)
@ -340,7 +340,7 @@ ModFile::transformPass(bool nostrict)
planner_objective = pos->getPlannerObjective();
}
assert(planner_objective != NULL);
ramsey_policy_orig_eqn_nbr = dynamic_model.equation_number();
ramsey_model_orig_eqn_nbr = dynamic_model.equation_number();
/*
clone the model then clone the new equations back to the original because
@ -395,11 +395,11 @@ ModFile::transformPass(bool nostrict)
/*
Enforce the same number of equations and endogenous, except in three cases:
- ramsey_policy is used
- ramsey_model, ramsey_policy or discretionary_policy is used
- a BVAR command is used and there is no equation (standalone BVAR estimation)
- nostrict option is passed and there are more endogs than equations (dealt with before freeze)
*/
if (!(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)
&& !(mod_file_struct.bvar_present && dynamic_model.equation_number() == 0)
&& (dynamic_model.equation_number() != symbol_table.endo_nbr()))
{
@ -419,11 +419,11 @@ ModFile::transformPass(bool nostrict)
exit(EXIT_FAILURE);
}
if (!mod_file_struct.ramsey_policy_present)
if (!mod_file_struct.ramsey_model_present)
cout << "Found " << dynamic_model.equation_number() << " equation(s)." << endl;
else
{
cout << "Found " << ramsey_policy_orig_eqn_nbr << " equation(s)." << endl;
cout << "Found " << ramsey_model_orig_eqn_nbr << " equation(s)." << endl;
cout << "Found " << dynamic_model.equation_number() << " FOC equation(s) for Ramsey Problem." << endl;
}
@ -461,7 +461,7 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output)
{
if (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.identification_present
|| mod_file_struct.ramsey_model_present || mod_file_struct.identification_present
|| mod_file_struct.calib_smoother_present)
static_model.set_cutoff_to_zero();
@ -476,7 +476,7 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output)
if (mod_file_struct.simul_present || mod_file_struct.check_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.identification_present
|| mod_file_struct.ramsey_model_present || mod_file_struct.identification_present
|| mod_file_struct.calib_smoother_present)
{
if (mod_file_struct.simul_present)
@ -485,7 +485,7 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output)
{
if (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.identification_present
|| mod_file_struct.ramsey_model_present || mod_file_struct.identification_present
|| mod_file_struct.calib_smoother_present)
dynamic_model.set_cutoff_to_zero();
if (mod_file_struct.order_option < 1 || mod_file_struct.order_option > 3)
@ -714,8 +714,8 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, b
if (block && !byte_code)
mOutputFile << "addpath " << basename << ";" << endl;
if (mod_file_struct.ramsey_policy_present)
mOutputFile << "M_.orig_eq_nbr = " << ramsey_policy_orig_eqn_nbr << ";" << endl;
if (mod_file_struct.ramsey_model_present)
mOutputFile << "M_.orig_eq_nbr = " << ramsey_model_orig_eqn_nbr << ";" << endl;
if (dynamic_model.equation_number() > 0)
{
@ -799,7 +799,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, b
}
// Create steady state file
steady_state_model.writeSteadyStateFile(basename, mod_file_struct.ramsey_policy_present);
steady_state_model.writeSteadyStateFile(basename, mod_file_struct.ramsey_model_present);
cout << "done" << endl;
}
@ -884,7 +884,7 @@ void
ModFile::writeExternalFiles(const string &basename, FileOutputType output, bool cuda) const
{
writeModelCC(basename, cuda);
steady_state_model.writeSteadyStateFileCC(basename, mod_file_struct.ramsey_policy_present, cuda);
steady_state_model.writeSteadyStateFileCC(basename, mod_file_struct.ramsey_model_present, cuda);
dynamic_model.writeDynamicFile(basename, block, byte_code, use_dll, mod_file_struct.order_option);

View File

@ -93,7 +93,7 @@ public:
eval_context_t global_eval_context;
//! Stores the original number of equations in the model_block
int ramsey_policy_orig_eqn_nbr;
int ramsey_model_orig_eqn_nbr;
//! Stores the list of extra files to be transefered during a parallel run
/*! (i.e. option parallel_local_files of model block) */

View File

@ -29,6 +29,7 @@ ModFileStructure::ModFileStructure() :
osr_present(false),
osr_params_present(false),
optim_weights_present(false),
ramsey_model_present(false),
ramsey_policy_present(false),
discretionary_policy_present(false),
planner_objective_present(false),

View File

@ -48,6 +48,8 @@ public:
bool osr_params_present;
//! Whether an optim weight statement is present
bool optim_weights_present;
//! Whether a ramsey_model statement is present
bool ramsey_model_present;
//! Whether a ramsey_policy statement is present
bool ramsey_policy_present;
//! Whether a discretionary_objective statement is present

View File

@ -56,7 +56,7 @@ SteadyStateModel::addMultipleDefinitions(const vector<int> &symb_ids, expr_t exp
}
void
SteadyStateModel::checkPass(bool ramsey_policy, WarningConsolidation &warnings) const
SteadyStateModel::checkPass(bool ramsey_model, WarningConsolidation &warnings) const
{
if (def_table.size() == 0)
return;
@ -74,7 +74,7 @@ SteadyStateModel::checkPass(bool ramsey_policy, WarningConsolidation &warnings)
warnings << "WARNING: in the 'steady_state_model' block, variable '" << symbol_table.getName(symb_ids[j]) << "' is declared twice" << endl;
// Check that expression has no undefined symbol
if (!ramsey_policy)
if (!ramsey_model)
{
set<int> used_symbols;
const expr_t &expr = def_table[i].second;
@ -105,7 +105,7 @@ SteadyStateModel::checkPass(bool ramsey_policy, WarningConsolidation &warnings)
}
void
SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_policy) const
SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model) const
{
if (def_table.size() == 0)
return;
@ -153,7 +153,7 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_polic
}
void
SteadyStateModel::writeSteadyStateFileCC(const string &basename, bool ramsey_policy, bool cuda) const
SteadyStateModel::writeSteadyStateFileCC(const string &basename, bool ramsey_model, bool cuda) const
{
string filename = basename + "_steadystate.cc";

View File

@ -41,15 +41,15 @@ public:
void addMultipleDefinitions(const vector<int> &symb_ids, expr_t expr);
//! Checks that definitions are in a recursive order, and that no variable is declared twice
/*!
\param[in] ramsey_policy Is there a ramsey_policy statement in the MOD file? If yes, then disable the check on the recursivity of the declarations
\param[in] ramsey_model Is there a Ramsey model in the MOD file? If yes, then disable the check on the recursivity of the declarations
*/
void checkPass(bool ramsey_policy, WarningConsolidation &warnings) const;
void checkPass(bool ramsey_model, WarningConsolidation &warnings) const;
//! Write the steady state file
/*!
\param[in] ramsey_policy Is there a ramsey_policy statement in the MOD file? If yes, then use the "ys" in argument of the steady state file as initial values
\param[in] ramsey_model Is there a Ramsey model in the MOD file? If yes, then use the "ys" in argument of the steady state file as initial values
*/
void writeSteadyStateFile(const string &basename, bool ramsey_policy) const;
void writeSteadyStateFileCC(const string &basename, bool ramsey_policy, bool cuda) const;
void writeSteadyStateFile(const string &basename, bool ramsey_model) const;
void writeSteadyStateFileCC(const string &basename, bool ramsey_model, bool cuda) const;
};
#endif

View File

@ -21,6 +21,8 @@ MODFILES = \
optimal_policy/osr_example.mod \
optimal_policy/ramsey.mod \
optimal_policy/nk_ramsey.mod \
optimal_policy/nk_ramsey_model.mod \
optimal_policy/nk_ramsey_det.mod \
optimal_policy/nk_ramsey_expectation.mod \
optimal_policy/nk_ramsey_expectation_a.mod \
optimal_policy/mult_elimination_test.mod \

View File

@ -0,0 +1,96 @@
//MODEL:
//test on Dynare to find the lagrangean multipliers.
//We consider a standard NK model. We use the FOCS of the competitive economy and we aim at calculating the Ramsey optimal problem.
//------------------------------------------------------------------------------------------------------------------------
//1. Variable declaration
//------------------------------------------------------------------------------------------------------------------------
var pai, c, n, r, a;
//4 variables + 1 shock
varexo u;
//------------------------------------------------------------------------------------------------------------------------
// 2. Parameter declaration and calibration
//-------------------------------------------------------------------------------------------------------------------------
parameters beta, rho, epsilon, omega, phi, gamma;
beta=0.99;
gamma=3; //Frish elasticity
omega=17; //price stickyness
epsilon=8; //elasticity for each variety of consumption
phi=1; //coefficient associated to labor effort disutility
rho=0.95; //coefficient associated to productivity shock
//-----------------------------------------------------------------------------------------------------------------------
// 3. The model
//-----------------------------------------------------------------------------------------------------------------------
model;
a=rho*(a(-1))+u;
1/c=beta*(1/(c(+1)))*(r/(pai(+1))); //euler
omega*pai*(pai-1)=beta*omega*(c/(c(+1)))*(pai(+1))*(pai(+1)-1)+epsilon*exp(a)*n*(c/exp(a)*phi*n^gamma-(epsilon-1)/epsilon); //NK pc
//pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega-exp(a)*n*(epsilon-1)/(omega*c); //NK pc
(exp(a))*n=c+(omega/2)*((pai-1)^2);
end;
//--------------------------------------------------------------------------------------------------------------------------
// 4. Steady state
//---------------------------------------------------------------------------------------------------------------------------
initval;
pai=1;
r=1/beta;
c=0.9671684882;
n=0.9671684882;
a=0;
end;
//---------------------------------------------------------------------------------------------------------------------------
// 5. shocks
//---------------------------------------------------------------------------------------------------------------------------
shocks;
var u;
periods 1;
values 0.008;
end;
//--------------------------------------------------------------------------------------------------------------------------
// 6. Ramsey problem
//--------------------------------------------------------------------------------------------------------------------------
planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma)));
write_latex_static_model;
ramsey_model(planner_discount=0.99);
options_.ramsey_policy=1;
steady;
options_.simul.maxit = 20;
simul(periods=100);
rplot r;

View File

@ -0,0 +1,90 @@
//MODEL:
//test on Dynare to find the lagrangean multipliers.
//We consider a standard NK model. We use the FOCS of the competitive economy and we aim at calculating the Ramsey optimal problem.
//------------------------------------------------------------------------------------------------------------------------
//1. Variable declaration
//------------------------------------------------------------------------------------------------------------------------
var pai, c, n, r, a;
//4 variables + 1 shock
varexo u;
//------------------------------------------------------------------------------------------------------------------------
// 2. Parameter declaration and calibration
//-------------------------------------------------------------------------------------------------------------------------
parameters beta, rho, epsilon, omega, phi, gamma;
beta=0.99;
gamma=3; //Frish elasticity
omega=17; //price stickyness
epsilon=8; //elasticity for each variety of consumption
phi=1; //coefficient associated to labor effort disutility
rho=0.95; //coefficient associated to productivity shock
//-----------------------------------------------------------------------------------------------------------------------
// 3. The model
//-----------------------------------------------------------------------------------------------------------------------
model;
a=rho*(a(-1))+u;
1/c=beta*(1/(c(+1)))*(r/(pai(+1))); //euler
omega*pai*(pai-1)=beta*omega*(c/(c(+1)))*(pai(+1))*(pai(+1)-1)+epsilon*exp(a)*n*(c/exp(a)*phi*n^gamma-(epsilon-1)/epsilon); //NK pc
//pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega-exp(a)*n*(epsilon-1)/(omega*c); //NK pc
(exp(a))*n=c+(omega/2)*((pai-1)^2);
end;
//--------------------------------------------------------------------------------------------------------------------------
// 4. Steady state
//---------------------------------------------------------------------------------------------------------------------------
initval;
pai=1;
r=1/beta;
c=0.9671684882;
n=0.9671684882;
a=0;
end;
//---------------------------------------------------------------------------------------------------------------------------
// 5. shocks
//---------------------------------------------------------------------------------------------------------------------------
shocks;
var u; stderr 0.008;
end;
//--------------------------------------------------------------------------------------------------------------------------
// 6. Ramsey problem
//--------------------------------------------------------------------------------------------------------------------------
planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma)));
write_latex_static_model;
ramsey_model(planner_discount=0.99);
options_.ramsey_policy=1;
stoch_simul(irf=0);