Commit afe0e475 authored by Houtan Bastani's avatar Houtan Bastani

trend_component_model statement

parent 618147a1
......@@ -258,16 +258,14 @@ PriorPosteriorFunctionStatement::writeJsonOutput(ostream &output) const
}
PacModelStatement::PacModelStatement(string name_arg,
string var_name_arg,
string aux_model_name_arg,
string discount_arg,
string growth_arg,
map<string, int> undiff_arg,
const SymbolTable &symbol_table_arg) :
name{move(name_arg)},
var_name{move(var_name_arg)},
aux_model_name{move(aux_model_name_arg)},
discount{move(discount_arg)},
growth{move(growth_arg)},
undiff{move(undiff_arg)},
symbol_table{symbol_table_arg}
{
}
......@@ -289,7 +287,7 @@ PacModelStatement::fillUndiffedLHS(vector<int> &lhs_arg)
void
PacModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{
output << "M_.pac." << name << ".var_model_name = '" << var_name << "';" << endl
output << "M_.pac." << name << ".auxiliary_model_name = '" << aux_model_name << "';" << endl
<< "M_.pac." << name << ".discount_index = " << symbol_table.getTypeSpecificID(discount) + 1 << ";" << endl;
if (!growth.empty())
......@@ -320,7 +318,8 @@ PacModelStatement::writeOutput(ostream &output, const string &basename, bool min
output << " ";
output << *it + 1;
}
output << "];" << endl
output << "];" << endl;
/*
<< "M_.pac." << name << ".undiff_eqtags = {";
for (auto it = undiff.begin(); it != undiff.end(); it++)
{
......@@ -337,6 +336,7 @@ PacModelStatement::writeOutput(ostream &output, const string &basename, bool min
output << it->second;
}
output << "];" << endl;
*/
}
void
......@@ -344,7 +344,7 @@ PacModelStatement::writeJsonOutput(ostream &output) const
{
output << "{\"statementName\": \"pac_model\","
<< "\"model_name\": \"" << name << "\","
<< "\"var_model_name\": \"" << var_name << "\","
<< "\"auxiliary_model_name\": \"" << aux_model_name << "\","
<< "\"discount_index\": " << symbol_table.getTypeSpecificID(discount) + 1;
if (!growth.empty())
......@@ -371,13 +371,13 @@ PacModelStatement::writeJsonOutput(ostream &output) const
output << "}";
}
void
PacModelStatement::getPacModelInfoForPacExpectation(tuple<string, string, string, int, map<string, int>> &pac_model_info) const
tuple<string, string, int>
PacModelStatement::getPacModelInfoForPacExpectation() const
{
int growth_symb_id = -1;
if (!growth.empty())
growth_symb_id = symbol_table.getID(growth);
pac_model_info = { name, var_name, discount, growth_symb_id, undiff };
return { name, aux_model_name, growth_symb_id };
}
VarModelStatement::VarModelStatement(SymbolList symbol_list_arg,
......@@ -2207,8 +2207,12 @@ ModelComparisonStatement::writeJsonOutput(ostream &output) const
output << "}";
}
PlannerObjectiveStatement::PlannerObjectiveStatement(SymbolTable &symbol_table, NumericalConstants &num_constants, ExternalFunctionsTable &external_functions_table) :
model_tree{symbol_table, num_constants, external_functions_table}
PlannerObjectiveStatement::PlannerObjectiveStatement(SymbolTable &symbol_table,
NumericalConstants &num_constants,
ExternalFunctionsTable &external_functions_table,
TrendComponentModelTable &trend_component_model_table_arg) :
model_tree{symbol_table, num_constants,
external_functions_table, trend_component_model_table_arg}
{
}
......
......@@ -123,24 +123,22 @@ class PacModelStatement : public Statement
{
private:
const string name;
const string var_name;
const string aux_model_name;
const string discount;
const string growth;
const map<string, int> undiff;
const SymbolTable &symbol_table;
vector<int> lhs;
public:
PacModelStatement(string name_arg,
string var_name_arg,
string aux_model_name_arg,
string discount_arg,
string growth_arg,
map<string, int> undiff_arg,
const SymbolTable &symbol_table_arg);
void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) override;
void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const override;
void writeJsonOutput(ostream &output) const override;
void fillUndiffedLHS(vector<int> &lhs);
void getPacModelInfoForPacExpectation(tuple<string, string, string, int, map<string, int>> &pac_model_info) const;
tuple<string, string, int> getPacModelInfoForPacExpectation() const;
};
class VarModelStatement : public Statement
......@@ -542,7 +540,8 @@ private:
public:
PlannerObjectiveStatement(SymbolTable &symbol_table,
NumericalConstants &num_constants,
ExternalFunctionsTable &external_functions_table);
ExternalFunctionsTable &external_functions_table,
TrendComponentModelTable &trend_component_model_table_arg);
/*! \todo check there are only endogenous variables at the current period in the objective
(no exogenous, no lead/lag) */
void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) override;
......
......@@ -28,10 +28,12 @@
DataTree::DataTree(SymbolTable &symbol_table_arg,
NumericalConstants &num_constants_arg,
ExternalFunctionsTable &external_functions_table_arg) :
ExternalFunctionsTable &external_functions_table_arg,
TrendComponentModelTable &trend_component_model_table_arg) :
symbol_table(symbol_table_arg),
num_constants(num_constants_arg),
external_functions_table(external_functions_table_arg),
trend_component_model_table(trend_component_model_table_arg),
node_counter(0)
{
Zero = AddNonNegativeConstant("0");
......
......@@ -34,6 +34,7 @@ using namespace std;
#include "NumericalConstants.hh"
#include "ExternalFunctionsTable.hh"
#include "ExprNode.hh"
#include "SubModel.hh"
class DataTree
{
......@@ -56,6 +57,8 @@ protected:
NumericalConstants &num_constants;
//! A reference to the external functions table
ExternalFunctionsTable &external_functions_table;
//! A reference to the trend component model table
TrendComponentModelTable &trend_component_model_table;
//! num_constant_id -> NumConstNode
using num_const_node_map_t = map<int, NumConstNode *>;
......@@ -130,7 +133,10 @@ private:
inline expr_t AddTrinaryOp(expr_t arg1, TrinaryOpcode op_code, expr_t arg2, expr_t arg3);
public:
DataTree(SymbolTable &symbol_table_arg, NumericalConstants &num_constants_arg, ExternalFunctionsTable &external_functions_table_arg);
DataTree(SymbolTable &symbol_table_arg,
NumericalConstants &num_constants_arg,
ExternalFunctionsTable &external_functions_table_arg,
TrendComponentModelTable &trend_component_model_table_arg);
virtual
~DataTree();
......
This diff is collapsed.
......@@ -250,7 +250,7 @@ private:
void findPacExpectationEquationNumbers(vector<int> &eqnumber) const;
public:
DynamicModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants_arg, ExternalFunctionsTable &external_functions_table_arg);
DynamicModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants_arg, ExternalFunctionsTable &external_functions_table_arg, TrendComponentModelTable &trend_component_model_table_arg);
//! Adds a variable node
/*! This implementation allows for non-zero lag */
VariableNode *AddVariable(int symb_id, int lag = 0) override;
......@@ -300,26 +300,12 @@ public:
//! Set the equations that have non-zero second derivatives
void setNonZeroHessianEquations(map<int, string> &eqs);
//! Get equation info associated with equation tags from var_model
void getVarModelVariablesFromEqTags(vector<string> &var_model_eqtags,
vector<int> &eqnumber,
vector<int> &lhs,
vector<expr_t> &lhs_expr_t,
vector<set<pair<int, int>>> &rhs,
vector<bool> &nonstationary) const;
//! Returns the max lag of the VAR
void checkVarMinLag(vector<int> &eqnumber) const;
//! Returns the max lag of the VAR
int getVarMaxLag(StaticModel &static_model, vector<int> &eqnumber) const;
// Get equtaino information on diff operator and max lag info
void getVarLhsDiffAndInfo(vector<int> &eqnumber, vector<bool> &diff,
vector<int> &orig_diff_var) const;
//! Fill the Trend Component Model Table
void fillTrendComponentModelTable() const;
void fillTrendComponentModelTableFromOrigModel(StaticModel &static_model) const;
//! Add aux equations (and aux variables) for variables declared in var_model at max order if they don't already exist
void addEquationsForVar(map<string, pair<SymbolList, int>> &var_model_info);
// void addEquationsForVar(map<string, pair<SymbolList, int>> &var_model_info);
//! Get Pac equation parameter info
void walkPacParameters();
//! Add var_model info to pac_expectation nodes
......@@ -439,8 +425,8 @@ public:
int getPacMaxLag(const string &pac_model_name) const;
//! Table to undiff LHS variables for pac vector z
void getUndiffLHSForPac(vector<int> &lhs, vector<expr_t> &lhs_expr_t, vector<bool> &diff, vector<int> &orig_diff_var,
vector<int> &eqnumber, map<string, int> &undiff, ExprNode::subst_table_t &diff_subst_table);
vector<int> getUndiffLHSForPac(const string &aux_model_name,
ExprNode::subst_table_t &diff_subst_table);
//! Transforms the model by replacing trend variables with a 1
void removeTrendVariableFromEquations();
......
......@@ -111,7 +111,7 @@ class ParsingDriver;
%token PRINT PRIOR_MC PRIOR_TRUNC PRIOR_MODE PRIOR_MEAN POSTERIOR_MODE POSTERIOR_MEAN POSTERIOR_MEDIAN MLE_MODE PRUNING
%token <string> QUOTED_STRING
%token QZ_CRITERIUM QZ_ZERO_THRESHOLD DSGE_VAR DSGE_VARLAG DSGE_PRIOR_WEIGHT TRUNCATE PIPE_E PIPE_X PIPE_P
%token RELATIVE_IRF REPLIC SIMUL_REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE PARAMETER_UNCERTAINTY
%token RELATIVE_IRF REPLIC SIMUL_REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE PARAMETER_UNCERTAINTY TRENDS
%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 ROBUST_LIN_SOLVE
%token STDERR STEADY STOCH_SIMUL SYLVESTER SYLVESTER_FIXED_POINT_TOL REGIMES REGIME REALTIME_SHOCK_DECOMPOSITION
......@@ -120,14 +120,14 @@ 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 VARIABLE VAROBS VAREXOBS PREDETERMINED_VARIABLES VAR_EXPECTATION VAR_EXPECTATION_MODEL PLOT_SHOCK_DECOMPOSITION MODEL_LOCAL_VARIABLE
%token WRITE_LATEX_DYNAMIC_MODEL WRITE_LATEX_STATIC_MODEL WRITE_LATEX_ORIGINAL_MODEL CROSSEQUATIONS COVARIANCE WRITE_LATEX_STEADY_STATE_MODEL
%token XLS_SHEET XLS_RANGE LMMCP OCCBIN BANDPASS_FILTER COLORMAP VAR_MODEL PAC_MODEL QOQ YOY AOA UNDIFF PAC_EXPECTATION
%token XLS_SHEET XLS_RANGE LMMCP OCCBIN BANDPASS_FILTER COLORMAP VAR_MODEL PAC_MODEL QOQ YOY AOA UNDIFF PAC_EXPECTATION TREND_COMPONENT_MODEL
%left EQUAL_EQUAL EXCLAMATION_EQUAL
%left LESS GREATER LESS_EQUAL GREATER_EQUAL
%left PLUS MINUS
%left TIMES DIVIDE
%precedence UMINUS UPLUS
%nonassoc POWER
%token EXP LOG LN LOG10 SIN COS TAN ASIN ACOS ATAN ERF DIFF ADL
%token EXP LOG LN LOG10 SIN COS TAN ASIN ACOS ATAN ERF DIFF ADL AUXILIARY_MODEL_NAME
%token SQRT NORMCDF NORMPDF STEADY_STATE EXPECTATION VAR_ESTIMATION
/* GSA analysis */
%token DYNARE_SENSITIVITY MORRIS STAB REDFORM PPRIOR PRIOR_RANGE PPOST ILPTAU MORRIS_NLIV
......@@ -223,6 +223,7 @@ statement : parameters
| data
| var_model
| pac_model
| trend_component_model
| restrictions
| prior
| prior_eq
......@@ -374,6 +375,18 @@ var_model_options : o_var_name
| o_var_eq_tags
;
trend_component_model : TREND_COMPONENT_MODEL '(' trend_component_model_options_list ')' ';' { driver.trend_component_model(); }
;
trend_component_model_options_list : trend_component_model_options_list COMMA trend_component_model_options
| trend_component_model_options
;
trend_component_model_options : o_trend_component_model_name
| o_trend_component_model_trends
| o_trend_component_model_eq_tags
;
pac_model : PAC_MODEL '(' pac_model_options_list ')' ';' { driver.pac_model(); } ;
pac_model_options_list : pac_model_options_list COMMA pac_model_options
......@@ -381,11 +394,9 @@ pac_model_options_list : pac_model_options_list COMMA pac_model_options
;
pac_model_options : o_pac_name
| o_pac_var_name
| o_pac_aux_model_name
| o_pac_discount
| o_pac_growth
| UNDIFF '(' QUOTED_STRING COMMA INT_NUMBER ')'
{ driver.pac_model_undiff($3, $5); }
;
var_expectation_model : VAR_EXPECTATION_MODEL '(' var_expectation_model_options_list ')' ';'
......@@ -3084,7 +3095,7 @@ o_qz_criterium : QZ_CRITERIUM EQUAL non_negative_number { driver.option_num("qz_
o_qz_zero_threshold : QZ_ZERO_THRESHOLD EQUAL non_negative_number { driver.option_num("qz_zero_threshold", $3); };
o_file : FILE EQUAL filename { driver.option_str("file", $3); };
o_pac_name : MODEL_NAME EQUAL symbol { driver.option_str("pac.model_name", $3); };
o_pac_var_name : VAR_MODEL_NAME EQUAL symbol { driver.option_str("pac.var_model_name", $3); };
o_pac_aux_model_name : AUXILIARY_MODEL_NAME EQUAL symbol { driver.option_str("pac.aux_model_name", $3); };
o_pac_discount : DISCOUNT EQUAL symbol { driver.option_str("pac.discount", $3); };
o_pac_growth : GROWTH EQUAL symbol { driver.option_str("pac.growth", $3); };
o_var_name : MODEL_NAME EQUAL symbol { driver.option_str("var.model_name", $3); };
......@@ -3101,6 +3112,9 @@ o_nobs : NOBS EQUAL vec_int
| NOBS EQUAL vec_int_number
{ driver.option_vec_int("nobs", $3); }
;
o_trend_component_model_name : MODEL_NAME EQUAL symbol { driver.option_str("trend_component.name", $3); };
o_trend_component_model_trends : TRENDS EQUAL vec_str { driver.option_vec_str("trend_component.trends", $3); }
o_trend_component_model_eq_tags : EQTAGS EQUAL vec_str { driver.option_vec_str("trend_component.eqtags", $3); }
o_conditional_variance_decomposition : CONDITIONAL_VARIANCE_DECOMPOSITION EQUAL vec_int
{ driver.option_vec_int("conditional_variance_decomposition", $3); }
| CONDITIONAL_VARIANCE_DECOMPOSITION EQUAL vec_int_number
......
......@@ -141,6 +141,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>simul {BEGIN DYNARE_STATEMENT; return token::SIMUL;}
<INITIAL>stoch_simul {BEGIN DYNARE_STATEMENT; return token::STOCH_SIMUL;}
<INITIAL>var_model {BEGIN DYNARE_STATEMENT; return token::VAR_MODEL;}
<INITIAL>trend_component_model {BEGIN DYNARE_STATEMENT; return token::TREND_COMPONENT_MODEL;}
<INITIAL>var_expectation_model {BEGIN DYNARE_STATEMENT; return token::VAR_EXPECTATION_MODEL;}
<INITIAL>pac_model {BEGIN DYNARE_STATEMENT; return token::PAC_MODEL;}
<INITIAL>dsample {BEGIN DYNARE_STATEMENT; return token::DSAMPLE;}
......@@ -348,6 +349,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
<DYNARE_STATEMENT>periods {return token::PERIODS;}
<DYNARE_STATEMENT,DYNARE_BLOCK>model_name {return token::MODEL_NAME;}
<DYNARE_STATEMENT>var_model_name {return token::VAR_MODEL_NAME;}
<DYNARE_STATEMENT>auxiliary_model_name {return token::AUXILIARY_MODEL_NAME;}
<DYNARE_STATEMENT>endogenous_terminal_period {return token::ENDOGENOUS_TERMINAL_PERIOD;}
<DYNARE_STATEMENT>sub_draws {return token::SUB_DRAWS;}
<DYNARE_STATEMENT>minimal_solving_periods {return token::MINIMAL_SOLVING_PERIODS;}
......@@ -487,6 +489,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
}
<DYNARE_STATEMENT>write_equation_tags {return token::WRITE_EQUATION_TAGS;}
<DYNARE_STATEMENT>eqtags {return token::EQTAGS;}
<DYNARE_STATEMENT>trends {return token::TRENDS;}
<DYNARE_STATEMENT>indxap {return token::INDXAP;}
<DYNARE_STATEMENT>apband {return token::APBAND;}
<DYNARE_STATEMENT>indximf {return token::INDXIMF;}
......
......@@ -52,7 +52,9 @@ dynare_m_SOURCES = \
SteadyStateModel.cc \
WarningConsolidation.hh \
WarningConsolidation.cc \
ExtendedPreprocessorTypes.hh
ExtendedPreprocessorTypes.hh \
SubModel.cc \
SubModel.hh
ACLOCAL_AMFLAGS = -I m4
......
This diff is collapsed.
......@@ -38,6 +38,7 @@ using namespace std;
#include "ConfigFile.hh"
#include "WarningConsolidation.hh"
#include "ExtendedPreprocessorTypes.hh"
#include "SubModel.hh"
//! The abstract representation of a "mod" file
class ModFile
......@@ -51,6 +52,8 @@ public:
ExternalFunctionsTable external_functions_table;
//! Numerical constants table
NumericalConstants num_constants;
//! Trend Component Model Table used for storing info about trend component models
TrendComponentModelTable trend_component_model_table;
//! Expressions outside model block
DataTree expressions_tree;
//! Original model, as declared in the "model" block, that won't be modified by the preprocessor
......@@ -69,6 +72,7 @@ public:
SteadyStateModel steady_state_model;
//! Static model used for mapping arguments of diff operator
StaticModel diff_static_model;
//! Option linear
bool linear;
......
......@@ -1003,8 +1003,10 @@ ModelTree::BlockLinear(const blocks_derivatives_t &blocks_derivatives, const vec
ModelTree::ModelTree(SymbolTable &symbol_table_arg,
NumericalConstants &num_constants_arg,
ExternalFunctionsTable &external_functions_table_arg) :
DataTree(symbol_table_arg, num_constants_arg, external_functions_table_arg),
ExternalFunctionsTable &external_functions_table_arg,
TrendComponentModelTable &trend_component_model_table_arg) :
DataTree(symbol_table_arg, num_constants_arg,
external_functions_table_arg, trend_component_model_table_arg),
cutoff(1e-15),
mfs(0)
......
......@@ -321,7 +321,10 @@ protected:
//! Initialize equation_reordered & variable_reordered
void initializeVariablesAndEquations();
public:
ModelTree(SymbolTable &symbol_table_arg, NumericalConstants &num_constants_arg, ExternalFunctionsTable &external_functions_table_arg);
ModelTree(SymbolTable &symbol_table_arg,
NumericalConstants &num_constants_arg,
ExternalFunctionsTable &external_functions_table_arg,
TrendComponentModelTable &trend_component_model_table_arg);
//! Absolute value under which a number is considered to be zero
double cutoff;
//! Compute the minimum feedback set
......
......@@ -348,7 +348,8 @@ ParsingDriver::declare_or_change_type(SymbolType new_type, const string &name)
// change in equations in ModelTree
auto dm = make_unique<DynamicModel>(mod_file->symbol_table,
mod_file->num_constants,
mod_file->external_functions_table);
mod_file->external_functions_table,
mod_file->trend_component_model_table);
mod_file->dynamic_model.updateAfterVariableChange(*dm);
// remove error messages
......@@ -1418,6 +1419,30 @@ ParsingDriver::stoch_simul()
options_list.clear();
}
void
ParsingDriver::trend_component_model()
{
OptionsList::string_options_t::const_iterator it =
options_list.string_options.find("trend_component.name");
if (it == options_list.string_options.end())
error("You must pass the model_name option to the trend_component_model statement.");
auto name = it->second;
OptionsList::vec_str_options_t::const_iterator it1 =
options_list.vector_str_options.find("trend_component.eqtags");
if (it1 == options_list.vector_str_options.end())
error("You must pass the eqtags option to the trend_component_model statement.");
auto eqtags = it1->second;
it1 = options_list.vector_str_options.find("trend_component.trends");
if (it1 == options_list.vector_str_options.end())
error("You must pass the trends option to the trend_component_model statement.");
auto trends = it1->second;
mod_file->trend_component_model_table.addTrendComponentModel(name, eqtags, trends);
options_list.clear();
}
void
ParsingDriver::var_model()
{
......@@ -2045,7 +2070,10 @@ ParsingDriver::run_model_comparison()
void
ParsingDriver::begin_planner_objective()
{
planner_objective_statement = new PlannerObjectiveStatement(mod_file->symbol_table, mod_file->num_constants, mod_file->external_functions_table);
planner_objective_statement = new PlannerObjectiveStatement(mod_file->symbol_table,
mod_file->num_constants,
mod_file->external_functions_table,
mod_file->trend_component_model_table);
set_current_data_tree(&planner_objective_statement->getPlannerObjective());
}
......@@ -2527,10 +2555,10 @@ ParsingDriver::pac_model()
error("You must pass the model_name option to the pac_model statement.");
auto name = it->second;
it = options_list.string_options.find("pac.var_model_name");
it = options_list.string_options.find("pac.aux_model_name");
if (it == options_list.string_options.end())
error("You must pass the var_model_name option to the pac_model statement.");
auto var_name = it->second;
error("You must pass the auxiliary_model_name option to the pac_model statement.");
auto aux_model_name = it->second;
it = options_list.string_options.find("pac.discount");
if (it == options_list.string_options.end())
......@@ -2542,17 +2570,11 @@ ParsingDriver::pac_model()
if (it != options_list.string_options.end())
growth = it->second;
mod_file->addStatement(new PacModelStatement(name, var_name, discount, growth, pac_undiff, mod_file->symbol_table));
mod_file->addStatement(new PacModelStatement(name, aux_model_name, discount, growth,
mod_file->symbol_table));
symbol_list.clear();
options_list.clear();
pac_undiff.clear();
}
void
ParsingDriver::pac_model_undiff(string eqtag, const string &order)
{
pac_undiff[move(eqtag)] = stoi(order);
}
expr_t
......
......@@ -242,8 +242,6 @@ private:
SymbolList graph_formats;
//! Temporary storage for equation tags
vector<pair<string, string>> eq_tags;
//! Temporary storage for pac statement undiff option
map<string, int> pac_undiff;
//! Map Var name to variables
map<string, vector<string>> var_map;
......@@ -463,6 +461,8 @@ public:
void rplot();
//! Writes a stock_simul command
void stoch_simul();
//! Writes a trend component command
void trend_component_model();
//! Writes a var (vector autoregression) command
void var_model();
//! Writes a simul command
......@@ -697,8 +697,6 @@ public:
expr_t add_pac_expectation(const string &var_model_name);
//! Creates pac_model statement
void pac_model();
//! Add undiff option for pac_model statement
void pac_model_undiff(string eqtag, const string &order);
//! Writes token "diff(arg1)" to model tree
expr_t add_diff(expr_t arg1);
//! Writes token "adl(arg1, lag)" to model tree
......
......@@ -31,8 +31,10 @@
StaticModel::StaticModel(SymbolTable &symbol_table_arg,
NumericalConstants &num_constants_arg,
ExternalFunctionsTable &external_functions_table_arg) :
ModelTree(symbol_table_arg, num_constants_arg, external_functions_table_arg),
ExternalFunctionsTable &external_functions_table_arg,
TrendComponentModelTable &trend_component_model_table_arg) :
ModelTree(symbol_table_arg, num_constants_arg,
external_functions_table_arg, trend_component_model_table_arg),
global_temporary_terms(true)
{
}
......
......@@ -160,7 +160,10 @@ protected:
void writeStaticModel(ostream &DynamicOutput, bool use_dll, bool julia) const;
void writeStaticModel(const string &dynamic_basename, bool use_dll, bool julia) const;
public:
StaticModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants, ExternalFunctionsTable &external_functions_table_arg);
StaticModel(SymbolTable &symbol_table_arg,
NumericalConstants &num_constants,
ExternalFunctionsTable &external_functions_table_arg,
TrendComponentModelTable &trend_component_model_table_arg);
//! Writes information on block decomposition when relevant
void writeOutput(ostream &output, bool block) const;
......
......@@ -22,8 +22,14 @@
#include "SteadyStateModel.hh"
SteadyStateModel::SteadyStateModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants_arg, ExternalFunctionsTable &external_functions_table_arg, const StaticModel &static_model_arg) :
DataTree(symbol_table_arg, num_constants_arg, external_functions_table_arg), static_model(static_model_arg)
SteadyStateModel::SteadyStateModel(SymbolTable &symbol_table_arg,
NumericalConstants &num_constants_arg,
ExternalFunctionsTable &external_functions_table_arg,
TrendComponentModelTable &trend_component_model_table_arg,
const StaticModel &static_model_arg) :
DataTree(symbol_table_arg, num_constants_arg,
external_functions_table_arg, trend_component_model_table_arg),
static_model(static_model_arg)
{
}
......
......@@ -35,7 +35,11 @@ private:
const StaticModel &static_model;
public:
SteadyStateModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants_arg, ExternalFunctionsTable &external_functions_table_arg, const StaticModel &static_model_arg);
SteadyStateModel(SymbolTable &symbol_table_arg,
NumericalConstants &num_constants_arg,
ExternalFunctionsTable &external_functions_table_arg,
TrendComponentModelTable &trend_component_model_table_arg,
const StaticModel &static_model_arg);
//! Add an expression of the form "var = expr;"
void addDefinition(int symb_id, expr_t expr);
//! Add an expression of the form "[ var1, var2, ... ] = expr;"
......
/*
* Copyright (C) 2018 Dynare Team
*
* This file is part of Dynare.
*
* Dynare is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Dynare is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include "SubModel.hh"
TrendComponentModelTable::TrendComponentModelTable(SymbolTable &symbol_table_arg) :
symbol_table(symbol_table_arg)
{
}
void
TrendComponentModelTable::addTrendComponentModel(string name_arg,
vector<string> eqtags_arg,
vector<string> trend_eqtags_arg)
{
if (isExistingTrendComponentModelName(name_arg))
{
cerr << "Error: a trend component model already exists with the name " << name_arg << endl;
exit(EXIT_FAILURE);
}
eqtags[name_arg] = move(eqtags_arg);
trend_eqtags[name_arg] = move(trend_eqtags_arg);
names.insert(move(name_arg));
}
void
TrendComponentModelTable::setEqNums(map<string, vector<int>> eqnums_arg)
{
eqnums = move(eqnums_arg);
setUndiffEqnums();
}
void
TrendComponentModelTable::setTrendEqNums(map<string, vector<int>> trend_eqnums_arg)
{
trend_eqnums = move(trend_eqnums_arg);
setUndiffEqnums();
}
void
TrendComponentModelTable::setUndiffEqnums()
{
if (!nontrend_eqnums.empty() || eqnums.empty() || trend_eqnums.empty())
return;
for (const auto &it : eqnums)
{
vector<int> nontrend_vec;
for (auto eq : it.second)
if (find(trend_eqnums[it.first].begin(), trend_eqnums[it.first].end(), eq)
== trend_eqnums[it.first].end())
nontrend_vec.push_back(eq);
nontrend_eqnums[it.first] = nontrend_vec;
}
}
void
TrendComponentModelTable::setNonstationary(map<string, vector<bool>> nonstationary_arg)
{
nonstationary = move(nonstationary_arg);
}
void
TrendComponentModelTable::setLhs(map<string, vector<int>> lhs_arg)
{
lhs = move(lhs_arg);
}
void