Commit dbc9e099 authored by sebastien's avatar sebastien
Browse files

* Preprocessor: implemented interface to conditional forecast, with three new...

* Preprocessor: implemented interface to conditional forecast, with three new statements: "conditional_forecast", "conditional_forecast_paths" and "plot_conditional_forecast"
* Reference manual: created a section on forecasting (with "forecast" option), and added the three new statements to that section


git-svn-id: https://www.dynare.org/svn/dynare/trunk@3049 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 3c2d944c
...@@ -1409,13 +1409,12 @@ periods 100; ...@@ -1409,13 +1409,12 @@ periods 100;
<sect1><title>Solving and simulating</title> <sect1><title>Solving and simulating</title>
<para> <para>
Dynare has special commands for the computation of the static equilibrium of the model (<xref linkend='steady'/>, of the eigenvalues of the linearized model (<xref linkend='check'/>) for dynamics local analysis, of a deterministic simulation (<xref linkend='simul'/>) and for solving and/or simulating a stochastic model (<xref linkend='stoch_simul'/>). Dynare has special commands for the computation of the static equilibrium of the model (<xref linkend='steady'/>), of the eigenvalues of the linearized model (<xref linkend='check'/>) for dynamics local analysis, of a deterministic simulation (<xref linkend='simul'/>) and for solving and/or simulating a stochastic model (<xref linkend='stoch_simul'/>).
</para> </para>
<itemizedlist> <itemizedlist>
<listitem><para><xref linkend='steady'/></para></listitem> <listitem><para><xref linkend='steady'/></para></listitem>
<listitem><para><xref linkend='homotopy_setup'/></para></listitem> <listitem><para><xref linkend='homotopy_setup'/></para></listitem>
<listitem><para><xref linkend='check'/></para></listitem> <listitem><para><xref linkend='check'/></para></listitem>
<listitem><para><xref linkend='forecast'/></para></listitem>
<listitem><para><xref linkend='simul'/></para></listitem> <listitem><para><xref linkend='simul'/></para></listitem>
<listitem><para><xref linkend='stoch_simul'/></para></listitem> <listitem><para><xref linkend='stoch_simul'/></para></listitem>
</itemizedlist> </itemizedlist>
...@@ -1558,82 +1557,6 @@ A necessary condition for the uniqueness of a stable equilibrium in the neighbor ...@@ -1558,82 +1557,6 @@ A necessary condition for the uniqueness of a stable equilibrium in the neighbor
</refsect1> </refsect1>
</refentry> </refentry>
<refentry id="forecast">
<refmeta>
<refentrytitle>forecast</refentrytitle>
</refmeta>
<refnamediv>
<refname>forecast</refname>
<refpurpose>computes a simulation of a stochastic model from a given state</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>forecast</command>
<arg>(<replaceable>OPTION</replaceable><arg rep="repeat">, <replaceable>OPTION</replaceable></arg>)</arg>
<arg><replaceable>VARIABLE_NAME</replaceable></arg>
<arg rep="repeat"><arg>,</arg> <replaceable>VARIABLE_NAME</replaceable></arg><arg choice="plain">;</arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1><title>Options</title>
<variablelist>
<varlistentry>
<term><option>periods</option> = <replaceable>INTEGER</replaceable></term>
<listitem><para>Number of periods of the forecast. Default: <literal>40</literal></para></listitem>
</varlistentry>
<varlistentry id="conf_sig" xreflabel="conf_sig">
<term><option>conf_sig</option> = <replaceable>DOUBLE</replaceable></term>
<listitem><para>Level of significance for confidence interval. Default: <literal>0.90</literal></para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1><title>Description</title>
<para><command>forecast</command> computes a simulation of a stochastic model from an arbitrary initial point.</para>
<para>When the model also contains deterministic exogenous shocks, the simulation is computed conditionaly to the agents knowing the future values of the deterministic exogenous variables.</para>
<para><command>forecast</command> must be called after <xref linkend="stoch_simul"/>.</para>
<para><command>forecast</command> plots the trajectory of endogenous variables. When a list of variable names follows the command, only those variables are plotted. A 90% confidence interval is plotted around the mean trajectory. Use option <option>conf_sig</option> to change the level of the confidence interval.</para>
</refsect1>
<refsect1><title>Output variables</title>
<para>The following variables are set in structure <varname>oo_</varname>:
<itemizedlist spacing="compact">
<listitem><para><varname>oo_.forecast.Mean.<replaceable>VARIABLE_NAME</replaceable></varname>: mean forecast of endogenous variables</para></listitem>
<listitem><para><varname>oo_.forecast.HPDinf.<replaceable>VARIABLE_NAME</replaceable></varname>: lower bound of a confidence interval around the forecast</para></listitem>
<listitem><para><varname>oo_.forecast.HPDsup.<replaceable>VARIABLE_NAME</replaceable></varname>: upper bound of a confidence interval around the forecast</para></listitem>
<listitem><para><varname>oo_.forecast.Exogenous.<replaceable>VARIABLE_NAME</replaceable></varname>: trajectory of the deterministic exogenous variables</para></listitem>
</itemizedlist>
</para>
</refsect1>
<refsect1><title>Example</title>
<informalexample>
<programlisting>
varexo_det tau;
varexo e;
...
shocks;
var e; stderr 0.01;
var tau;
periods 1:9;
values -0.15;
end;
stoch_simul(irf=0);
forecast;
</programlisting>
</informalexample>
</refsect1>
</refentry>
<refentry id="simul"> <refentry id="simul">
<refmeta> <refmeta>
<refentrytitle>simul</refentrytitle> <refentrytitle>simul</refentrytitle>
...@@ -2843,6 +2766,228 @@ oo_.posterior_hpdsup.measurement_errors_corr.gdp_conso ...@@ -2843,6 +2766,228 @@ oo_.posterior_hpdsup.measurement_errors_corr.gdp_conso
</refentry> </refentry>
</sect1> </sect1>
<sect1><title>Forecasting</title>
<para>On a calibrated model, forecasting is done using the <xref linkend="forecast"/> command. On an estimated command, use the <xref linkend="forecast_opt"/> option of <xref linkend="estimation"/> command.</para>
<para>It is also possible to compute forecasts on a calibrated or estimated model for a given constrained path of the future endogenous variables. This is done, from the reduced form representation of the DSGE model, by finding the structural shocks that are needed to match the restricted paths. Use <xref linkend="conditional_forecast" />, <xref linkend="conditional_forecast_paths" /> and <xref linkend="plot_conditional_forecast" /> for that purpose.</para>
<refentry id="forecast">
<refmeta>
<refentrytitle>forecast</refentrytitle>
</refmeta>
<refnamediv>
<refname>forecast</refname>
<refpurpose>computes a simulation of a stochastic model from a given state</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>forecast</command>
<arg>(<replaceable>OPTION</replaceable><arg rep="repeat">, <replaceable>OPTION</replaceable></arg>)</arg>
<arg><replaceable>VARIABLE_NAME</replaceable></arg>
<arg rep="repeat"><arg>,</arg> <replaceable>VARIABLE_NAME</replaceable></arg><arg choice="plain">;</arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1><title>Options</title>
<variablelist>
<varlistentry>
<term><option>periods</option> = <replaceable>INTEGER</replaceable></term>
<listitem><para>Number of periods of the forecast. Default: <literal>40</literal></para></listitem>
</varlistentry>
<varlistentry id="conf_sig" xreflabel="conf_sig">
<term><option>conf_sig</option> = <replaceable>DOUBLE</replaceable></term>
<listitem><para>Level of significance for confidence interval. Default: <literal>0.90</literal></para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1><title>Description</title>
<para><command>forecast</command> computes a simulation of a stochastic model from an arbitrary initial point.</para>
<para>When the model also contains deterministic exogenous shocks, the simulation is computed conditionaly to the agents knowing the future values of the deterministic exogenous variables.</para>
<para><command>forecast</command> must be called after <xref linkend="stoch_simul"/>.</para>
<para><command>forecast</command> plots the trajectory of endogenous variables. When a list of variable names follows the command, only those variables are plotted. A 90% confidence interval is plotted around the mean trajectory. Use option <option>conf_sig</option> to change the level of the confidence interval.</para>
</refsect1>
<refsect1><title>Output variables</title>
<para>The following variables are set in structure <varname>oo_</varname>:
<itemizedlist spacing="compact">
<listitem><para><varname>oo_.forecast.Mean.<replaceable>VARIABLE_NAME</replaceable></varname>: mean forecast of endogenous variables</para></listitem>
<listitem><para><varname>oo_.forecast.HPDinf.<replaceable>VARIABLE_NAME</replaceable></varname>: lower bound of a confidence interval around the forecast</para></listitem>
<listitem><para><varname>oo_.forecast.HPDsup.<replaceable>VARIABLE_NAME</replaceable></varname>: upper bound of a confidence interval around the forecast</para></listitem>
<listitem><para><varname>oo_.forecast.Exogenous.<replaceable>VARIABLE_NAME</replaceable></varname>: trajectory of the deterministic exogenous variables</para></listitem>
</itemizedlist>
</para>
</refsect1>
<refsect1><title>Example</title>
<informalexample>
<programlisting>
varexo_det tau;
varexo e;
...
shocks;
var e; stderr 0.01;
var tau;
periods 1:9;
values -0.15;
end;
stoch_simul(irf=0);
forecast;
</programlisting>
</informalexample>
</refsect1>
</refentry>
<refentry id="conditional_forecast">
<refmeta>
<refentrytitle>conditional_forecast</refentrytitle>
</refmeta>
<refnamediv>
<refname>conditional_forecast</refname>
<refpurpose>computes a simulation of a stochastic model conditionally to a specified future path for some endogenous</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>conditional_forecast</command>
<arg>(<replaceable>OPTION</replaceable><arg rep="repeat">, <replaceable>OPTION</replaceable></arg>)</arg>
<arg choice="plain"><replaceable>VARIABLE_NAME</replaceable></arg>
<arg rep="repeat"><arg>,</arg> <replaceable>VARIABLE_NAME</replaceable></arg><arg choice="plain">;</arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1><title>Options</title>
<variablelist>
<varlistentry>
<term><option>parameter_set</option> = <option>calibration</option> | <option>prior_mode</option> | <option>prior_mean</option> | <option>posterior_mode</option> | <option>posterior_mean</option> | <option>posterior_median</option></term>
<listitem><para>Specify the parameter set to use for the forecasting. Use <option>calibration</option> if you calibrated your model instead of estimating it. No default value, mandatory option</para></listitem>
</varlistentry>
<varlistentry>
<term><option>controlled_varexo</option> = (<replaceable>VARIABLE_NAME</replaceable> [ [,] <replaceable>VARIABLE_NAME</replaceable> ... ] )</term>
<listitem><para>Specify the exogenous variables to use as control variables. No default value, mandatory option</para></listitem>
</varlistentry>
<varlistentry>
<term><option>periods</option> = <replaceable>INTEGER</replaceable></term>
<listitem><para>Number of periods of the forecast. Default: as many as the length of the constrained path</para></listitem>
</varlistentry>
<varlistentry>
<term><option>replic</option> = <replaceable>INTEGER</replaceable></term>
<listitem><para>Number of simulations. Default: ????</para></listitem>
</varlistentry>
<varlistentry>
<term><option>conf_sig</option> = <replaceable>DOUBLE</replaceable></term>
<listitem><para>Level of significance for confidence interval. Default: <literal>0.90</literal></para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1><title>Description</title>
<para><command>conditional_forecast</command> computes forecasts on a calibrated or estimated model for a given constrained path of some future endogenous variables. This is done, from the reduced form representation of the DSGE model, by finding the structural shocks that are needed to match the restricted paths.</para>
<para>Use <xref linkend="conditional_forecast_paths" /> to give the list of constrained endogenous, and their constrained future path. Option <option>controlled_varexo</option> is used to specify the structural shocks which will be matched to generate the constrained path.</para>
<para>Use <xref linkend="plot_conditional_forecast" /> to graph the results.</para>
</refsect1>
<refsect1><title>Example</title>
<informalexample>
<programlisting>
var y a
varexo e u;
...
stoch_simul(irf=0);
conditional_forecast_paths;
var y;
periods 1:3, 4:5;
values 2, 5;
var a;
periods 1:5;
values 3;
end;
conditional_forecast(parameter_set = calibration, controlled_varexo = (e, u), replic = 3000);
plot_conditional_forecast(periods = 10) e u;
</programlisting>
</informalexample>
</refsect1>
</refentry>
<refentry id="conditional_forecast_paths">
<refmeta>
<refentrytitle>conditional_forecast_paths</refentrytitle>
</refmeta>
<refnamediv>
<refname>conditional_forecast_paths</refname>
<refpurpose>in a conditional forecast, gives the list of constrained endogenous and their path</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>conditional_forecast_paths</command><arg choice="plain">;</arg><sbr/>
<arg rep="repeat">
<arg choice="plain">var <replaceable>VARIABLE_NAME</replaceable>;</arg>
<arg choice="plain">periods <replaceable>INTEGER</replaceable><arg>:<replaceable>INTEGER</replaceable></arg><arg rep="repeat"><arg>,</arg> <replaceable>INTEGER</replaceable><arg>:<replaceable>INTEGER</replaceable></arg></arg>;</arg>
<arg choice="plain">values <replaceable>EXPRESSION</replaceable> <arg rep="repeat"><arg>,</arg> <replaceable>EXPRESSION</replaceable></arg>;</arg>
</arg><sbr/>
<command>end</command><arg choice="plain">;</arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1><title>Description</title>
<para>Describes the path of constrained endogenous, before calling <xref linkend="conditional_forecast"/>. The syntax is similar to deterministic shocks in <xref linkend="shocks"/>, see <xref linkend="conditional_forecast"/> for an example.</para>
</refsect1>
</refentry>
<refentry id="plot_conditional_forecast">
<refmeta>
<refentrytitle>plot_conditional_forecast</refentrytitle>
</refmeta>
<refnamediv>
<refname>plot_conditional_forecast</refname>
<refpurpose>plots the conditional forecasts</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>plot_conditional_forecast</command>
<arg>(<option>periods</option> = <replaceable>INTEGER</replaceable>)</arg><arg choice="plain">;</arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1><title>Options</title>
<variablelist>
<varlistentry>
<term><option>periods</option> = <replaceable>INTEGER</replaceable></term>
<listitem><para>Number of periods to be plotted. Default: as many as the length of the forecast</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1><title>Description</title>
<para>
To be used after <xref linkend="conditional_forecast"/>.
</para>
</refsect1>
</refentry>
</sect1>
<sect1><title>Optimal policy</title> <sect1><title>Optimal policy</title>
<para>Dynare has tools to compute optimal policies for quadratic objectives. You can either solve for optimal policy under commitment with <command>planner_objective</command> or for optimal simple rule with <xref linkend='osr'/>. <para>Dynare has tools to compute optimal policies for quadratic objectives. You can either solve for optimal policy under commitment with <command>planner_objective</command> or for optimal simple rule with <xref linkend='osr'/>.
</para> </para>
......
...@@ -1016,4 +1016,27 @@ ShockDecompositionStatement::writeOutput(ostream &output, const string &basename ...@@ -1016,4 +1016,27 @@ ShockDecompositionStatement::writeOutput(ostream &output, const string &basename
output << "oo_ = shock_decomposition(M_,oo_,options_,var_list_);\n"; output << "oo_ = shock_decomposition(M_,oo_,options_,var_list_);\n";
} }
ConditionalForecastStatement::ConditionalForecastStatement(const OptionsList &options_list_arg) :
options_list(options_list_arg)
{
}
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;
}
PlotConditionalForecastStatement::PlotConditionalForecastStatement(int periods_arg, const SymbolList &symbol_list_arg) :
periods(periods_arg),
symbol_list(symbol_list_arg)
{
}
void
PlotConditionalForecastStatement::writeOutput(ostream &output, const string &basename) const
{
symbol_list.writeOutput("var_list_", output);
output << "plot_icforecast(var_list_);" << endl;
}
...@@ -470,4 +470,24 @@ public: ...@@ -470,4 +470,24 @@ public:
virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeOutput(ostream &output, const string &basename) const;
}; };
class ConditionalForecastStatement : public Statement
{
private:
const OptionsList options_list;
public:
ConditionalForecastStatement(const OptionsList &options_list_arg);
virtual void writeOutput(ostream &output, const string &basename) const;
};
class PlotConditionalForecastStatement : public Statement
{
private:
//! A value of -1 indicates that the length of the constrained path should be used
const int periods;
const SymbolList symbol_list;
public:
PlotConditionalForecastStatement(int periods_arg, const SymbolList &symbol_list_arg);
virtual void writeOutput(ostream &output, const string &basename) const;
};
#endif #endif
...@@ -92,7 +92,7 @@ class ParsingDriver; ...@@ -92,7 +92,7 @@ class ParsingDriver;
%token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA %token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA
%token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN %token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN
%token BVAR_REPLIC BYTECODE %token BVAR_REPLIC BYTECODE
%token CALIB CALIB_VAR CHANGE_TYPE CHECK CONF_SIG CONSTANT CORR COVAR CUTOFF %token CALIB CALIB_VAR CALIBRATION CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR COVAR CUTOFF
%token DATAFILE DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE %token DATAFILE DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE
%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT %token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT
%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS %token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS
...@@ -113,8 +113,8 @@ class ParsingDriver; ...@@ -113,8 +113,8 @@ class ParsingDriver;
%token NAN_CONSTANT NOBS NOCONSTANT NOCORR NODIAGNOSTIC NOFUNCTIONS %token NAN_CONSTANT NOBS NOCONSTANT NOCORR NODIAGNOSTIC NOFUNCTIONS
%token NOGRAPH NOMOMENTS NOPRINT NORMAL_PDF %token NOGRAPH NOMOMENTS NOPRINT NORMAL_PDF
%token OBSERVATION_TRENDS OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS %token OBSERVATION_TRENDS OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS
%token PARAMETERS PERIODS PLANNER_OBJECTIVE PLOT_PRIORS PREFILTER PRESAMPLE %token PARAMETERS PARAMETER_SET PERIODS PLANNER_OBJECTIVE PLOT_CONDITIONAL_FORECAST PLOT_PRIORS PREFILTER PRESAMPLE
%token PRINT PRIOR_MC PRIOR_TRUNC PRIOR_ANALYSIS POSTERIOR_ANALYSIS %token PRINT PRIOR_MC PRIOR_TRUNC PRIOR_ANALYSIS PRIOR_MODE PRIOR_MEAN POSTERIOR_ANALYSIS POSTERIOR_MODE POSTERIOR_MEAN POSTERIOR_MEDIAN
%token <string_val> QUOTED_STRING %token <string_val> QUOTED_STRING
%token QZ_CRITERIUM %token QZ_CRITERIUM
%token RELATIVE_IRF REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE %token RELATIVE_IRF REPLIC RPLOT SAVE_PARAMS_AND_STEADY_STATE
...@@ -227,6 +227,9 @@ statement : parameters ...@@ -227,6 +227,9 @@ statement : parameters
| write_latex_dynamic_model | write_latex_dynamic_model
| write_latex_static_model | write_latex_static_model
| shock_decomposition | shock_decomposition
| conditional_forecast
| conditional_forecast_paths
| plot_conditional_forecast
; ;
dsample : DSAMPLE INT_NUMBER ';' dsample : DSAMPLE INT_NUMBER ';'
...@@ -565,7 +568,7 @@ shock_list : shock_list shock_elem ...@@ -565,7 +568,7 @@ shock_list : shock_list shock_elem
; ;
shock_elem : VAR symbol ';' PERIODS period_list ';' VALUES value_list ';' shock_elem : VAR symbol ';' PERIODS period_list ';' VALUES value_list ';'
{ driver.add_det_shock($2); } { driver.add_det_shock($2, false); }
| VAR symbol ';' STDERR expression ';' | VAR symbol ';' STDERR expression ';'
{ driver.add_stderr_shock($2, $5); } { driver.add_stderr_shock($2, $5); }
| VAR symbol EQUAL expression ';' | VAR symbol EQUAL expression ';'
...@@ -1502,6 +1505,39 @@ number : INT_NUMBER ...@@ -1502,6 +1505,39 @@ number : INT_NUMBER
| FLOAT_NUMBER | FLOAT_NUMBER
; ;
conditional_forecast : CONDITIONAL_FORECAST '(' conditional_forecast_options ')' ';'
{ driver.conditional_forecast(); }
;
conditional_forecast_options : conditional_forecast_option
| conditional_forecast_options COMMA conditional_forecast_option
;
conditional_forecast_option : o_periods
| o_replic
| o_conf_sig
| o_controlled_varexo
| o_parameter_set
;
plot_conditional_forecast : PLOT_CONDITIONAL_FORECAST symbol_list ';'
{ driver.plot_conditional_forecast(); }
| PLOT_CONDITIONAL_FORECAST '(' PERIODS EQUAL INT_NUMBER ')' symbol_list ';'
{ driver.plot_conditional_forecast($5); }
;
conditional_forecast_paths : CONDITIONAL_FORECAST_PATHS ';' conditional_forecast_paths_shock_list END
{ driver.conditional_forecast_paths(); }
;
conditional_forecast_paths_shock_list : conditional_forecast_paths_shock_elem
| 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); }
;
o_dr_algo : DR_ALGO EQUAL INT_NUMBER { o_dr_algo : DR_ALGO EQUAL INT_NUMBER {
if (*$3 == string("0")) if (*$3 == string("0"))
driver.warning("dr_algo option is now deprecated, and may be removed in a future version of Dynare"); driver.warning("dr_algo option is now deprecated, and may be removed in a future version of Dynare");
...@@ -1638,6 +1674,20 @@ o_prior_mc : PRIOR_MC EQUAL INT_NUMBER { driver.option_num("prior_mc", $3); } ...@@ -1638,6 +1674,20 @@ o_prior_mc : PRIOR_MC EQUAL INT_NUMBER { driver.option_num("prior_mc", $3); }
o_homotopy_mode : HOMOTOPY_MODE EQUAL INT_NUMBER {driver.option_num("homotopy_mode",$3); }; o_homotopy_mode : HOMOTOPY_MODE EQUAL INT_NUMBER {driver.option_num("homotopy_mode",$3); };
o_homotopy_steps : HOMOTOPY_STEPS EQUAL INT_NUMBER {driver.option_num("homotopy_steps",$3); }; o_homotopy_steps : HOMOTOPY_STEPS EQUAL INT_NUMBER {driver.option_num("homotopy_steps",$3); };
o_controlled_varexo : CONTROLLED_VAREXO EQUAL '(' symbol_list ')' { driver.option_symbol_list("controlled_varexo"); };
o_parameter_set : PARAMETER_SET EQUAL PRIOR_MODE
{ driver.option_str("parameter_set", "prior_mode"); }
| PARAMETER_SET EQUAL PRIOR_MEAN
{ driver.option_str("parameter_set", "prior_mean"); }
| PARAMETER_SET EQUAL POSTERIOR_MEAN
{ driver.option_str("parameter_set", "posterior_mean"); }
| PARAMETER_SET EQUAL POSTERIOR_MODE
{ driver.option_str("parameter_set", "posterior_mode"); }
| PARAMETER_SET EQUAL POSTERIOR_MEDIAN
{ driver.option_str("parameter_set", "posterior_median"); }
| PARAMETER_SET EQUAL CALIBRATION
{ driver.option_str("parameter_set", "calibration"); }
;
o_parameters : PARAMETERS EQUAL symbol {driver.option_str("parameters",$3);}; o_parameters : PARAMETERS EQUAL symbol {driver.option_str("parameters",$3);};
o_shocks : SHOCKS EQUAL '(' list_of_symbol_lists ')' { driver.option_symbol_list("shocks"); }; o_shocks : SHOCKS EQUAL '(' list_of_symbol_lists ')' { driver.option_symbol_list("shocks"); };
......
...@@ -137,6 +137,8 @@ int sigma_e = 0; ...@@ -137,6 +137,8 @@ int sigma_e = 0;
<INITIAL>shock_decomposition {BEGIN DYNARE_STATEMENT; return token::SHOCK_DECOMPOSITION;} <INITIAL>shock_decomposition {BEGIN DYNARE_STATEMENT; return token::SHOCK_DECOMPOSITION;}
<INITIAL>sbvar {BEGIN DYNARE_STATEMENT; return token::SBVAR;} <INITIAL>sbvar {BEGIN DYNARE_STATEMENT; return token::SBVAR;}
<INITIAL>ms_sbvar {BEGIN DYNARE_STATEMENT; return token::MS_SBVAR;} <INITIAL>ms_sbvar {BEGIN DYNARE_STATEMENT; return token::MS_SBVAR;}
<INITIAL>conditional_forecast {BEGIN DYNARE_STATEMENT; return token::CONDITIONAL_FORECAST;}
<INITIAL>plot_conditional_forecast {BEGIN DYNARE_STATEMENT; return token::PLOT_CONDITIONAL_FORECAST;}
/* End of a Dynare statement */ /* End of a Dynare statement */
<DYNARE_STATEMENT>; { <DYNARE_STATEMENT>; {
...@@ -162,6 +164,7 @@ int sigma_e = 0; ...@@ -162,6 +164,7 @@ int sigma_e = 0;
<INITIAL>optim_weights {BEGIN DYNARE_BLOCK; return token::OPTIM_WEIGHTS;} <INITIAL>optim_weights {BEGIN DYNARE_BLOCK; return token::OPTIM_WEIGHTS;}
<INITIAL>calib_var {BEGIN DYNARE_BLOCK; return token::CALIB_VAR;} <INITIAL>calib_var {BEGIN DYNARE_BLOCK; return token::CALIB_VAR;}
<INITIAL>homotopy_setup {BEGIN DYNARE_BLOCK; return token::HOMOTOPY_SETUP;} <INITIAL>homotopy_setup {BEGIN DYNARE_BLOCK; return token::HOMOTOPY_SETUP;}
<INITIAL>conditional_forecast_paths {BEGIN DYNARE_BLOCK; return token::CONDITIONAL_FORECAST_PATHS;}
/* End of a Dynare block */ /* End of a Dynare block */
<DYNARE_BLOCK>end[ \t\n]*; {BEGIN INITIAL; return token::END;} <DYNARE_BLOCK>end[ \t\n]*; {BEGIN INITIAL; return token::END;}
...@@ -323,6 +326,16 @@ int sigma_e = 0; ...@@ -323,6 +326,16 @@ int sigma_e = 0;
<DYNARE_STATEMENT>homotopy_mode {return token::HOMOTOPY_MODE; } <DYNARE_STATEMENT>homotopy_mode {return token::HOMOTOPY_MODE; }
<DYNARE_STATEMENT>homotopy_steps {return token::HOMOTOPY_STEPS; } <DYNARE_STATEMENT>homotopy_steps {return token::HOMOTOPY_STEPS; }
<DYNARE_STATEMENT>controlled_varexo {return token::CONTROLLED_VAREXO; }
<DYNARE_STATEMENT>parameter_set {return token::PARAMETER_SET; }
<DYNARE_STATEMENT>prior_mode {return token::PRIOR_MODE; }
<DYNARE_STATEMENT>prior_mean {return token::PRIOR_MEAN; }
<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>calibration {return token::CALIBRATION; }
<DYNARE_STATEMENT>[\$][^$]*[\$] { <DYNARE_STATEMENT>[\$][^$]*[\$] {
strtok(yytext+1, "$"); strtok(yytext+1, "$");
yylval->string_val = new string(yytext + 1); yylval->string_val = new string(yytext + 1);
......
...@@ -429,18 +429,27 @@ ParsingDriver::end_mshocks() ...@@ -429,18 +429,27 @@ ParsingDriver::end_mshocks()
} }
void void
ParsingDriver::add_det_shock(string *var) ParsingDriver::add_det_shock(string *var, bool conditional_forecast)
{ {
check_symbol_existence(*var); check_symbol_existence(*var);
SymbolType type = mod_file->symbol_table.getType(*var); SymbolType type = mod_file->symbol_table.getType(*var);
if (type != eExogenous && type != eExogenousDet)
error("shocks: shocks can only be applied to exogenous variables"); if (conditional_forecast)
{
if (type != eEndogenous)
error("conditional_forecast_paths: shocks can only be applied to exogenous variables");
}
else
{
if (type != eExogenous && type != eExogenousDet)
error("shocks: shocks can only be applied to exogenous variables");
}
if (det_shocks.find(*var) != det_shocks.end()) if (det_shocks.find(*var) != det_shocks.end())
error("shocks: variable " + *var + " declared twice"); error("shocks/conditional_forecast_paths: variable " + *var + " declared twice");
if (det_shocks_periods.size() != det_shocks_values.size()) if (det_shocks_periods.size() != det_shocks_values.size())
error("shocks: variable " + *var + ": number of periods is different from number of shock values"); error("shocks/conditional_forecast_paths: variable " + *var + ": number of periods is different from number of shock values");
vector<ShocksStatement::DetShockElement> v; vector<ShocksStatement::DetShockElement> v;
...@@ -533,6 +542,8 @@ ParsingDriver::add_period(string *p1, string *p2) ...@@ -533,6 +542,8 @@ ParsingDriver::add_period(string *p1, string *p2)
{ {
int p1_val = atoi(p1->c_str()); int p1_val = atoi(p1->c_str());
int p2_val = atoi(p2->c_str()); int p2_val = atoi(p2->c_str());
if (p1_val > p2_val)