Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • giovanma/dynare
  • giorgiomas/dynare
  • Vermandel/dynare
  • Dynare/dynare
  • normann/dynare
  • MichelJuillard/dynare
  • wmutschl/dynare
  • FerhatMihoubi/dynare
  • sebastien/dynare
  • lnsongxf/dynare
  • rattoma/dynare
  • CIMERS/dynare
  • FredericKarame/dynare
  • SumuduK/dynare
  • MinjeJeon/dynare
  • camilomrch/dynare
  • DoraK/dynare
  • avtishin/dynare
  • selma/dynare
  • claudio_olguin/dynare
  • jeffjiang07/dynare
  • EthanSystem/dynare
  • stepan-a/dynare
  • wjgatt/dynare
  • JohannesPfeifer/dynare
  • gboehl/dynare
  • chskcau/dynare-doc-fixes
27 results
Select Git revision
Show changes
Commits on Source (12)
...@@ -932,7 +932,7 @@ over those passed to @ref{@@#includepath}. ...@@ -932,7 +932,7 @@ over those passed to @ref{@@#includepath}.
Allows Dynare to issue a warning and continue processing when Allows Dynare to issue a warning and continue processing when
@enumerate @enumerate
@item there are more endogenous variables than equations @item there are more endogenous variables than equations
@item an undeclared symbol is assigned in @code{initval} or @code{endval} @item an undeclared symbol is assigned in @code{initval}, @code{endval}, @code{histval}, or @code{shocks}
@item exogenous variables were declared but not used in the @code{model} block @item exogenous variables were declared but not used in the @code{model} block
@end enumerate @end enumerate
   
......
...@@ -3710,6 +3710,21 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode ...@@ -3710,6 +3710,21 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode
writeDynamicMFile(t_basename); writeDynamicMFile(t_basename);
} }
void
DynamicModel::updateAfterVariableChange(DynamicModel &dm)
{
variable_node_map.clear();
unary_op_node_map.clear();
binary_op_node_map.clear();
trinary_op_node_map.clear();
external_function_node_map.clear();
first_deriv_external_function_node_map.clear();
second_deriv_external_function_node_map.clear();
cloneDynamic(dm);
dm.replaceMyEquations(*this);
}
void void
DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const
{ {
......
...@@ -263,6 +263,9 @@ public: ...@@ -263,6 +263,9 @@ public:
/*! It assumes that the dynamic model given in argument has just been allocated */ /*! It assumes that the dynamic model given in argument has just been allocated */
void cloneDynamic(DynamicModel &dynamic_model) const; void cloneDynamic(DynamicModel &dynamic_model) const;
//! update equations after variable type change in model block
void updateAfterVariableChange(DynamicModel &dynamic_model);
//! Replaces model equations with derivatives of Lagrangian w.r.t. endogenous //! Replaces model equations with derivatives of Lagrangian w.r.t. endogenous
void computeRamseyPolicyFOCs(const StaticModel &static_model); void computeRamseyPolicyFOCs(const StaticModel &static_model);
//! Replaces the model equations in dynamic_model with those in this model //! Replaces the model equations in dynamic_model with those in this model
......
...@@ -121,7 +121,7 @@ class ParsingDriver; ...@@ -121,7 +121,7 @@ class ParsingDriver;
%token PERFECT_FORESIGHT_SETUP PERFECT_FORESIGHT_SOLVER NO_POSTERIOR_KERNEL_DENSITY FUNCTION %token PERFECT_FORESIGHT_SETUP PERFECT_FORESIGHT_SOLVER NO_POSTERIOR_KERNEL_DENSITY FUNCTION
%token PRINT PRIOR_MC PRIOR_TRUNC PRIOR_MODE PRIOR_MEAN POSTERIOR_MODE POSTERIOR_MEAN POSTERIOR_MEDIAN MLE_MODE PRUNING %token PRINT PRIOR_MC PRIOR_TRUNC PRIOR_MODE PRIOR_MEAN POSTERIOR_MODE POSTERIOR_MEAN POSTERIOR_MEDIAN MLE_MODE PRUNING
%token <string_val> QUOTED_STRING %token <string_val> QUOTED_STRING
%token QZ_CRITERIUM QZ_ZERO_THRESHOLD FULL DSGE_VAR DSGE_VARLAG DSGE_PRIOR_WEIGHT TRUNCATE %token QZ_CRITERIUM QZ_ZERO_THRESHOLD FULL DSGE_VAR DSGE_VARLAG DSGE_PRIOR_WEIGHT TRUNCATE PIPE_E PIPE_X PIPE_P
%token RELATIVE_IRF REPLIC SIMUL_REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE PARAMETER_UNCERTAINTY %token RELATIVE_IRF REPLIC SIMUL_REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE PARAMETER_UNCERTAINTY
%token SHOCKS SHOCK_DECOMPOSITION SHOCK_GROUPS USE_SHOCK_GROUPS SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED ENDOGENOUS_TERMINAL_PERIOD %token SHOCKS SHOCK_DECOMPOSITION SHOCK_GROUPS USE_SHOCK_GROUPS SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED ENDOGENOUS_TERMINAL_PERIOD
%token SMOOTHER SMOOTHER2HISTVAL SQUARE_ROOT_SOLVER STACK_SOLVE_ALGO STEADY_STATE_MODEL SOLVE_ALGO SOLVER_PERIODS ROBUST_LIN_SOLVE %token SMOOTHER SMOOTHER2HISTVAL SQUARE_ROOT_SOLVER STACK_SOLVE_ALGO STEADY_STATE_MODEL SOLVE_ALGO SOLVER_PERIODS ROBUST_LIN_SOLVE
...@@ -734,6 +734,12 @@ hand_side : '(' hand_side ')' ...@@ -734,6 +734,12 @@ hand_side : '(' hand_side ')'
{ $$ = $2;} { $$ = $2;}
| symbol | symbol
{ $$ = driver.add_model_variable($1); } { $$ = driver.add_model_variable($1); }
| symbol PIPE_E
{ $$ = driver.declare_or_change_type(eEndogenous, $1); }
| symbol PIPE_X
{ $$ = driver.declare_or_change_type(eExogenous, $1); }
| symbol PIPE_P
{ $$ = driver.declare_or_change_type(eParameter, $1); }
| non_negative_number | non_negative_number
{ $$ = driver.add_non_negative_constant($1); } { $$ = driver.add_non_negative_constant($1); }
| hand_side PLUS hand_side | hand_side PLUS hand_side
......
...@@ -852,6 +852,10 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 ...@@ -852,6 +852,10 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
} }
<DATES_STATEMENT>. { yylval->string_val->append(yytext); } <DATES_STATEMENT>. { yylval->string_val->append(yytext); }
<DYNARE_BLOCK>\|[eE] { return token::PIPE_E; }
<DYNARE_BLOCK>\|[xX] { return token::PIPE_X; }
<DYNARE_BLOCK>\|[pP] { return token::PIPE_P; }
<DYNARE_STATEMENT,DYNARE_BLOCK>\'[^\']+\' { <DYNARE_STATEMENT,DYNARE_BLOCK>\'[^\']+\' {
yylval->string_val = new string(yytext + 1); yylval->string_val = new string(yytext + 1);
yylval->string_val->resize(yylval->string_val->length() - 1); yylval->string_val->resize(yylval->string_val->length() - 1);
......
...@@ -44,14 +44,14 @@ void ...@@ -44,14 +44,14 @@ void
ParsingDriver::check_symbol_existence_in_model_block(const string &name) ParsingDriver::check_symbol_existence_in_model_block(const string &name)
{ {
if (!mod_file->symbol_table.exists(name)) if (!mod_file->symbol_table.exists(name))
model_error("Unknown symbol: " + name); model_error("Unknown symbol: " + name + ".\nTry using 'nostrict' option to have this declared as an exogenous variable by the preprocessor.", name);
} }
void void
ParsingDriver::check_symbol_existence(const string &name) ParsingDriver::check_symbol_existence(const string &name)
{ {
if (!mod_file->symbol_table.exists(name)) if (!mod_file->symbol_table.exists(name))
error("Unknown symbol: " + name); error("Unknown symbol: " + name + ".\nIf referenced from the 'initval', 'endval', 'histval', or 'shocks' block, you can pass the 'nostrict' option to dynare to have this line ignored.");
} }
void void
...@@ -139,10 +139,17 @@ ParsingDriver::create_error_string(const Dynare::parser::location_type &l, const ...@@ -139,10 +139,17 @@ ParsingDriver::create_error_string(const Dynare::parser::location_type &l, const
} }
void void
ParsingDriver::model_error(const string &m) ParsingDriver::create_error_string(const Dynare::parser::location_type &l, const string &m, const string &var)
{ {
create_error_string(location, m, model_errors); ostringstream stream;
model_error_encountered = true; create_error_string(l, m, stream);
model_errors.push_back(make_pair(var, stream.str()));
}
void
ParsingDriver::model_error(const string &m, const string &var)
{
create_error_string(location, m, var);
} }
void void
...@@ -360,7 +367,7 @@ ParsingDriver::add_model_variable(string *name) ...@@ -360,7 +367,7 @@ ParsingDriver::add_model_variable(string *name)
{ {
symb_id = mod_file->symbol_table.getID(*name); symb_id = mod_file->symbol_table.getID(*name);
if (undeclared_model_vars.find(*name) != undeclared_model_vars.end()) if (undeclared_model_vars.find(*name) != undeclared_model_vars.end())
model_error("Unknown symbol: " + *name); model_error("Unknown symbol: " + *name + ".\nTry using 'nostrict' option to have this declared as an exogenous variable by the preprocessor.", *name);
} }
catch (SymbolTable::UnknownSymbolNameException &e) catch (SymbolTable::UnknownSymbolNameException &e)
{ {
...@@ -374,6 +381,57 @@ ParsingDriver::add_model_variable(string *name) ...@@ -374,6 +381,57 @@ ParsingDriver::add_model_variable(string *name)
return add_model_variable(symb_id, 0); return add_model_variable(symb_id, 0);
} }
expr_t
ParsingDriver::declare_or_change_type(SymbolType new_type, string *name)
{
int symb_id;
try
{
symb_id = mod_file->symbol_table.getID(*name);
mod_file->symbol_table.changeType(symb_id, new_type);
// change in equations in ModelTree
DynamicModel *dm = new DynamicModel(mod_file->symbol_table,
mod_file->num_constants,
mod_file->external_functions_table);
mod_file->dynamic_model.updateAfterVariableChange(*dm);
delete dm;
// remove error messages
undeclared_model_vars.erase(*name);
for (vector<pair<string, string> >::iterator it = model_errors.begin();
it != model_errors.end();)
if (it->first == *name)
it = model_errors.erase(it);
else
it++;
}
catch (SymbolTable::UnknownSymbolNameException &e)
{
switch (new_type)
{
case eEndogenous:
declare_endogenous(new string(*name));
break;
case eExogenous:
declare_exogenous(new string(*name));
break;
case eExogenousDet:
declare_exogenous_det(new string(*name));
break;
case eParameter:
declare_parameter(new string(*name));
break;
default:
error("Type not yet supported");
}
symb_id = mod_file->symbol_table.getID(*name);
}
delete name;
return add_model_variable(symb_id, 0);
}
expr_t expr_t
ParsingDriver::add_model_variable(int symb_id, int lag) ParsingDriver::add_model_variable(int symb_id, int lag)
{ {
...@@ -536,6 +594,14 @@ ParsingDriver::initval_file(string *filename) ...@@ -536,6 +594,14 @@ ParsingDriver::initval_file(string *filename)
void void
ParsingDriver::hist_val(string *name, string *lag, expr_t rhs) ParsingDriver::hist_val(string *name, string *lag, expr_t rhs)
{ {
if (nostrict)
if (!mod_file->symbol_table.exists(*name))
{
warning("discarding '" + *name + "' as it was not recognized in the histavl block");
delete name;
return;
}
check_symbol_existence(*name); check_symbol_existence(*name);
int symb_id = mod_file->symbol_table.getID(*name); int symb_id = mod_file->symbol_table.getID(*name);
SymbolType type = mod_file->symbol_table.getType(symb_id); SymbolType type = mod_file->symbol_table.getType(symb_id);
...@@ -689,9 +755,22 @@ ParsingDriver::begin_model() ...@@ -689,9 +755,22 @@ ParsingDriver::begin_model()
void void
ParsingDriver::end_model() ParsingDriver::end_model()
{ {
if (model_error_encountered) if (model_errors.size() > 0)
{ {
cerr << model_errors.str(); bool exit_after_write = false;
bool exit_after_write_undeclared_vars = true;
for (vector<pair<string, string> >::const_iterator it = model_errors.begin();
it != model_errors.end(); it++)
{
if (it->first == "")
exit_after_write = true;
if (mod_file->symbol_table.getType(it->first) == eExogenous)
exit_after_write_undeclared_vars = false;
else
cerr << it->second;
}
if (exit_after_write || exit_after_write_undeclared_vars)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
reset_data_tree(); reset_data_tree();
...@@ -761,6 +840,14 @@ ParsingDriver::add_det_shock(string *var, bool conditional_forecast) ...@@ -761,6 +840,14 @@ ParsingDriver::add_det_shock(string *var, bool conditional_forecast)
void void
ParsingDriver::add_stderr_shock(string *var, expr_t value) ParsingDriver::add_stderr_shock(string *var, expr_t value)
{ {
if (nostrict)
if (!mod_file->symbol_table.exists(*var))
{
warning("discarding shocks block declaration of the standard error of '" + *var + "' as it was not declared");
delete var;
return;
}
check_symbol_existence(*var); check_symbol_existence(*var);
int symb_id = mod_file->symbol_table.getID(*var); int symb_id = mod_file->symbol_table.getID(*var);
...@@ -776,6 +863,14 @@ ParsingDriver::add_stderr_shock(string *var, expr_t value) ...@@ -776,6 +863,14 @@ ParsingDriver::add_stderr_shock(string *var, expr_t value)
void void
ParsingDriver::add_var_shock(string *var, expr_t value) ParsingDriver::add_var_shock(string *var, expr_t value)
{ {
if (nostrict)
if (!mod_file->symbol_table.exists(*var))
{
warning("discarding shocks block declaration of the variance of '" + *var + "' as it was not declared");
delete var;
return;
}
check_symbol_existence(*var); check_symbol_existence(*var);
int symb_id = mod_file->symbol_table.getID(*var); int symb_id = mod_file->symbol_table.getID(*var);
...@@ -791,6 +886,15 @@ ParsingDriver::add_var_shock(string *var, expr_t value) ...@@ -791,6 +886,15 @@ ParsingDriver::add_var_shock(string *var, expr_t value)
void void
ParsingDriver::add_covar_shock(string *var1, string *var2, expr_t value) ParsingDriver::add_covar_shock(string *var1, string *var2, expr_t value)
{ {
if (nostrict)
if (!mod_file->symbol_table.exists(*var1) || !mod_file->symbol_table.exists(*var2))
{
warning("discarding shocks block declaration of the covariance of '" + *var1 + "' and '" + *var2 + "' as at least one was not declared");
delete var1;
delete var2;
return;
}
check_symbol_existence(*var1); check_symbol_existence(*var1);
check_symbol_existence(*var2); check_symbol_existence(*var2);
int symb_id1 = mod_file->symbol_table.getID(*var1); int symb_id1 = mod_file->symbol_table.getID(*var1);
...@@ -814,6 +918,15 @@ ParsingDriver::add_covar_shock(string *var1, string *var2, expr_t value) ...@@ -814,6 +918,15 @@ ParsingDriver::add_covar_shock(string *var1, string *var2, expr_t value)
void void
ParsingDriver::add_correl_shock(string *var1, string *var2, expr_t value) ParsingDriver::add_correl_shock(string *var1, string *var2, expr_t value)
{ {
if (nostrict)
if (!mod_file->symbol_table.exists(*var1) || !mod_file->symbol_table.exists(*var2))
{
warning("discarding shocks block declaration of the correlation of '" + *var1 + "' and '" + *var2 + "' as at least one was not declared");
delete var1;
delete var2;
return;
}
check_symbol_existence(*var1); check_symbol_existence(*var1);
check_symbol_existence(*var2); check_symbol_existence(*var2);
int symb_id1 = mod_file->symbol_table.getID(*var1); int symb_id1 = mod_file->symbol_table.getID(*var1);
...@@ -2657,11 +2770,11 @@ ParsingDriver::add_model_var_or_external_function(string *function_name, bool in ...@@ -2657,11 +2770,11 @@ ParsingDriver::add_model_var_or_external_function(string *function_name, bool in
else else
{ // e.g. model_var(lag) => ADD MODEL VARIABLE WITH LEAD (NumConstNode)/LAG (UnaryOpNode) { // e.g. model_var(lag) => ADD MODEL VARIABLE WITH LEAD (NumConstNode)/LAG (UnaryOpNode)
if (undeclared_model_vars.find(*function_name) != undeclared_model_vars.end()) if (undeclared_model_vars.find(*function_name) != undeclared_model_vars.end())
model_error("Unknown symbol: " + *function_name); model_error("Unknown symbol: " + *function_name + ".\nTry using 'nostrict' option to have this declared as an exogenous variable by the preprocessor.", *function_name);
pair<bool, double> rv = is_there_one_integer_argument(); pair<bool, double> rv = is_there_one_integer_argument();
if (!rv.first) if (!rv.first)
model_error(string("Symbol ") + *function_name + string(" is being treated as if it were a function (i.e., takes an argument that is not an integer).")); model_error(string("Symbol ") + *function_name + string(" is being treated as if it were a function (i.e., takes an argument that is not an integer)."), "");
nid = add_model_variable(mod_file->symbol_table.getID(*function_name), (int) rv.second); nid = add_model_variable(mod_file->symbol_table.getID(*function_name), (int) rv.second);
stack_external_function_args.pop(); stack_external_function_args.pop();
...@@ -2692,7 +2805,7 @@ ParsingDriver::add_model_var_or_external_function(string *function_name, bool in ...@@ -2692,7 +2805,7 @@ ParsingDriver::add_model_var_or_external_function(string *function_name, bool in
// Continue processing, noting that it was not declared // Continue processing, noting that it was not declared
// Paring will end at the end of the model block // Paring will end at the end of the model block
undeclared_model_vars.insert(*function_name); undeclared_model_vars.insert(*function_name);
model_error("Unknown symbol: " + *function_name); model_error("Unknown symbol: " + *function_name + ".\nTry using 'nostrict' option to have this declared as an exogenous variable by the preprocessor.", *function_name);
pair<bool, double> rv = is_there_one_integer_argument(); pair<bool, double> rv = is_there_one_integer_argument();
if (rv.first) if (rv.first)
{ {
......
...@@ -234,12 +234,10 @@ private: ...@@ -234,12 +234,10 @@ private:
bool nostrict; bool nostrict;
bool model_error_encountered; vector<pair<string, string> > model_errors;
ostringstream model_errors;
public: public:
ParsingDriver(WarningConsolidation &warnings_arg, bool nostrict_arg) : warnings(warnings_arg), nostrict(nostrict_arg), model_error_encountered(false) { }; ParsingDriver(WarningConsolidation &warnings_arg, bool nostrict_arg) : warnings(warnings_arg), nostrict(nostrict_arg) { };
//! Starts parsing, and constructs the MOD file representation //! Starts parsing, and constructs the MOD file representation
/*! The returned pointer should be deleted after use */ /*! The returned pointer should be deleted after use */
...@@ -268,9 +266,10 @@ public: ...@@ -268,9 +266,10 @@ public:
void warning(const string &m); void warning(const string &m);
//! Error handler with explicit location (used in model block, accumulating error messages to be printed later) //! Error handler with explicit location (used in model block, accumulating error messages to be printed later)
void model_error(const string &m); void model_error(const string &m, const string &var);
//! Code shared between model_error() and error() //! Code shared between model_error() and error()
void create_error_string(const Dynare::parser::location_type &l, const string &m, const string &var);
void create_error_string(const Dynare::parser::location_type &l, const string &m, ostream &stream); void create_error_string(const Dynare::parser::location_type &l, const string &m, ostream &stream);
//! Check if a given symbol exists in the parsing context, and is not a mod file local variable //! Check if a given symbol exists in the parsing context, and is not a mod file local variable
...@@ -330,6 +329,9 @@ public: ...@@ -330,6 +329,9 @@ public:
expr_t add_inf_constant(); expr_t add_inf_constant();
//! Adds a model variable to ModelTree and VariableTable //! Adds a model variable to ModelTree and VariableTable
expr_t add_model_variable(string *name); expr_t add_model_variable(string *name);
//! Declares a variable of type new_type OR changes a variable in the equations to type new_type
//! and removes any error messages that may have been issued in model_errors
expr_t declare_or_change_type(SymbolType new_type, string *name);
//! Adds an Expression's variable //! Adds an Expression's variable
expr_t add_expression_variable(string *name); expr_t add_expression_variable(string *name);
//! Adds a "periods" statement //! Adds a "periods" statement
......
// Declaration of some endogenous variables.
var c;
/*
** REMARKS
**
** Some declarations for the endogenous variables are missing. They are declared below in
** the model block.
**
*/
// Declaration of some of the parameters.
parameters beta, rho, theta, psi, tau;
rho = 0.95;
tau = 0.025;
beta = 0.99;
psi = 0;
theta = 2.95;
phi = 0.1;
/*
** REMARKS
**
** Same remark, some parameters are defined in the below in the model block (alpha and delta). These
** variables must be calibrated after the model block (ie after the calibration).
**
** We do not declare the exogenous variables in the preamble. The innovations are decalred in the model
** block below.
**
*/
model;
c*theta*h|e^(1+psi)=(1-alpha)*y;
k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))
*(exp(b(+1))*alpha|p*y(+1)+(1-delta)*k));
y|e = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
k|e = exp(b)*(y-c)+(1-delta|p)*k(-1);
a|e = rho*a(-1) + e|x;
b|e = rho*b(-1) + u|x;
end;
/*
** REMARKS
**
** On the fly declaration works as follows:
**
** - A symbol followed by |e implicitely declares an endogenous variable.
** - A symbol followed by |x implicitely declares an exogenous variable.
** - A symbol followed by |p implicitely declares a parameter.
**
** A parameter declared on the fly has to be calibrated after its declaration, ie after the model
** block. If the user tries to give a value to a parameter before its declaration, then Dynare
** interpret the calibration as a matlab statement, because Dynare doesn't know that the symbol is
** a parameter.
**
** By default an undeclared symbol is interpreted as an exogenous variable. Consequently, if the user
** removes an equation where an endogenous variable is declared, the status of the variable changes.
** For instance, if one comments the last equation, the law of motion of b, symbol b becomes an
** exogenous variable (whose value is zero by default). A more interesting use case, is to remove
** the first equation, the arbitrage condition between leisure and consumption. Labour supply is
** then supposed to be exogenous.
*/
alpha = 0.36;
delta = 0.025;
initval;
y = 1.08068253095672;
c = 0.80359242014163;
h = 0.29175631001732;
k = 11.08360443260358;
a = 0;
b = 0;
e = 0;
u = 0;
end;
shocks;
var e; stderr 0.009;
var u; stderr 0.009;
var e, u = phi*0.009*0.009;
end;
stoch_simul(order=1);