Commit 94f1f988 authored by MichelJuillard's avatar MichelJuillard

adding groups of shocks for shock_decomposition

consistency checks, documentation and test case
are still missing
parent aa12dc6d
......@@ -120,7 +120,7 @@ class ParsingDriver;
%token <string_val> QUOTED_STRING
%token QZ_CRITERIUM QZ_ZERO_THRESHOLD FULL DSGE_VAR DSGE_VARLAG DSGE_PRIOR_WEIGHT TRUNCATE
%token RELATIVE_IRF REPLIC SIMUL_REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE PARAMETER_UNCERTAINTY
%token SHOCKS SHOCK_DECOMPOSITION 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
%token STDERR STEADY STOCH_SIMUL SURPRISE SYLVESTER SYLVESTER_FIXED_POINT_TOL REGIMES REGIME
%token TEX RAMSEY_MODEL RAMSEY_POLICY RAMSEY_CONSTRAINTS PLANNER_DISCOUNT DISCRETIONARY_POLICY DISCRETIONARY_TOL
......@@ -128,7 +128,7 @@ class ParsingDriver;
%token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED
%token VALUES VAR VAREXO VAREXO_DET VAROBS PREDETERMINED_VARIABLES
%token WRITE_LATEX_DYNAMIC_MODEL WRITE_LATEX_STATIC_MODEL WRITE_LATEX_ORIGINAL_MODEL
%token XLS_SHEET XLS_RANGE LMMCP OCCBIN BANDPASS_FILTER
%token XLS_SHEET XLS_RANGE LMMCP OCCBIN BANDPASS_FILTER COLORMAP
%left COMMA
%left EQUAL_EQUAL EXCLAMATION_EQUAL
%left LESS GREATER LESS_EQUAL GREATER_EQUAL
......@@ -285,6 +285,7 @@ statement : parameters
| perfect_foresight_solver
| prior_function
| posterior_function
| shock_groups
;
dsample : DSAMPLE INT_NUMBER ';'
......@@ -2382,6 +2383,8 @@ shock_decomposition_options_list : shock_decomposition_option COMMA shock_decomp
shock_decomposition_option : o_parameter_set
| o_datafile
| o_use_shock_groups
| o_colormap
;
homotopy_setup: HOMOTOPY_SETUP ';' homotopy_list END ';'
......@@ -2583,6 +2586,23 @@ smoother2histval_option : o_infile
| o_outvars
;
shock_groups : SHOCK_GROUPS ';' shock_group_list END ';'{driver.end_shock_groups(new string("default"));}
| SHOCK_GROUPS '(' NAME EQUAL symbol ')' ';' shock_group_list END ';'
{driver.end_shock_groups($5);}
;
shock_group_list : shock_group_list shock_group_element
| shock_group_element
;
shock_group_element : symbol EQUAL shock_name_list ';' {driver.add_shock_group($1);}
;
shock_name_list : shock_name_list COMMA symbol {driver.add_shock_group_element($3);}
| shock_name_list symbol {driver.add_shock_group_element($2);}
| symbol {driver.add_shock_group_element($1);}
;
o_dr_algo : DR_ALGO EQUAL INT_NUMBER {
if (*$3 == string("0"))
driver.warning("dr_algo option is now deprecated, and may be removed in a future version of Dynare");
......@@ -3094,6 +3114,10 @@ o_lmmcp : LMMCP {driver.option_num("lmmcp", "1"); };
o_occbin : OCCBIN {driver.option_num("occbin", "1"); };
o_function : FUNCTION EQUAL filename { driver.option_str("function", $3); };
o_sampling_draws : SAMPLING_DRAWS EQUAL INT_NUMBER { driver.option_num("sampling_draws",$3); };
o_use_shock_groups : USE_SHOCK_GROUPS { driver.option_str("use_shock_groups","default"); }
| USE_SHOCK_GROUPS EQUAL symbol { driver.option_str("use_shock_groups", $3); }
;
o_colormap : COLORMAP EQUAL symbol { driver.option_str("colormap",$3); };
range : symbol ':' symbol
{
......
......@@ -187,6 +187,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
<INITIAL>endval {BEGIN DYNARE_BLOCK; return token::ENDVAL;}
<INITIAL>histval {BEGIN DYNARE_BLOCK; return token::HISTVAL;}
<INITIAL>shocks {BEGIN DYNARE_BLOCK; return token::SHOCKS;}
<INITIAL>shock_groups {BEGIN DYNARE_BLOCK; return token::SHOCK_GROUPS;}
<INITIAL>mshocks {BEGIN DYNARE_BLOCK; return token::MSHOCKS;}
<INITIAL>estimated_params {BEGIN DYNARE_BLOCK; return token::ESTIMATED_PARAMS;}
/* priors is an alias for estimated_params */
......@@ -793,6 +794,8 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
<DYNARE_STATEMENT>max_dim_cova_group {return token::MAX_DIM_COVA_GROUP;}
<DYNARE_STATEMENT>gsa_sample_file {return token::GSA_SAMPLE_FILE;}
<DYNARE_STATEMENT>use_shock_groups {return token::USE_SHOCK_GROUPS;}
<DYNARE_STATEMENT,DYNARE_BLOCK>[A-Za-z_][A-Za-z0-9_]* {
yylval->string_val = new string(yytext);
return token::NAME;
......
......@@ -2872,3 +2872,36 @@ ParsingDriver::add_ramsey_constraint(const string *name, BinaryOpcode op_code, c
delete name;
}
void
ParsingDriver::add_shock_group_element(string *name)
{
check_symbol_existence(*name);
int symb_id = mod_file->symbol_table.getID(*name);
SymbolType type = mod_file->symbol_table.getType(symb_id);
if (type != eExogenous)
error("shock_groups: " + *name + " should be an exogenous variable");
shock_group.push_back(*name);
delete name;
}
void
ParsingDriver::add_shock_group(string *name)
{
ShockGroupsStatement::Group G;
G.name = *name;
G.list = shock_group;
shock_groups.push_back(G);
shock_group.clear();
}
void
ParsingDriver::end_shock_groups(const string *name)
{
mod_file->addStatement(new ShockGroupsStatement(shock_groups, *name));
shock_groups.clear();
}
......@@ -205,6 +205,10 @@ private:
//! Temporary storage for subsample statement: map<pair<var_name1, var_name2>>, subsample_declaration_map >
typedef map<pair<string, string >, SubsamplesStatement::subsample_declaration_map_t > subsample_declarations_t;
subsample_declarations_t subsample_declarations;
//! Temporary storage for shock_groups
vector<string> shock_group;
vector<ShockGroupsStatement::Group> shock_groups;
//! reset the values for temporary storage
void reset_current_external_function_options();
//! Adds a model lagged variable to ModelTree and VariableTable
......@@ -698,7 +702,13 @@ public:
void add_irf_calibration_item(string *endo, string *periods, string *exo, vector<string *> *range);
//! End a moment_calibration statement
void end_irf_calibration();
//! Add a shock to a group
void add_shock_group_element(string *name);
//! Add a set of shock groups
void add_shock_group(string *name);
//! End shock groups declaration
void end_shock_groups(const string *name);
void smoother2histval();
void histval_file(string *filename);
void perfect_foresight_setup();
......
......@@ -459,3 +459,22 @@ IrfCalibration::writeOutput(ostream &output, const string &basename, bool minima
}
output << "};" << endl;
}
ShockGroupsStatement::ShockGroupsStatement(const group_t &shock_groups_arg, const string &name_arg)
: shock_groups(shock_groups_arg), name(name_arg)
{
}
void
ShockGroupsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{
for (vector<Group>::const_iterator it = shock_groups.begin(); it != shock_groups.end(); it++)
{
output << "M_.shock_groups." << name
<< "." << it->name << " = {";
for ( vector<string>::const_iterator it1 = it->list.begin(); it1 != it->list.end(); it1++)
output << " '" << *it1 << "'";
output << "};" << endl;
}
}
......@@ -141,4 +141,22 @@ public:
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
};
class ShockGroupsStatement : public Statement
{
public:
struct Group
{
string name;
vector<string> list;
};
typedef vector<Group> group_t;
private:
group_t shock_groups;
vector<string> group_names;
string name;
public:
ShockGroupsStatement(const group_t &shock_groups_arg, const string &name_arg);
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
};
#endif
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