diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index 32110a3b66229bcffcd1fb7163f30f3244201b41..e6cd7e91a536d819e40432bffaf3fdbc0018647b 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -100,6 +100,7 @@ DynamicModel::DynamicModel(const DynamicModel &m) : ModelTree {m}, trend_component_model_table {m.trend_component_model_table}, var_model_table {m.var_model_table}, + balanced_growth_test_tol {m.balanced_growth_test_tol}, static_only_equations_lineno {m.static_only_equations_lineno}, static_only_equations_equation_tags {m.static_only_equations_equation_tags}, deriv_id_table {m.deriv_id_table}, @@ -160,6 +161,7 @@ DynamicModel::operator=(const DynamicModel &m) assert(&trend_component_model_table == &m.trend_component_model_table); assert(&var_model_table == &m.var_model_table); + balanced_growth_test_tol = m.balanced_growth_test_tol; static_only_equations_lineno = m.static_only_equations_lineno; static_only_equations_equation_tags = m.static_only_equations_equation_tags; @@ -5800,13 +5802,14 @@ DynamicModel::testTrendDerivativesEqualToZero(const eval_context_t &eval_context if (symbol_table.getType(endogit->first.first) == SymbolType::endogenous) { double nearZero = testeq->getDerivative(endogit->second)->eval(eval_context); // eval d F / d Trend d Endog - if (fabs(nearZero) > zero_band) + if (fabs(nearZero) > balanced_growth_test_tol) { - cerr << "WARNING: trends not compatible with balanced growth path; the second-order cross partial of equation " << eq + 1 << " (line " + cerr << "ERROR: trends not compatible with balanced growth path; the second-order cross partial of equation " << eq + 1 << " (line " << equations_lineno[eq] << ") w.r.t. trend variable " << symbol_table.getName(it->first.first) << " and endogenous variable " - << symbol_table.getName(endogit->first.first) << " is not null. " << endl; - // Changed to warning. See discussion in #1389 + << symbol_table.getName(endogit->first.first) << " is not null (abs. value = " + << fabs(nearZero) << "). If you are confident that your trends are correctly specified, you can raise the value of option 'balanced_growth_test_tol' in the 'model' block." << endl; + exit(EXIT_FAILURE); } } } diff --git a/src/DynamicModel.hh b/src/DynamicModel.hh index 67ca4019efa0c140e6ada23539da1856b6a902bb..865d22d7198bd3a8b5dcf31152e92b716af6c338 100644 --- a/src/DynamicModel.hh +++ b/src/DynamicModel.hh @@ -35,7 +35,15 @@ public: TrendComponentModelTable &trend_component_model_table; //! A reference to the VAR model table VarModelTable &var_model_table; + /* Used in the balanced growth test, for determining whether the + cross-derivative of a given equation, w.r.t. an endogenous and a trend + variable is zero. Controlled by option “balanced_growth_test_tol” of the + “model” block. The default should not be too small (see dynare#1389). */ + double balanced_growth_test_tol{1e-6}; private: + /* Used in the balanced growth test, for skipping equations where the test + cannot be performed (i.e. when LHS=RHS at the initial values). Should not + be too large, otherwise the test becomes less powerful. */ constexpr static double zero_band{1e-8}; //! Stores equations declared as [static] diff --git a/src/DynareBison.yy b/src/DynareBison.yy index ca6ce5085679b04664b754a56e1cc156c7850ae9..f1a24547e7ff593d96867fc80ff9ac462b541503 100644 --- a/src/DynareBison.yy +++ b/src/DynareBison.yy @@ -73,7 +73,7 @@ class ParsingDriver; } %token AIM_SOLVER ANALYTIC_DERIVATION ANALYTIC_DERIVATION_MODE AR POSTERIOR_SAMPLING_METHOD -%token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION SILENT_OPTIMIZER +%token BALANCED_GROWTH_TEST_TOL BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION SILENT_OPTIMIZER %token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION DR_DISPLAY_TOL HUGE_NUMBER FIG_NAME WRITE_XLS %token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA INTERACTIVE SCREEN_SHOCKS STEADYSTATE %token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN DETAIL_PLOT TYPE @@ -900,6 +900,7 @@ model_options : BLOCK { driver.block(); } | o_linear | PARALLEL_LOCAL_FILES EQUAL '(' parallel_local_filename_list ')' | LINEAR_DECOMPOSITION { driver.linear_decomposition(); } + | BALANCED_GROWTH_TEST_TOL EQUAL non_negative_number { driver.balanced_growth_test_tol($3); } ; model_options_list : model_options_list COMMA model_options diff --git a/src/DynareFlex.ll b/src/DynareFlex.ll index 111d07cb70c8fd564997154b1add554e070c8e16..b24d6a2f9fa1431a1782731597e1db4d74e05095 100644 --- a/src/DynareFlex.ll +++ b/src/DynareFlex.ll @@ -706,6 +706,7 @@ DATE -?[0-9]+([ya]|m([1-9]|1[0-2])|q[1-4]|w([1-9]{1}|[1-4][0-9]|5[0-2])) <DYNARE_BLOCK>periods {return token::PERIODS;} <DYNARE_BLOCK>cutoff {return token::CUTOFF;} <DYNARE_BLOCK>mfs {return token::MFS;} +<DYNARE_BLOCK>balanced_growth_test_tol {return token::BALANCED_GROWTH_TEST_TOL;} <DYNARE_BLOCK>gamma_pdf {return token::GAMMA_PDF;} <DYNARE_BLOCK>beta_pdf {return token::BETA_PDF;} <DYNARE_BLOCK>normal_pdf {return token::NORMAL_PDF;} diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc index 2ecac4d6aede4d546140d47d70368c969c231b21..0aea25adb1de15af62c69a108fa03c60ad466afb 100644 --- a/src/ParsingDriver.cc +++ b/src/ParsingDriver.cc @@ -793,6 +793,12 @@ ParsingDriver::mfs(const string &value) mod_file->static_model.mfs = val; } +void +ParsingDriver::balanced_growth_test_tol(const string &value) +{ + mod_file->dynamic_model.balanced_growth_test_tol = stod(value); +} + void ParsingDriver::end_initval(bool all_values_required) { diff --git a/src/ParsingDriver.hh b/src/ParsingDriver.hh index 42572adf8342bdce344907ec28299ca7e7a15a26..c944dc2c5fe5ce44f5b7da18b076e3c1722fa2b1 100644 --- a/src/ParsingDriver.hh +++ b/src/ParsingDriver.hh @@ -356,6 +356,8 @@ public: void cutoff(const string &value); //! mfs option of model block void mfs(const string &value); + //! balanced_growth_test_tol option of model block + void balanced_growth_test_tol(const string &value); //! Sets the FILENAME for the initial value in initval void initval_file(const string &filename); //! Declares an endogenous variable