diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 36049ab4..dcd000d4 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1359,7 +1359,9 @@ MarkovSwitchingStatement::MarkovSwitchingStatement(const OptionsList &options_li void MarkovSwitchingStatement::writeOutput(ostream &output, const string &basename) const { - OptionsList::num_options_t::const_iterator itChain, itRegime, itNOR, itDuration; + bool isDurationAVec = true; + string infStr("Inf"); + OptionsList::num_options_t::const_iterator itChain, itNOR, itDuration; itChain = options_list.num_options.find("ms.chain"); if (itChain == options_list.num_options.end()) @@ -1374,16 +1376,20 @@ MarkovSwitchingStatement::writeOutput(ostream &output, const string &basename) c cerr << "MarkovSwitchingStatement::writeOutput() Should not arrive here (2). Please report this to the Dynare Team." << endl; exit(EXIT_FAILURE); } + else if (atof(itDuration->second.c_str()) || infStr.compare(itDuration->second) == 0) + isDurationAVec = false; + output << "options_.ms.duration = " << itDuration->second << ";" << endl; - itRegime = options_list.num_options.find("ms.regime"); itNOR = options_list.num_options.find("ms.number_of_regimes"); - if (itRegime != options_list.num_options.end() - && itNOR == options_list.num_options.end()) - output << "options_.ms.ms_chain(" << itChain->second << ").regime(" << itRegime->second << ").duration = " << itDuration->second << ";" << endl; - else if (itRegime == options_list.num_options.end() - && itNOR != options_list.num_options.end()) + if (itNOR != options_list.num_options.end()) for (int i = 0; i < atoi(itNOR->second.c_str()); i++) - output << "options_.ms.ms_chain(" << itChain->second << ").regime(" << i+1 << ").duration = " << itDuration->second << ";" << endl; + { + output << "options_.ms.ms_chain(" << itChain->second << ").regime(" + << i+1 << ").duration = options_.ms.duration"; + if (isDurationAVec) + output << "(" << i+1 << ")"; + output << ";" << endl; + } else { cerr << "MarkovSwitchingStatement::writeOutput() Should not arrive here (3). Please report this to the Dynare Team." << endl; diff --git a/DynareBison.yy b/DynareBison.yy index 1956931f..a6bb978c 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -156,7 +156,7 @@ class ParsingDriver; %token SBVAR TREND_VAR DEFLATOR GROWTH_FACTOR MS_IRF MS_VARIANCE_DECOMPOSITION %token MS_ESTIMATION MS_SIMULATION MS_COMPUTE_MDD MS_COMPUTE_PROBABILITIES MS_FORECAST %token SVAR_IDENTIFICATION EQUATION EXCLUSION LAG UPPER_CHOLESKY LOWER_CHOLESKY MONTHLY QUARTERLY -%token MARKOV_SWITCHING CHAIN REGIME DURATION NUMBER_OF_REGIMES +%token MARKOV_SWITCHING CHAIN DURATION NUMBER_OF_REGIMES %token SVAR COEFF COEFFICIENTS VARIANCES CONSTANTS EQUATIONS %token EXTERNAL_FUNCTION EXT_FUNC_NAME EXT_FUNC_NARGS FIRST_DERIV_PROVIDED SECOND_DERIV_PROVIDED %token SELECTED_VARIABLES_ONLY COVA_COMPUTE SIMULATION_FILE_TAG FILE_TAG @@ -740,7 +740,6 @@ ms_options_list : ms_options_list COMMA ms_options ; ms_options : o_chain - | o_regime | o_duration | o_number_of_regimes ; @@ -2220,11 +2219,10 @@ o_cnum : CNUM EQUAL INT_NUMBER {driver.option_num("ms.cnum",$3); }; o_k_order_solver : K_ORDER_SOLVER {driver.option_num("k_order_solver","1"); }; o_pruning : PRUNING { driver.option_num("pruning", "1"); }; o_chain : CHAIN EQUAL INT_NUMBER { driver.option_num("ms.chain",$3); }; -o_regime : REGIME EQUAL INT_NUMBER { driver.option_num("ms.regime",$3); }; o_duration : DURATION EQUAL non_negative_number { driver.option_num("ms.duration",$3); } - | DURATION EQUAL INF_CONSTANT - { driver.option_num("ms.duration","Inf"); } + | DURATION EQUAL vec_value_w_inf + { driver.option_num("ms.duration",$3); } ; o_number_of_regimes : NUMBER_OF_REGIMES EQUAL INT_NUMBER { driver.option_num("ms.number_of_regimes",$3); }; o_coefficients : COEFFICIENTS { driver.option_str("ms.coefficients","svar_coefficients"); }; diff --git a/DynareFlex.ll b/DynareFlex.ll index 293f9adc..824476d9 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -504,7 +504,6 @@ string eofbuff; upper_cholesky {return token::UPPER_CHOLESKY;} lower_cholesky {return token::LOWER_CHOLESKY;} chain {return token::CHAIN;} -regime {return token::REGIME;} number_of_regimes {return token::NUMBER_OF_REGIMES;} duration {return token::DURATION;} coefficients {return token::COEFFICIENTS;} diff --git a/ParsingDriver.cc b/ParsingDriver.cc index a2d73eb7..178caa5f 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -1738,7 +1738,7 @@ ParsingDriver::svar() void ParsingDriver::markov_switching() { - OptionsList::num_options_t::const_iterator it0, it1; + OptionsList::num_options_t::const_iterator it0; it0 = options_list.num_options.find("ms.chain"); if (it0 == options_list.num_options.end()) @@ -1746,31 +1746,15 @@ ParsingDriver::markov_switching() else if (atoi(it0->second.c_str()) <= 0) error("The value passed to the chain option must be greater than zero."); - it0 = options_list.num_options.find("ms.regime"); - it1 = options_list.num_options.find("ms.number_of_regimes"); - if ((it0 == options_list.num_options.end()) - && (it1 == options_list.num_options.end())) - error("Either a regime option or a number_of_regimes option must be passed to the markov_switching statement."); + it0 = options_list.num_options.find("ms.number_of_regimes"); + if (it0 == options_list.num_options.end()) + error("A number_of_regimes option must be passed to the markov_switching statement."); + else if (atoi(it0->second.c_str()) <= 0) + error("The value passed to the number_of_regimes option must be greater than zero."); - if ((it0 != options_list.num_options.end()) - && (it1 != options_list.num_options.end())) - error("You cannot pass both a regime option and a number_of_regimes option to the markov_switching statement."); - - if (it0 != options_list.num_options.end()) - if (atoi(it0->second.c_str()) <= 0) - error("The value passed to the regime option must be greater than zero."); - - if (it1 != options_list.num_options.end()) - if (atoi(it1->second.c_str()) <= 0) - error("The value passed to the number_of_regimes option must be greater than zero."); - - string infStr("Inf"); it0 = options_list.num_options.find("ms.duration"); if (it0 == options_list.num_options.end()) error("A duration option must be passed to the markov_switching statement."); - else if (infStr.compare(it0->second) != 0) - if (atof(it0->second.c_str()) <= 0.0) - error("The value passed to the duration option must be greater than zero."); mod_file->addStatement(new MarkovSwitchingStatement(options_list)); options_list.clear();