Commit c7090532 authored by Ferhat Mihoubi's avatar Ferhat Mihoubi
Browse files

Adds conditional forecast using the extended path method

parent 34099da1
/*
* Copyright (C) 2003-2012 Dynare Team
* Copyright (C) 2003-2013 Dynare Team
*
* This file is part of Dynare.
*
......@@ -1275,7 +1275,7 @@ void
ConditionalForecastStatement::writeOutput(ostream &output, const string &basename) const
{
options_list.writeOutput(output, "options_cond_fcst_");
output << "imcforecast(constrained_paths_, constrained_vars_, options_cond_fcst_);" << endl;
output << "imcforecast(constrained_paths_, constrained_vars_, options_cond_fcst_, constrained_perfect_foresight_);" << endl;
}
PlotConditionalForecastStatement::PlotConditionalForecastStatement(int periods_arg, const SymbolList &symbol_list_arg) :
......
/*
* Copyright (C) 2003-2012 Dynare Team
* Copyright (C) 2003-2013 Dynare Team
*
* This file is part of Dynare.
*
......@@ -96,7 +96,7 @@ class ParsingDriver;
%token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN
%token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED
%token CALIB_SMOOTHER CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR COVAR CUTOFF CYCLE_REDUCTION LOGARITHMIC_REDUCTION
%token DATAFILE FILE DOUBLING DR_CYCLE_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_MAXITER DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION
%token DATAFILE FILE DETERMINISTIC DOUBLING DR_CYCLE_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_MAXITER DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION
%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT EXTENDED_PATH
%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS LAST_OBS SET_TIME
%token <string_val> FLOAT_NUMBER
......@@ -118,13 +118,14 @@ class ParsingDriver;
%token NAN_CONSTANT NO_STATIC NOBS NOCONSTANT NODISPLAY NOCORR NODIAGNOSTIC NOFUNCTIONS
%token NOGRAPH NOMOMENTS NOPRINT NORMAL_PDF
%token OBSERVATION_TRENDS OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS MAX_DIM_COVA_GROUP ADVANCED
%token PARAMETERS PARAMETER_SET PARTIAL_INFORMATION PERIODS PLANNER_OBJECTIVE PLOT_CONDITIONAL_FORECAST PLOT_PRIORS PREFILTER PRESAMPLE
%token PARAMETERS PARAMETER_SET PARTIAL_INFORMATION PERFECT_FORESIGHT PERIODS PLANNER_OBJECTIVE PLOT_CONDITIONAL_FORECAST PLOT_PRIORS PREFILTER PRESAMPLE
%token PRINT PRIOR_MC PRIOR_TRUNC PRIOR_MODE PRIOR_MEAN POSTERIOR_MODE POSTERIOR_MEAN POSTERIOR_MEDIAN PRUNING
%token <string_val> QUOTED_STRING
%token QZ_CRITERIUM FULL DSGE_VAR DSGE_VARLAG DSGE_PRIOR_WEIGHT TRUNCATE
%token RELATIVE_IRF REPLIC SIMUL_REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE PARAMETER_UNCERTAINTY
%token SHOCKS SHOCK_DECOMPOSITION SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED SMOOTHER SQUARE_ROOT_SOLVER STACK_SOLVE_ALGO STEADY_STATE_MODEL SOLVE_ALGO SOLVER_PERIODS
%token STDERR STEADY STOCH_SIMUL SYLVESTER SYLVESTER_FIXED_POINT_TOL REGIMES REGIME
%token SHOCKS SHOCK_DECOMPOSITION SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED SIMULATION_TYPE
%token SMOOTHER SQUARE_ROOT_SOLVER STACK_SOLVE_ALGO STEADY_STATE_MODEL STOCHASTIC SOLVE_ALGO SOLVER_PERIODS
%token STDERR STEADY STOCH_SIMUL SURPRISE SYLVESTER SYLVESTER_FIXED_POINT_TOL REGIMES REGIME
%token TEX RAMSEY_POLICY PLANNER_DISCOUNT DISCRETIONARY_POLICY DISCRETIONARY_TOL
%token <string_val> TEX_NAME
%token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE
......@@ -794,6 +795,12 @@ period_list : period_list COMMA INT_NUMBER
{ driver.add_period($1); }
;
expectation_type : PERFECT_FORESIGHT
{ driver.add_expectation_pf(true); }
| SURPRISE
{ driver.add_expectation_pf(false); }
;
sigma_e : SIGMA_E EQUAL '[' triangular_matrix ']' ';' { driver.do_sigma_e(); };
value_list : value_list COMMA '(' expression ')'
......@@ -864,8 +871,15 @@ check_options : steady_options;
model_info : MODEL_INFO ';'
{ driver.model_info(); }
| MODEL_INFO '(' model_info_options_list ')' ';'
{ driver.model_info(); }
;
model_info_options_list : model_info_options_list COMMA model_info_options
| model_info_options
;
model_info_options :
simul : SIMUL ';'
{ driver.simul(); }
| SIMUL '(' simul_options_list ')' ';'
......@@ -2112,6 +2126,7 @@ conditional_forecast_option : o_periods
| o_conf_sig
| o_controlled_varexo
| o_parameter_set
| o_simulation_type
;
plot_conditional_forecast : PLOT_CONDITIONAL_FORECAST symbol_list ';'
......@@ -2130,6 +2145,8 @@ conditional_forecast_paths_shock_list : conditional_forecast_paths_shock_elem
conditional_forecast_paths_shock_elem : VAR symbol ';' PERIODS period_list ';' VALUES value_list ';'
{ driver.add_det_shock($2, true); }
| VAR symbol ';' PERIODS period_list ';' VALUES value_list ';' EXPECTATION expectation_type ';'
{ driver.add_det_shock($2, true); }
;
steady_state_model : STEADY_STATE_MODEL ';' { driver.begin_steady_state_model(); }
......@@ -2424,6 +2441,11 @@ o_parameter_set : PARAMETER_SET EQUAL PRIOR_MODE
| PARAMETER_SET EQUAL CALIBRATION
{ driver.option_str("parameter_set", "calibration"); }
;
o_simulation_type : SIMULATION_TYPE EQUAL DETERMINISTIC
{ driver.option_str("simulation_type", "deterministic"); }
| SIMULATION_TYPE EQUAL STOCHASTIC
{ driver.option_str("simulation_type", "stochastic"); }
;
o_shocks : SHOCKS EQUAL '(' list_of_symbol_lists ')' { driver.option_symbol_list("shocks"); };
o_labels : LABELS EQUAL '(' symbol_list ')' { driver.option_symbol_list("labels"); };
o_ms_drop : DROP EQUAL INT_NUMBER { driver.option_num("ms.drop", $3); };
......
/*
* Copyright (C) 2003-2012 Dynare Team
* Copyright (C) 2003-2013 Dynare Team
*
* This file is part of Dynare.
*
......@@ -458,6 +458,9 @@ string eofbuff;
<DYNARE_STATEMENT>posterior_mode {return token::POSTERIOR_MODE; }
<DYNARE_STATEMENT>posterior_mean {return token::POSTERIOR_MEAN; }
<DYNARE_STATEMENT>posterior_median {return token::POSTERIOR_MEDIAN; }
<DYNARE_STATEMENT>simulation_type {return token::SIMULATION_TYPE; }
<DYNARE_STATEMENT>deterministic {return token::DETERMINISTIC; }
<DYNARE_STATEMENT>stochastic {return token::STOCHASTIC; }
<DYNARE_STATEMENT>k_order_solver {return token::K_ORDER_SOLVER; }
<DYNARE_STATEMENT>filter_covariance {return token::FILTER_COVARIANCE; }
<DYNARE_STATEMENT>filter_decomposition {return token::FILTER_DECOMPOSITION; }
......@@ -481,6 +484,8 @@ string eofbuff;
<DYNARE_BLOCK>stderr {return token::STDERR;}
<DYNARE_BLOCK>values {return token::VALUES;}
<DYNARE_BLOCK>corr {return token::CORR;}
<DYNARE_BLOCK>surprise {return token::SURPRISE;}
<DYNARE_BLOCK>perfect_foresight {return token::PERFECT_FORESIGHT;}
<DYNARE_BLOCK>periods {return token::PERIODS;}
<DYNARE_BLOCK>cutoff {return token::CUTOFF;}
<DYNARE_BLOCK>mfs {return token::MFS;}
......
/*
* Copyright (C) 2003-2012 Dynare Team
* Copyright (C) 2003-2013 Dynare Team
*
* This file is part of Dynare.
*
......@@ -606,10 +606,12 @@ ParsingDriver::add_det_shock(string *var, bool conditional_forecast)
v.push_back(dse);
}
det_shocks[symb_id] = v;
det_shocks[symb_id].first = v;
det_shocks[symb_id].second = det_shocks_expectation_pf;
det_shocks_periods.clear();
det_shocks_values.clear();
det_shocks_expectation_pf = false;
delete var;
}
......@@ -749,6 +751,12 @@ ParsingDriver::add_value(string *v)
det_shocks_values.push_back(id);
}
void
ParsingDriver::add_expectation_pf(bool pf)
{
det_shocks_expectation_pf = pf;
}
void
ParsingDriver::begin_svar_identification()
{
......
/*
* Copyright (C) 2003-2012 Dynare Team
* Copyright (C) 2003-2013 Dynare Team
*
* This file is part of Dynare.
*
......@@ -131,6 +131,8 @@ private:
vector<pair<int, int> > det_shocks_periods;
//! Temporary storage for values of deterministic shocks
vector<expr_t> det_shocks_values;
//! Temporary storage for perfect foresight of deterministic shocks in conditional forecast
bool det_shocks_expectation_pf;
//! Temporary storage for variances of shocks
ShocksStatement::var_and_std_shocks_t var_shocks;
//! Temporary storage for standard errors of shocks
......@@ -332,6 +334,8 @@ public:
//! Adds a deterministic shock value
/*! \param v a string containing a (possibly negative) numeric constant */
void add_value(string *v);
//! Adds a expectation type for conditional forecast with deterministic simulation
void add_expectation_pf(bool pf);
//! Writes a Sigma_e block
void do_sigma_e();
//! Ends row of Sigma_e block
......
/*
* Copyright (C) 2003-2012 Dynare Team
* Copyright (C) 2003-2013 Dynare Team
*
* This file is part of Dynare.
*
......@@ -46,11 +46,11 @@ AbstractShocksStatement::writeDetShocks(ostream &output) const
bool exo_det = (symbol_table.getType(it->first) == eExogenousDet);
int set_shocks_index = ((int) mshocks) + 2 * ((int) exo_det);
for (size_t i = 0; i < it->second.size(); i++)
for (size_t i = 0; i < it->second.first.size(); i++)
{
const int &period1 = it->second[i].period1;
const int &period2 = it->second[i].period2;
const expr_t value = it->second[i].value;
const int &period1 = it->second.first[i].period1;
const int &period2 = it->second.first[i].period2;
const expr_t value = it->second.first[i].value;
if (period1 == period2)
{
......@@ -262,7 +262,7 @@ ConditionalForecastPathsStatement::checkPass(ModFileStructure &mod_file_struct,
it != paths.end(); it++)
{
int this_path_length = 0;
const vector<AbstractShocksStatement::DetShockElement> &elems = it->second;
const vector<AbstractShocksStatement::DetShockElement> &elems = it->second.first;
for (int i = 0; i < (int) elems.size(); i++)
// Period1 < Period2, as enforced in ParsingDriver::add_period()
this_path_length = max(this_path_length, elems[i].period2);
......@@ -289,11 +289,18 @@ ConditionalForecastPathsStatement::writeOutput(ostream &output, const string &ba
it != paths.end(); it++)
{
if (it == paths.begin())
output << "constrained_vars_ = " << it->first +1 << ";" << endl;
{
output << "constrained_vars_ = " << it->first +1 << ";" << endl;
output << "constrained_perfect_foresight_ = " << it->second.second << ";" << endl;
}
else
output << "constrained_vars_ = [constrained_vars_; " << it->first +1 << "];" << endl;
{
output << "constrained_vars_ = [constrained_vars_; " << it->first +1 << "];" << endl;
output << "constrained_perfect_foresight_ = [constrained_perfect_foresight_; " << it->second.second << "];" << endl;
}
const vector<AbstractShocksStatement::DetShockElement> &elems = it->second;
const vector<AbstractShocksStatement::DetShockElement> &elems = it->second.first;
for (int i = 0; i < (int) elems.size(); i++)
for (int j = elems[i].period1; j <= elems[i].period2; j++)
{
......
/*
* Copyright (C) 2003-2012 Dynare Team
* Copyright (C) 2003-2013 Dynare Team
*
* This file is part of Dynare.
*
......@@ -39,7 +39,9 @@ public:
int period2;
expr_t value;
};
typedef map<int, vector<DetShockElement> > det_shocks_t;
//The boolean element indicates if the shock is a surprise (false) or a perfect foresight (true) shock.
//This boolean is used only in case of conditional forecast with extended path method (simulation_type = deterministic).
typedef map<int, pair< vector<DetShockElement>, bool> > det_shocks_t;
protected:
//! Is this statement a "mshocks" statement ? (instead of a "shocks" statement)
const bool mshocks;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment