diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index 03a7b1a1caa3071689b89601fa62c0db35f80936..d12c8460482d2d433a86109f570e5f39eb557604 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -182,6 +182,7 @@ options_.ramsey_policy = 0; options_.timeless = 0; % estimation +options_.initial_period = dynDate(1); options_.Harvey_scale_factor = 10; options_.MaxNumberOfBytes = 1e6; options_.MaximumNumberOfMegaBytes = 111; diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 78831ce14371762d823b70d7e23c2224442b3759..39993b13418cceb253dd21c9b8a2b69e888862ee 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -1431,3 +1431,14 @@ SvarStatement::writeOutput(ostream &output, const string &basename) const else output << "'ALL';" << endl; } + +SetTimeStatement::SetTimeStatement(const OptionsList &options_list_arg) : + options_list(options_list_arg) +{ +} + +void +SetTimeStatement::writeOutput(ostream &output, const string &basename) const +{ + options_list.writeOutput(output); +} diff --git a/preprocessor/ComputingTasks.hh b/preprocessor/ComputingTasks.hh index 2c7a0e8692cf8a53ca2f8a3bd9af6d40afb11498..75851a611e7eac1d9304b7202c94d449422b8887 100644 --- a/preprocessor/ComputingTasks.hh +++ b/preprocessor/ComputingTasks.hh @@ -556,4 +556,14 @@ public: virtual void writeOutput(ostream &output, const string &basename) const; }; +class SetTimeStatement : public Statement +{ +private: + const OptionsList options_list; +public: + SetTimeStatement(const OptionsList &options_list_arg); + virtual void writeOutput(ostream &output, const string &basename) const; +}; + + #endif diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 0503ea970ac53ad0b335892384b84f6f2c28471b..a533cdec0a8a5be5cc67158a5f5de8e5d58cf46d 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -96,13 +96,14 @@ class ParsingDriver; %token CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR COVAR CUTOFF %token DATAFILE DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION %token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT -%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS +%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS SET_TIME %token <string_val> FLOAT_NUMBER %token FORECAST K_ORDER_SOLVER INSTRUMENTS %token GAMMA_PDF GRAPH CONDITIONAL_VARIANCE_DECOMPOSITION NOCHECK %token HISTVAL HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS HP_FILTER HP_NGRID %token IDENTIFICATION INF_CONSTANT INITVAL INITVAL_FILE %token <string_val> INT_NUMBER +%token <string_val> DATE_NUMBER %token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS %token KALMAN_ALGO KALMAN_TOL %token LABELS LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR @@ -173,7 +174,7 @@ class ParsingDriver; %type <node_val> expression expression_or_empty %type <node_val> equation hand_side -%type <string_val> non_negative_number signed_number signed_integer +%type <string_val> non_negative_number signed_number signed_integer date_number %type <string_val> filename symbol %type <string_val> vec_value_1 vec_value %type <string_val> range prior @@ -213,6 +214,7 @@ statement : parameters | estimated_params | estimated_params_bounds | estimated_params_init + | set_time | varobs | observation_trends | unit_root_vars @@ -963,6 +965,10 @@ non_negative_number : INT_NUMBER | FLOAT_NUMBER ; +date_number : DATE_NUMBER + | INT_NUMBER + ; + signed_number : PLUS non_negative_number { $$ = $2; } | MINUS non_negative_number @@ -1153,6 +1159,10 @@ prior : BETA_PDF { $$ = new string("6"); } ; +set_time : SET_TIME '(' date_number ')' ';' + { driver.set_time($3); } + ; + estimation : ESTIMATION ';' { driver.run_estimation(); } | ESTIMATION '(' estimation_options_list ')' ';' diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index e9230dd4ee0aa7760052cacba479d84add899301..7f46f7caa08d30e0cefcd33045368a0c8a9defda 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -108,6 +108,7 @@ string eofbuff; <INITIAL>periods {BEGIN DYNARE_STATEMENT; return token::PERIODS;} <INITIAL>model_info {BEGIN DYNARE_STATEMENT; return token::MODEL_INFO;} <INITIAL>estimation {BEGIN DYNARE_STATEMENT; return token::ESTIMATION;} +<INITIAL>set_time {BEGIN DYNARE_STATEMENT; return token::SET_TIME;} <INITIAL>varobs {BEGIN DYNARE_STATEMENT; return token::VAROBS;} <INITIAL>unit_root_vars {BEGIN DYNARE_STATEMENT; return token::UNIT_ROOT_VARS;} <INITIAL>rplot {BEGIN DYNARE_STATEMENT; return token::RPLOT;} @@ -591,6 +592,11 @@ string eofbuff; return token::INT_NUMBER; } +<DYNARE_STATEMENT,DYNARE_BLOCK>([1-2][0-9]{3}[Mm](([1-9])|(1[0-2])))|([1-2][0-9]{3}[Qq][1-4])|([1-2][0-9]{3}[Ww](([1-9]{1})|([1-5][0-9]))) { + yylval->string_val = new string(yytext); + return token::DATE_NUMBER; +} + <DYNARE_STATEMENT,DYNARE_BLOCK>\'[^\']+\' { yylval->string_val = new string(yytext + 1); yylval->string_val->resize(yylval->string_val->length() - 1); diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index 73fc785fcb6fcc958d0e5c36d0f2e6826bec6570..bc734f8ff87a6dae25207045a4ac6860a3bb2c1e 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -1056,6 +1056,23 @@ ParsingDriver::option_str(const string &name_option, const string &opt) options_list.string_options[name_option] = opt; } +void +ParsingDriver::option_date(const string &name_option, string *opt) +{ + option_date(name_option, *opt); + delete opt; +} + +void +ParsingDriver::option_date(const string &name_option, const string &opt) +{ + if (options_list.date_options.find(name_option) + != options_list.date_options.end()) + error("option " + name_option + " declared twice"); + + options_list.date_options[name_option] = opt; +} + void ParsingDriver::option_symbol_list(const string &name_option) { @@ -1184,6 +1201,17 @@ ParsingDriver::set_unit_root_vars() symbol_list.clear(); } +void +ParsingDriver::set_time(string *arg) +{ + string arg1 = *arg; + for (size_t i=0; i<arg1.length(); i++) + arg1[i]= toupper(arg1[i]); + option_date("initial_period", arg1); + mod_file->addStatement(new SetTimeStatement(options_list)); + options_list.clear(); +} + void ParsingDriver::run_estimation() { diff --git a/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh index dedf5e6db5007fae276deed454ece0074e443800..d3d7ac01c4012956e8d40e296768bc1d57a08e3b 100644 --- a/preprocessor/ParsingDriver.hh +++ b/preprocessor/ParsingDriver.hh @@ -319,6 +319,10 @@ public: void option_str(const string &name_option, string *opt); //! Sets an option to a string value void option_str(const string &name_option, const string &opt); + //! Sets an option to a date value + void option_date(const string &name_option, string *opt); + //! Sets an option to a date value + void option_date(const string &name_option, const string &opt); //! Sets an option to a list of symbols (used in conjunction with add_in_symbol_list()) void option_symbol_list(const string &name_option); //! Sets an option to a vector of integers @@ -351,6 +355,8 @@ public: void external_function_option(const string &name_option, const string &opt); //! Add a line in an estimated params block void add_estimated_params_element(); + //! Sets the frequency of the data + void set_time(string *arg); //! Runs estimation process void run_estimation(); //! Runs dynare_sensitivy() diff --git a/preprocessor/Statement.cc b/preprocessor/Statement.cc index ea34a236695beddc3a85dc3de7c1c0edc0a32a4d..5d61270f2bf653f85b9fb1a26703f8794781b92e 100644 --- a/preprocessor/Statement.cc +++ b/preprocessor/Statement.cc @@ -88,6 +88,10 @@ OptionsList::writeOutput(ostream &output) const it != string_options.end(); it++) output << "options_." << it->first << " = '" << it->second << "';" << endl; + for (date_options_t::const_iterator it = date_options.begin(); + it != date_options.end(); it++) + output << "options_." << it->first << " = dynDate('" << it->second << "');" << endl; + for (symbol_list_options_t::const_iterator it = symbol_list_options.begin(); it != symbol_list_options.end(); it++) it->second.writeOutput("options_." + it->first, output); @@ -127,6 +131,10 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const it != string_options.end(); it++) output << option_group << "." << it->first << " = '" << it->second << "';" << endl; + for (date_options_t::const_iterator it = date_options.begin(); + it != date_options.end(); it++) + output << option_group << "." << it->first << " = dynDate('" << it->second << "');" << endl; + for (symbol_list_options_t::const_iterator it = symbol_list_options.begin(); it != symbol_list_options.end(); it++) it->second.writeOutput(option_group + "." + it->first, output); @@ -154,6 +162,7 @@ OptionsList::clear() num_options.clear(); paired_num_options.clear(); string_options.clear(); + date_options.clear(); symbol_list_options.clear(); vector_int_options.clear(); } diff --git a/preprocessor/Statement.hh b/preprocessor/Statement.hh index 1d27815ebfff4b78a52fb0d4a0448910aad04c1b..3b9aebd84fc48c2e96c114656dec9c56145b1ce7 100644 --- a/preprocessor/Statement.hh +++ b/preprocessor/Statement.hh @@ -118,11 +118,13 @@ public: typedef map<string, string> num_options_t; typedef map<string, pair<string, string> > paired_num_options_t; typedef map<string, string> string_options_t; + typedef map<string, string> date_options_t; typedef map<string, SymbolList> symbol_list_options_t; typedef map<string, vector<int> > vec_int_options_t; num_options_t num_options; paired_num_options_t paired_num_options; string_options_t string_options; + date_options_t date_options; symbol_list_options_t symbol_list_options; vec_int_options_t vector_int_options; void writeOutput(ostream &output) const;