Reactivate and fix the test for the balanced growth path.

If the homogeneized equation evaluates to zero, then we skip the
test (otherwise the 2nd derivative of the log is infinite, and the test fails
while it should not necessarily).

Closes #506
time-shift
Sébastien Villemot 2013-10-29 18:46:54 +08:00
parent 4e7806d71c
commit f889760f61
2 changed files with 25 additions and 18 deletions

View File

@ -3757,22 +3757,28 @@ DynamicModel::testTrendDerivativesEqualToZero(const eval_context_t &eval_context
|| symbol_table.getType(it->first.first) == eLogTrend) || symbol_table.getType(it->first.first) == eLogTrend)
for (int eq = 0; eq < (int) equations.size(); eq++) for (int eq = 0; eq < (int) equations.size(); eq++)
{ {
expr_t testeq = AddLog(AddMinus(equations[eq]->get_arg1(), // F: a = b -> ln(a - b) expr_t homogeneq = AddMinus(equations[eq]->get_arg1(),
equations[eq]->get_arg2())); equations[eq]->get_arg2())
testeq = testeq->getDerivative(it->second); // d F / d Trend
for (deriv_id_table_t::const_iterator endogit = deriv_id_table.begin(); // Do not run the test if the term inside the log is zero
endogit != deriv_id_table.end(); endogit++) if (fabs(homogeneq->eval(eval_context)) > ZERO_BAND)
if (symbol_table.getType(endogit->first.first) == eEndogenous) {
{ expr_t testeq = AddLog(homogeneq); // F = log(lhs-rhs)
double nearZero = testeq->getDerivative(endogit->second)->eval(eval_context); // eval d F / d Trend d Endog testeq = testeq->getDerivative(it->second); // d F / d Trend
if (fabs(nearZero) > ZERO_BAND) for (deriv_id_table_t::const_iterator endogit = deriv_id_table.begin();
endogit != deriv_id_table.end(); endogit++)
if (symbol_table.getType(endogit->first.first) == eEndogenous)
{ {
cerr << "ERROR: trends not compatible with balanced growth path; the second-order cross partial of equation " << eq + 1 << " w.r.t. trend variable " double nearZero = testeq->getDerivative(endogit->second)->eval(eval_context); // eval d F / d Trend d Endog
<< symbol_table.getName(it->first.first) << " and endogenous variable " if (fabs(nearZero) > ZERO_BAND)
<< symbol_table.getName(endogit->first.first) << " is not null. " << endl; {
exit(EXIT_FAILURE); cerr << "ERROR: trends not compatible with balanced growth path; the second-order cross partial of equation " << eq + 1 << " w.r.t. trend variable "
<< symbol_table.getName(it->first.first) << " and endogenous variable "
<< symbol_table.getName(endogit->first.first) << " is not null. " << endl;
exit(EXIT_FAILURE);
}
} }
} }
} }
} }
@ -4134,8 +4140,9 @@ DynamicModel::transformPredeterminedVariables()
void void
DynamicModel::detrendEquations() DynamicModel::detrendEquations()
{ {
for (nonstationary_symbols_map_t::const_iterator it = nonstationary_symbols_map.begin(); // We go backwards in the list of trend_vars, to deal correctly with I(2) processes
it != nonstationary_symbols_map.end(); it++) for (nonstationary_symbols_map_t::const_reverse_iterator it = nonstationary_symbols_map.rbegin();
it != nonstationary_symbols_map.rend(); ++it)
for (int i = 0; i < (int) equations.size(); i++) for (int i = 0; i < (int) equations.size(); i++)
{ {
BinaryOpNode *substeq = dynamic_cast<BinaryOpNode *>(equations[i]->detrend(it->first, it->second.first, it->second.second)); BinaryOpNode *substeq = dynamic_cast<BinaryOpNode *>(equations[i]->detrend(it->first, it->second.first, it->second.second));

View File

@ -416,8 +416,8 @@ ModFile::computingPass(bool no_tmp_terms)
// Mod file may have no equation (for example in a standalone BVAR estimation) // Mod file may have no equation (for example in a standalone BVAR estimation)
if (dynamic_model.equation_number() > 0) if (dynamic_model.equation_number() > 0)
{ {
/*if (nonstationary_variables) if (nonstationary_variables)
trend_dynamic_model.runTrendTest(global_eval_context);*/ trend_dynamic_model.runTrendTest(global_eval_context);
// Compute static model and its derivatives // Compute static model and its derivatives
dynamic_model.toStatic(static_model); dynamic_model.toStatic(static_model);