From 281f01f29e88e7f8f8f4c9331d26cf1ea071843e Mon Sep 17 00:00:00 2001 From: Marco Ratto <marco.ratto@ec.europa.eu> Date: Thu, 14 Dec 2023 22:26:40 +0100 Subject: [PATCH] bug fixes and examples in testsuite --- matlab/+occbin/forecast.m | 5 +-- matlab/+occbin/irf.m | 10 +++--- matlab/+occbin/plot_irfs.m | 2 +- tests/occbin/filter/NKM.mod | 35 +++++++++++++++++++ .../dynrbc_common.inc | 2 ++ 5 files changed, 46 insertions(+), 8 deletions(-) diff --git a/matlab/+occbin/forecast.m b/matlab/+occbin/forecast.m index aa1cde63b0..56cc1999fd 100644 --- a/matlab/+occbin/forecast.m +++ b/matlab/+occbin/forecast.m @@ -56,7 +56,7 @@ if opts.replic options_.occbin.simul.exo_pos=ishock; options_.occbin.simul.SHOCKS = SHOCKS; options_.occbin.simul.waitbar=0; - [~, out] = occbin.solver(M_,oo_,options_); + [~, out] = occbin.solver(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state); zlin0(:,:,iter)=out.linear; zpiece0(:,:,iter)=out.piecewise; ys=out.ys; @@ -124,7 +124,8 @@ else options_.occbin.simul.init_violvecbool = []; options_.occbin.simul.irfshock = M_.exo_names; options_.occbin.simul.SHOCKS = SHOCKS; - [~, out] = occbin.solver(M_,oo_,options_); + [~, out] = occbin.solver(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state); + zlin=out.linear; zpiece=out.piecewise; frcst_regime_history=out.regime_history; diff --git a/matlab/+occbin/irf.m b/matlab/+occbin/irf.m index 70ad560d7c..a94b42b9d9 100644 --- a/matlab/+occbin/irf.m +++ b/matlab/+occbin/irf.m @@ -20,7 +20,7 @@ else options_.occbin.simul.endo_init = oo_.occbin.smoother.alphahat(oo_.dr.inv_order_var,t0); end options_.occbin.simul.SHOCKS=shocks0; -[~, out0] = occbin.solver(M_,oo_,options_); +[~, out0] = occbin.solver(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state); zlin0 = out0.linear; zpiece0 = out0.piecewise; @@ -61,11 +61,11 @@ for counter = 1:length(jexo_all) if t0 == 0 options_.occbin.simul.SHOCKS=shocks1; options_.occbin.simul.endo_init = []; - [~, out_pos] = occbin.solver(M_,oo_,options_); + [~, out_pos] = occbin.solver(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state); else options_.occbin.simul.SHOCKS=shocks1; options_.occbin.simul.endo_init = oo_.occbin.smoother.alphahat(oo_.dr.inv_order_var,t0); - [~, out_pos] = occbin.solver(M_,oo_,options_); + [~, out_pos] = occbin.solver(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state); end if out_pos.error_flag warning('Occbin error.') @@ -85,11 +85,11 @@ for counter = 1:length(jexo_all) if t0 == 0 options_.occbin.simul.SHOCKS=shocks_1; options_.occbin.simul.endo_init = []; - [~, out_neg] = occbin.solver(M_,oo_,options_); + [~, out_neg] = occbin.solver(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state); else options_.occbin.simul.SHOCKS=shocks_1; options_.occbin.simul.endo_init = oo_.occbin.smoother.alphahat(oo_.dr.inv_order_var,t0); - [~, out_neg] = occbin.solver(M_,oo_,options_); + [~, out_neg] = occbin.solver(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state); end if out_neg.error_flag warning('Occbin error.') diff --git a/matlab/+occbin/plot_irfs.m b/matlab/+occbin/plot_irfs.m index 48489b0f3a..efe9285478 100644 --- a/matlab/+occbin/plot_irfs.m +++ b/matlab/+occbin/plot_irfs.m @@ -66,7 +66,7 @@ for sss = 1:numel(shocksigns) j1=j1+1; if mod(j1,npan)==1 % vector corresponds to [left bottom width height]. 680 and 678 for the left and bottom elements correspond to the default values used by MATLAB while creating a figure and width, . - hfig = dyn_figure(options_.nodisplay,'name',['OccbinIRFs ' shocknames{j} ' ' simulname],'PaperPositionMode', 'auto','PaperType','A4','PaperOrientation','portrait','renderermode','auto','position',[10 10 950 650]); + hfig = dyn_figure(options_.nodisplay,'name',['OccbinIRFs ' shocknames{j} ' ' simulname ' ' shocksign],'PaperPositionMode', 'auto','PaperType','A4','PaperOrientation','portrait','renderermode','auto','position',[10 10 950 650]); ifig=ifig+1; isub=0; end diff --git a/tests/occbin/filter/NKM.mod b/tests/occbin/filter/NKM.mod index 81b25d1d7e..7bc3309032 100644 --- a/tests/occbin/filter/NKM.mod +++ b/tests/occbin/filter/NKM.mod @@ -311,6 +311,41 @@ varobs yg inom pi; mh_replic=0, plot_priors=0, smoother, nodisplay,consider_all_endogenous,heteroskedastic_filter,filter_step_ahead=[1],smoothed_state_uncertainty); + // plot regimes + occbin.plot_regimes(oo_.occbin.smoother.regime_history,M_,options_) + + // forecast starting from period 42, zero shocks (default) + smoother2histval(period=42); + [oo, error_flag] = occbin.forecast(options_,M_,oo_,8); + // forecast with stochastic shocks + options_.occbin.forecast.qmc=true; + options_.occbin.forecast.replic=127; + [oo1, error_flag] = occbin.forecast(options_,M_,oo_,8); + + // GIRF given states in 42 and shocks in 43 + t0=42; + options_.occbin.irf.exo_names=M_.exo_names; + options_.occbin.irf.t0=t0; + oo_ = occbin.irf(M_,oo_,options_); + + vars_irf = { + 'c', 'consumption' + 'n', 'labor' + 'y', 'output' + 'pigap', 'inflation rate' + 'inom', 'interest rate' + 'inomnot', 'shadow rate' + }; + + options_.occbin.plot_irf.exo_names = M_.exo_names; + options_.occbin.plot_irf.endo_names = vars_irf(:,1); + options_.occbin.plot_irf.endo_names_long = vars_irf(:,2); + // if you want to scale ... + // options_occbin_.plot_irf.endo_scaling_factor = vars_irf(:,3); + options_.occbin.plot_irf.simulname = ['t0_' int2str(t0)]; + options_.occbin.plot_irf.tplot = min(40,options_.irf); + occbin.plot_irfs(M_,oo_,options_); + oo0=oo_; // use smoother_redux estimation( diff --git a/tests/occbin/model_irrcap_twoconstraints/dynrbc_common.inc b/tests/occbin/model_irrcap_twoconstraints/dynrbc_common.inc index 9f504605ef..d006a785da 100644 --- a/tests/occbin/model_irrcap_twoconstraints/dynrbc_common.inc +++ b/tests/occbin/model_irrcap_twoconstraints/dynrbc_common.inc @@ -109,5 +109,7 @@ occbin_graph(noconstant) c erra lambdak k i a k; line1=100*[oo_.occbin.endo_piecewise.c-oo_.occbin.endo_ss.c,oo_.occbin.endo_piecewise.lambdak/100,oo_.occbin.endo_piecewise.k-oo_.occbin.endo_ss.k,oo_.occbin.endo_piecewise.i-oo_.occbin.endo_ss.i,oo_.occbin.endo_piecewise.a-oo_.occbin.endo_ss.a, shock_vector]; line2=100*[oo_.occbin.linear_smoother.SmoothedVariables.c-oo_.occbin.endo_ss.c,oo_.occbin.linear_smoother.SmoothedVariables.lambdak/100,oo_.occbin.linear_smoother.SmoothedVariables.k-oo_.occbin.endo_ss.k,oo_.occbin.linear_smoother.SmoothedVariables.i-oo_.occbin.endo_ss.i,oo_.occbin.linear_smoother.SmoothedVariables.a-oo_.occbin.endo_ss.a, oo_.occbin.linear_smoother.SmoothedShocks.erra/100]; occbin.make_chart(titlelist,legendlist,figtitle,ylabels,cat(3,line1,line2)); + + occbin.plot_regimes(oo_.occbin.smoother.regime_history,M_,options_) @#endif @#endfor -- GitLab