diff --git a/matlab/initial_condition_decomposition.m b/matlab/initial_condition_decomposition.m index df9e4e93ae59ab753fdc85d6c403664b51b73cdf..1eb2b795982cb21fce950259e1f1c62989990f01 100644 --- a/matlab/initial_condition_decomposition.m +++ b/matlab/initial_condition_decomposition.m @@ -38,6 +38,13 @@ function oo_ = initial_condition_decomposition(M_,oo_,options_,varlist,bayestopt % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. +options_.plot_shock_decomp.detail_plot = options_.initial_condition_decomp.detail_plot; +options_.plot_shock_decomp.steadystate = options_.initial_condition_decomp.steadystate; +options_.plot_shock_decomp.write_xls = options_.initial_condition_decomp.write_xls; +options_.plot_shock_decomp.type = options_.initial_condition_decomp.type; +options_.plot_shock_decomp.plot_init_date = options_.initial_condition_decomp.plot_init_date; +options_.plot_shock_decomp.plot_end_date = options_.initial_condition_decomp.plot_end_date; + % indices of endogenous variables if size(varlist,1) == 0 varlist = M_.endo_names(1:M_.orig_endo_nbr,:); diff --git a/matlab/set_default_initial_condition_decomposition_options.m b/matlab/set_default_initial_condition_decomposition_options.m new file mode 100644 index 0000000000000000000000000000000000000000..07c84d3e6b16bb0af8b67bf48743ffa8bea603b4 --- /dev/null +++ b/matlab/set_default_initial_condition_decomposition_options.m @@ -0,0 +1,37 @@ +function options = set_default_initial_condition_decomposition_options(options) +%function options = set_default_initial_condition_decomposition_options(options) +% sets the default options for prior_shock_decomposition +% +% INPUTS +% options +% +% OUTPUTS +% options +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 2017 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/>. + +options.initial_condition_decomp.detail_plot = 0; +options.initial_condition_decomp.steadystate = 0; +options.initial_condition_decomp.write_xls = 0; +options.initial_condition_decomp.type = ''; +options.initial_condition_decomp.plot_init_date = []; +options.initial_condition_decomp.plot_end_date = []; +end diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index d91d04c106359bbb8c2d8607541b9dac4ad44c99..21b2dd7553863f114b30d657b84771a5011996c9 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -1696,6 +1696,22 @@ PlotShockDecompositionStatement::writeOutput(ostream &output, const string &base output << "plot_shock_decomposition(M_, oo_, options_, var_list_);" << endl; } +InitialConditionDecompositionStatement::InitialConditionDecompositionStatement(const SymbolList &symbol_list_arg, + const OptionsList &options_list_arg) : + symbol_list(symbol_list_arg), + options_list(options_list_arg) +{ +} + +void +InitialConditionDecompositionStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const +{ + output << "options_ = set_default_initial_condition_decomposition_options(options_);" << endl; + options_list.writeOutput(output); + symbol_list.writeOutput("var_list_", output); + output << "initial_condition_decomposition(M_, oo_, options_, var_list_, bayestopt_, estim_params_);" << endl; +} + ConditionalForecastStatement::ConditionalForecastStatement(const OptionsList &options_list_arg) : options_list(options_list_arg) { diff --git a/preprocessor/ComputingTasks.hh b/preprocessor/ComputingTasks.hh index 41da6098233034ea532cbfc16f7406fc2a4003d9..596738c27cbd4f98b6dd0aa83b5c7ea3a521177a 100644 --- a/preprocessor/ComputingTasks.hh +++ b/preprocessor/ComputingTasks.hh @@ -608,6 +608,17 @@ public: virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; +class InitialConditionDecompositionStatement : public Statement +{ +private: + const SymbolList symbol_list; + const OptionsList options_list; +public: + InitialConditionDecompositionStatement(const SymbolList &symbol_list_arg, + const OptionsList &options_list_arg); + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; +}; + class ConditionalForecastStatement : public Statement { private: diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 10361cdb95f9f5fffd822407c1e98bbf5165c35a..6eea69bc8dd9c901d9c7c5ea1fede336aa338249 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -91,7 +91,7 @@ class ParsingDriver; %token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN DETAIL_PLOT TYPE %token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED PROPOSAL_DISTRIBUTION REALTIME VINTAGE %token CALIB_SMOOTHER CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR COVAR CUTOFF CYCLE_REDUCTION LOGARITHMIC_REDUCTION -%token CONSIDER_ALL_ENDOGENOUS CONSIDER_ONLY_OBSERVED +%token CONSIDER_ALL_ENDOGENOUS CONSIDER_ONLY_OBSERVED INITIAL_CONDITION_DECOMPOSITION %token DATAFILE FILE SERIES DOUBLING DR_CYCLE_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_MAXITER DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION DIFFERENTIATE_FORWARD_VARS %token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT EXTENDED_PATH ENDOGENOUS_PRIOR %token FILENAME DIRNAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS LAST_OBS SET_TIME OSR_PARAMS_BOUNDS KEEP_KALMAN_ALGO_IF_SINGULARITY_IS_DETECTED @@ -103,7 +103,7 @@ class ParsingDriver; %token IDENTIFICATION INF_CONSTANT INITVAL INITVAL_FILE BOUNDS JSCALE INIT INFILE INVARS %token <string_val> INT_NUMBER %token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS IRF_PLOT_THRESHOLD IRF_CALIBRATION -%token FAST_KALMAN_FILTER KALMAN_ALGO KALMAN_TOL DIFFUSE_KALMAN_TOL SUBSAMPLES OPTIONS TOLF TOLX +%token FAST_KALMAN_FILTER KALMAN_ALGO KALMAN_TOL DIFFUSE_KALMAN_TOL SUBSAMPLES OPTIONS TOLF TOLX PLOT_INIT_DATE PLOT_END_DATE %token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_RESULTS_AFTER_LOAD_MH LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LOGDATA LYAPUNOV LINEAR_APPROXIMATION %token LYAPUNOV_FIXED_POINT_TOL LYAPUNOV_DOUBLING_TOL LYAPUNOV_SQUARE_ROOT_SOLVER_TOL LOG_DEFLATOR LOG_TREND_VAR LOG_GROWTH_FACTOR MARKOWITZ MARGINAL_DENSITY MAX MAXIT %token MFS MH_CONF_SIG MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER POSTERIOR_MAX_SUBSAMPLE_DRAWS MIN MINIMAL_SOLVING_PERIODS @@ -263,6 +263,7 @@ statement : parameters | shock_decomposition | realtime_shock_decomposition | plot_shock_decomposition + | initial_condition_decomposition | conditional_forecast | conditional_forecast_paths | plot_conditional_forecast @@ -2150,6 +2151,16 @@ plot_shock_decomposition : PLOT_SHOCK_DECOMPOSITION ';' { driver.plot_shock_decomposition(); } ; +initial_condition_decomposition : INITIAL_CONDITION_DECOMPOSITION ';' + {driver.initial_condition_decomposition(); } + | INITIAL_CONDITION_DECOMPOSITION '(' initial_condition_decomposition_options_list ')' ';' + { driver.initial_condition_decomposition(); } + | INITIAL_CONDITION_DECOMPOSITION symbol_list ';' + { driver.initial_condition_decomposition(); } + | INITIAL_CONDITION_DECOMPOSITION '(' initial_condition_decomposition_options_list ')' symbol_list ';' + { driver.initial_condition_decomposition(); } + ; + bvar_prior_option : o_bvar_prior_tau | o_bvar_prior_decay | o_bvar_prior_lambda @@ -2554,6 +2565,18 @@ plot_shock_decomposition_option : o_psd_use_shock_groups | o_psd_vintage ; +initial_condition_decomposition_options_list : initial_condition_decomposition_option COMMA initial_condition_decomposition_options_list + | initial_condition_decomposition_option + ; + +initial_condition_decomposition_option : o_icd_type + | o_icd_detail_plot + | o_icd_steadystate + | o_icd_write_xls + | o_icd_plot_init_date + | o_icd_plot_end_date + ; + homotopy_setup: HOMOTOPY_SETUP ';' homotopy_list END ';' { driver.end_homotopy();}; @@ -3012,9 +3035,11 @@ o_dr_cycle_reduction_tol : DR_CYCLE_REDUCTION_TOL EQUAL non_negative_number {dri o_dr_logarithmic_reduction_tol : DR_LOGARITHMIC_REDUCTION_TOL EQUAL non_negative_number {driver.option_num("dr_logarithmic_reduction_tol",$3);}; o_dr_logarithmic_reduction_maxiter : DR_LOGARITHMIC_REDUCTION_MAXITER EQUAL INT_NUMBER {driver.option_num("dr_logarithmic_reduction_maxiter",$3);}; o_psd_detail_plot : DETAIL_PLOT { driver.option_num("plot_shock_decomp.detail_plot", "1"); }; +o_icd_detail_plot : DETAIL_PLOT { driver.option_num("initial_condition_decomp.detail_plot", "1"); }; o_psd_interactive : INTERACTIVE { driver.option_num("plot_shock_decomp.interactive", "1"); }; o_psd_screen_shocks : SCREEN_SHOCKS { driver.option_num("plot_shock_decomp.screen_shocks", "1"); }; o_psd_steadystate : STEADYSTATE { driver.option_num("plot_shock_decomp.steadystate", "1"); }; +o_icd_steadystate : STEADYSTATE { driver.option_num("initial_condition_decomp.steadystate", "1"); }; o_psd_fig_name : FIG_NAME EQUAL filename { driver.option_str("plot_shock_decomp.fig_name", $3); }; o_psd_type : TYPE EQUAL QOQ { driver.option_str("plot_shock_decomp.type", "qoq"); } @@ -3023,6 +3048,16 @@ o_psd_type : TYPE EQUAL QOQ | TYPE EQUAL AOA { driver.option_str("plot_shock_decomp.type", "qoq"); } ; +o_icd_type : TYPE EQUAL QOQ + { driver.option_str("initial_condition_decomp.type", "qoq"); } + | TYPE EQUAL YOY + { driver.option_str("initial_condition_decomp.type", "qoq"); } + | TYPE EQUAL AOA + { driver.option_str("initial_condition_decomp.type", "qoq"); } + ; +o_icd_plot_init_date : PLOT_INIT_DATE EQUAL date_expr { driver.option_date("initial_condition_decomp.plot_init_date", $3); } ; +o_icd_plot_end_date : PLOT_END_DATE EQUAL date_expr { driver.option_date("initial_condition_decomp.plot_end_date", $3); } ; +o_icd_write_xls : WRITE_XLS { driver.option_num("initial_condition_decomp.write_xls", "1"); }; o_psd_write_xls : WRITE_XLS { driver.option_num("plot_shock_decomp.write_xls", "1"); }; o_psd_realtime : REALTIME EQUAL INT_NUMBER { driver.option_num("plot_shock_decomp.realtime", $3); }; o_psd_vintage : VINTAGE EQUAL INT_NUMBER { driver.option_num("plot_shock_decomp.vintage", $3); }; diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index 59eac989a97f541b55cd1564bae18410f18b9408..299d31eddaccf8af091a53cde112e86973cd8aef 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -152,6 +152,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>shock_decomposition {BEGIN DYNARE_STATEMENT; return token::SHOCK_DECOMPOSITION;} <INITIAL>realtime_shock_decomposition {BEGIN DYNARE_STATEMENT; return token::REALTIME_SHOCK_DECOMPOSITION;} <INITIAL>plot_shock_decomposition {BEGIN DYNARE_STATEMENT; return token::PLOT_SHOCK_DECOMPOSITION;} +<INITIAL>initial_condition_decomposition {BEGIN DYNARE_STATEMENT; return token::INITIAL_CONDITION_DECOMPOSITION;} <INITIAL>sbvar {BEGIN DYNARE_STATEMENT; return token::SBVAR;} <INITIAL>ms_estimation {BEGIN DYNARE_STATEMENT; return token::MS_ESTIMATION;} <INITIAL>ms_simulation {BEGIN DYNARE_STATEMENT; return token::MS_SIMULATION;} @@ -375,6 +376,8 @@ 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>indxscalesstates {return token::INDXSCALESSTATES;} <DYNARE_STATEMENT>fixed_point {return token::FIXED_POINT;} <DYNARE_STATEMENT>doubling {return token::DOUBLING;} +<DYNARE_STATEMENT>plot_init_date {return token::PLOT_INIT_DATE;} +<DYNARE_STATEMENT>plot_end_date {return token::PLOT_END_DATE;} <DYNARE_STATEMENT>square_root_solver {return token::SQUARE_ROOT_SOLVER;} <DYNARE_STATEMENT>cycle_reduction {return token::CYCLE_REDUCTION;} <DYNARE_STATEMENT>logarithmic_reduction {return token::LOGARITHMIC_REDUCTION;} diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index d370979e98dde0614895b647dd9a3204455066c2..c0f4729164487a325df2761971d419032ce76b90 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -2141,6 +2141,14 @@ ParsingDriver::plot_shock_decomposition() options_list.clear(); } +void +ParsingDriver::initial_condition_decomposition() +{ + mod_file->addStatement(new InitialConditionDecompositionStatement(symbol_list, options_list)); + symbol_list.clear(); + options_list.clear(); +} + void ParsingDriver::conditional_forecast() { diff --git a/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh index 29b9c3210293f5e9ce5930f192e4a91455858395..bc9729fff47dbba5dae1df6bc9294f87ef500262 100644 --- a/preprocessor/ParsingDriver.hh +++ b/preprocessor/ParsingDriver.hh @@ -594,6 +594,8 @@ public: void realtime_shock_decomposition(); //! Plot Shock decomposition void plot_shock_decomposition(); + //! Initial Condition decomposition + void initial_condition_decomposition(); //! Conditional forecast statement void conditional_forecast(); //! Conditional forecast paths block