From 865dcb57f8709b82a342c6447b750dd6f8de9829 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 31 Mar 2011 16:33:47 +0200 Subject: [PATCH] IRF: add an option to limit the exogenous shocked in the computations (ticket 114) --- doc/dynare.texi | 4 ++++ matlab/PosteriorIRF_core1.m | 3 ++- matlab/getIrfShocksIndx.m | 29 +++++++++++++++++++++++++++++ matlab/stoch_simul.m | 3 ++- matlab/stoch_simul_sparse.m | 3 ++- preprocessor/DynareBison.yy | 4 +++- preprocessor/DynareFlex.ll | 1 + preprocessor/ParsingDriver.cc | 9 +++++++++ 8 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 matlab/getIrfShocksIndx.m diff --git a/doc/dynare.texi b/doc/dynare.texi index d3f264809..92232f7bf 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -2782,6 +2782,10 @@ increase it for highly autocorrelated processes. Default: @code{512}. Number of periods on which to compute the IRFs. Setting @code{irf=0}, suppresses the plotting of IRF's. Default: @code{40}. +@item irf_shocks = ( @var{VARIABLE_NAME} [@var{VARIABLE_NAME} @dots{}] ) +@anchor{irf_shocks} +The exogenous variables for which to compute IRFs. Default: all. + @item relative_irf Requests the computation of normalized IRFs in percentage of the standard error of each shock. diff --git a/matlab/PosteriorIRF_core1.m b/matlab/PosteriorIRF_core1.m index c0d7e63f8..b1c15f596 100644 --- a/matlab/PosteriorIRF_core1.m +++ b/matlab/PosteriorIRF_core1.m @@ -161,7 +161,8 @@ while fpar 1e-13 y=irf(dr,SS(M_.exo_names_orig_ord,i), options_.irf, options_.drop,options_.replic,options_.order); if options_.relative_irf diff --git a/matlab/getIrfShocksIndx.m b/matlab/getIrfShocksIndx.m new file mode 100644 index 000000000..0974bcedc --- /dev/null +++ b/matlab/getIrfShocksIndx.m @@ -0,0 +1,29 @@ +function irf_shocks_indx=getIrfShocksIndx() + +% Copyright (C) 2011 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 . + +global M_ options_ + +if (isfield(options_,'irf_shocks')==0) + irf_shocks_indx = M_.exo_names_orig_ord; +else + irf_shocks_indx = zeros(1,size(options_.irf_shocks,1)); + for i=1:size(options_.irf_shocks,1) + irf_shocks_indx(i) = find(M_.exo_names==options_.irf_shocks(i)); + end +end \ No newline at end of file diff --git a/matlab/stoch_simul.m b/matlab/stoch_simul.m index 6e9a58d6a..6938107e5 100644 --- a/matlab/stoch_simul.m +++ b/matlab/stoch_simul.m @@ -159,7 +159,8 @@ if options_.irf if TeX titTeX(M_.exo_names_orig_ord,:) = M_.exo_names_tex; end - for i=1:M_.exo_nbr + irf_shocks_indx = getIrfShocksIndx(); + for i=irf_shocks_indx if SS(i,i) > 1e-13 if PI_PCL_solver y=PCL_Part_info_irf (0, PCL_varobs, i_var, M_, oo_.dr, options_.irf, i); diff --git a/matlab/stoch_simul_sparse.m b/matlab/stoch_simul_sparse.m index 1f3307f7e..eefad2ba8 100644 --- a/matlab/stoch_simul_sparse.m +++ b/matlab/stoch_simul_sparse.m @@ -132,7 +132,8 @@ if options_.irf if TeX titTeX(M_.exo_names_orig_ord,:) = M_.exo_names_tex; end - for i=1:M_.exo_nbr + irf_shocks_indx = getIrfShocksIndx(); + for i=irf_shocks_indx if SS(i,i) > 1e-13 y=irf(oo_.dr,cs(M_.exo_names_orig_ord,i), options_.irf, options_.drop, ... options_.replic, options_.order); diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 05128b703..f35184527 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -103,7 +103,7 @@ class ParsingDriver; %token HISTVAL HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS HP_FILTER HP_NGRID %token IDENTIFICATION INF_CONSTANT INITVAL INITVAL_FILE %token INT_NUMBER -%token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF +%token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS %token KALMAN_ALGO KALMAN_TOL %token LABELS LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR %token MARKOWITZ MARGINAL_DENSITY MAX @@ -858,6 +858,7 @@ stoch_simul_options : o_dr_algo | o_nomoments | o_nograph | o_irf + | o_irf_shocks | o_relative_irf | o_hp_filter | o_hp_ngrid @@ -1689,6 +1690,7 @@ o_nocorr : NOCORR { driver.option_num("nocorr", "1"); }; o_nofunctions : NOFUNCTIONS { driver.option_num("nofunctions", "1"); }; o_nomoments : NOMOMENTS { driver.option_num("nomoments", "1"); }; o_irf : IRF EQUAL INT_NUMBER { driver.option_num("irf", $3); }; +o_irf_shocks : IRF_SHOCKS EQUAL '(' symbol_list ')' { driver.option_symbol_list("irf_shocks"); }; o_hp_filter : HP_FILTER EQUAL INT_NUMBER { driver.option_num("hp_filter", $3); }; o_hp_ngrid : HP_NGRID EQUAL INT_NUMBER { driver.option_num("hp_ngrid", $3); }; o_periods : PERIODS EQUAL INT_NUMBER { driver.option_num("periods", $3); }; diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index 1927bb50f..0f15b24b4 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -404,6 +404,7 @@ string eofbuff; ar {return token::AR;} nofunctions {return token::NOFUNCTIONS;} irf {return token::IRF;} +irf_shocks {return token::IRF_SHOCKS;} hp_filter {return token::HP_FILTER;} hp_ngrid {return token::HP_NGRID;} simul_seed {return token::SIMUL_SEED;} diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index 907d0b88c..088a636a7 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -925,6 +925,15 @@ ParsingDriver::option_symbol_list(const string &name_option) != options_list.symbol_list_options.end()) error("option " + name_option + " declared twice"); + if (name_option.compare("irf_shocks")==0) + { + vector shocks = symbol_list.get_symbols(); + for (vector::const_iterator it = shocks.begin(); + it != shocks.end(); it++) + if (mod_file->symbol_table.getType(*it) != eExogenous) + error("Variables passed to irf_for must be exogenous. Caused by: " + *it); + } + options_list.symbol_list_options[name_option] = symbol_list; symbol_list.clear(); }