diff --git a/doc/manual/source/the-model-file.rst b/doc/manual/source/the-model-file.rst index 5bcf15e52f59bad48a689b30db728d114b1f0499..6a3ee4312e0f24298110d404f75c079200aab6f3 100644 --- a/doc/manual/source/the-model-file.rst +++ b/doc/manual/source/the-model-file.rst @@ -5024,37 +5024,39 @@ All of these elements are discussed in the following. The command outputs various objects into ``oo_.occbin``. -.. matvar:: oo_.occbin.piecewise +.. matvar:: oo_.occbin.simul.piecewise |br| Matrix storing the simulations based on the piecewise-linear solution. The variables are arranged column by column, in order of declaration (as in ``M_.endo_names``), while the the rows correspond to the ``simul_periods``. -.. matvar:: oo_.occbin.linear +.. matvar:: oo_.occbin.simul.linear |br| Matrix storing the simulations based on the linear solution, i.e. ignoring the occasionally binding constraint(s). The variables are arranged column by column, in order of declaration (as in ``M_.endo_names``), while the the rows correspond to the ``simul_periods``. -.. matvar:: oo_.occbin.shocks_sequence +.. matvar:: oo_.occbin.simul.shocks_sequence |br| Matrix storing the shock sequence employed during the simulation. The shocks are arranged column by column, with their order in ``M_.exo_names`` stored in ``oo_.occbin.exo_pos``. The the rows correspond to the number of shock periods specified in a `surprise(shocks)`-block, which may be smaller than ``simul_periods``. -.. matvar:: oo_.occbin.regime_history +.. matvar:: oo_.occbin.simul.regime_history |br| Structure storing information on the regime history, conditional on the shock that - happened in the respective period (stored along the rows). The subfield ``regime`` contains + happened in the respective period (stored along the rows). ``type`` is equal to either ``smoother`` + or ``simul``, depending on whether the output comes from a run of simulations or the smoother. + The subfield ``regime`` contains a vector storing the regime state, while the the subfield ``regimestart`` indicates the expected start of the respective regime state. For example, if row 40 contains ``[1,0]`` for ``regime2`` and ``[1,6]`` for ``regimestart2``, it indicates that - after the shock in period 40 - has occurred - the second constraint became binding (1) and is expected to revert to non-binding (0) six periods - later. + has occurred - the second constraint became binding (1) and is expected to revert to non-binding (0) after + six periods including the current one, i.e. period 45. -.. matvar:: oo_.occbin.ys +.. matvar:: oo_.occbin.simul.ys |br| Vector of steady state values @@ -5073,8 +5075,8 @@ All of these elements are discussed in the following. .. command:: occbin_write_regimes ; occbin_write_regimes (OPTIONS...); - |br| Write the information on the regime history stored in ``oo_.occbin.regime_history`` - into an Excel file stored in the ``FILENAME/Output``-folder. + |br| Write the information on the regime history stored in ``oo_.occbin.simul.regime_history`` + or ````oo_.occbin.smoother.regime_history`` into an Excel file stored in the ``FILENAME/Output``-folder. *Options* @@ -5087,6 +5089,13 @@ All of these elements are discussed in the following. Name of the Excel-file to write. Default: ``FILENAME_occbin_regimes``. + .. option:: simul + + Selects the regime history from the last run of simulations. Default: enabled. + + .. option:: smoother + + Selects the regime history from the last run of the smoother. Default: use ``simul``. .. _estim: diff --git a/matlab/+occbin/graph.m b/matlab/+occbin/graph.m index d2a96e9ef4c016e86692e699464999fb5488fda9..7595272aa0412c61bdb471cbf285e718d43b2769 100644 --- a/matlab/+occbin/graph.m +++ b/matlab/+occbin/graph.m @@ -42,9 +42,9 @@ end var_list_plots=var_list(index_uniques); var_list_TeX = M_.endo_names_tex(i_var); -data_to_plot(:,:,1)=oo_.occbin.piecewise(:,i_var); -if isfield(oo_.occbin,'linear') - data_to_plot(:,:,2)=oo_.occbin.linear(:,i_var); +data_to_plot(:,:,1)=oo_.occbin.simul.piecewise(:,i_var); +if isfield(oo_.occbin,'simul') && isfield(oo_.occbin.simul,'linear') + data_to_plot(:,:,2)=oo_.occbin.simul.linear(:,i_var); legend_list = {'Piecewise Linear','Linear'}; else legend_list = {'Piecewise Linear'}; @@ -54,7 +54,7 @@ nperiods=size(data_to_plot,1); ndim=size(data_to_plot,3); if ~options_.occbin.graph.steady_state - data_to_plot=data_to_plot-repmat(oo_.occbin.ys(i_var)',nperiods,1,ndim); + data_to_plot=data_to_plot-repmat(oo_.occbin.simul.ys(i_var)',nperiods,1,ndim); end %get exogenous variables @@ -65,14 +65,14 @@ var_list_TeX = [var_list_TeX; M_.exo_names_tex(i_var_exo)]; if number_of_plots_to_draw_exo>0 exo_index=NaN(number_of_plots_to_draw_exo); for ii=1:length(i_var_exo) - temp_index=find(oo_.occbin.exo_pos==i_var_exo(ii)); + temp_index=find(oo_.occbin.simul.exo_pos==i_var_exo(ii)); if ~isempty(temp_index) exo_index(ii)=temp_index; else error('%s was not part of the shocks for Occbin.', var_list{i_var_exo(ii)}); end end - data_to_plot(:,end+1:end+number_of_plots_to_draw_exo,1)=[oo_.occbin.shocks_sequence(:,exo_index); zeros(nperiods-size(oo_.occbin.shocks_sequence,1),number_of_plots_to_draw_exo)]; + data_to_plot(:,end+1:end+number_of_plots_to_draw_exo,1)=[oo_.occbin.simul.shocks_sequence(:,exo_index); zeros(nperiods-size(oo_.occbin.simul.shocks_sequence,1),number_of_plots_to_draw_exo)]; data_to_plot(:,end+1:end+number_of_plots_to_draw_exo,2)=NaN; end diff --git a/matlab/+occbin/set_default_options.m b/matlab/+occbin/set_default_options.m index 7f81b7e9acf8d5c534f3a8e7c356c7a9ed70e212..ea02b1a1f2bc83c0d996f6056eff0fe2291c0c53 100644 --- a/matlab/+occbin/set_default_options.m +++ b/matlab/+occbin/set_default_options.m @@ -37,6 +37,7 @@ if ismember(flag,{'all'}) options_occbin_.solver.solve_tolf=1e-5; options_occbin_.solver.maxit=10; options_occbin_.write_regimes.periods=[]; + options_occbin_.write_regimes.type='simul'; options_occbin_.write_regimes.filename=[M_.fname '_occbin_regimes']; end diff --git a/matlab/+occbin/solver.m b/matlab/+occbin/solver.m index f251432d81831027d9e19ff1b68e576714afb05d..125f28d909a06e20279d53f9c5614c36ff7af832 100644 --- a/matlab/+occbin/solver.m +++ b/matlab/+occbin/solver.m @@ -87,4 +87,4 @@ else end out.exo_pos = options_.occbin.simul.exo_pos; -oo_.occbin=out; +oo_.occbin.simul=out; diff --git a/matlab/+occbin/unpack_simulations.m b/matlab/+occbin/unpack_simulations.m index 4f102690ca4dd2a0daee447db6a0025977455e83..bea1e4103c0e1ca28a9897478d495b9f20d3ac81 100644 --- a/matlab/+occbin/unpack_simulations.m +++ b/matlab/+occbin/unpack_simulations.m @@ -29,10 +29,10 @@ function oo_=unpack_simulations(M_,oo_,options_) for i=1:M_.endo_nbr % unpack the IRFs - oo_.occbin.endo_linear.(M_.endo_names{i})= oo_.occbin.linear(:,i); - oo_.occbin.endo_piecewise.(M_.endo_names{i})=oo_.occbin.piecewise(:,i); - oo_.occbin.endo_ss.(M_.endo_names{i})=oo_.occbin.ys(i); + oo_.occbin.endo_linear.(M_.endo_names{i})= oo_.occbin.simul.linear(:,i); + oo_.occbin.endo_piecewise.(M_.endo_names{i})=oo_.occbin.simul.piecewise(:,i); + oo_.occbin.endo_ss.(M_.endo_names{i})=oo_.occbin.simul.ys(i); end -for i=1:length(oo_.occbin.exo_pos) +for i=1:length(oo_.occbin.simul.exo_pos) oo_.occbin.exo.(M_.exo_names{i})=options_.occbin.simul.SHOCKS(:,i); end \ No newline at end of file diff --git a/matlab/+occbin/write_regimes_to_xls.m b/matlab/+occbin/write_regimes_to_xls.m index 3e8767de9f9f7723f582f6ed57690c747affe267..0a6ae71630a8dbc460cf8f391d97515aa9b486c9 100644 --- a/matlab/+occbin/write_regimes_to_xls.m +++ b/matlab/+occbin/write_regimes_to_xls.m @@ -1,9 +1,9 @@ -function write_regimes_to_xls(regime_history,M_,options_) -% function write_regimes_to_xls(regime_history,M_,options_) +function write_regimes_to_xls(occbin_struct,M_,options_) +% function write_regimes_to_xls(occbin_struct,M_,options_) % writes regime results to Excel-file % % INPUTS -% - regime_history [struct] information on the regimes +% - occbin_struct [struct] occbin structure containing information on the regimes % - M_ [struct] Matlab's structure describing the model % - options_ [struct] Matlab's structure describing the current options @@ -26,6 +26,16 @@ function write_regimes_to_xls(regime_history,M_,options_) OutputDirectoryName = CheckPath('Output',M_.dname); +if strcmpi(options_.occbin.write_regimes.type,'simul') || strcmpi(options_.occbin.write_regimes.type,'smoother') + if isfield(occbin_struct,options_.occbin.write_regimes.type) && isfield(occbin_struct.(options_.occbin.write_regimes.type),'regime_history') + regime_history=occbin_struct.(lower(options_.occbin.write_regimes.type)).regime_history; + else + error('write_regimes_to_xls: the required field does not exist'); + end +else + error('write_regimes_to_xls: output type can only be simul or smoother.') +end + if isempty(options_.occbin.write_regimes.periods) T=1:length(regime_history); else diff --git a/preprocessor b/preprocessor index 81abea042b09d3027c917155a702fc0cb6f7e34f..a040a7dbdeb5afde955adedac4200612038175ac 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit 81abea042b09d3027c917155a702fc0cb6f7e34f +Subproject commit a040a7dbdeb5afde955adedac4200612038175ac diff --git a/tests/occbin/filter/NKM.mod b/tests/occbin/filter/NKM.mod index ee17fc607324495c8b18f2e90d2c72e227be6867..c8b17848ec38170ffc093a0e3d5c21abf1e3e6af 100644 --- a/tests/occbin/filter/NKM.mod +++ b/tests/occbin/filter/NKM.mod @@ -338,3 +338,4 @@ varobs yg inom pi; subplot(223) plot([oo0.SmoothedShocks.epss oo_.SmoothedShocks.epss]), title('epss') legend('PKF','IF') + occbin_write_regimes(smoother); diff --git a/tests/occbin/model_borrcon/borrcon_0_std_shocks.mod b/tests/occbin/model_borrcon/borrcon_0_std_shocks.mod index c43a0a2169d925a9c5dc1eb08b5fee5bc8d01f93..602320a522c66c494c0565ff09a4537cfe616dad 100644 --- a/tests/occbin/model_borrcon/borrcon_0_std_shocks.mod +++ b/tests/occbin/model_borrcon/borrcon_0_std_shocks.mod @@ -54,6 +54,6 @@ end; @#include "borrcon_common.inc" orig_results=load(['borrcon' filesep 'Output' filesep 'borrcon_results.mat']); -if max(max(abs(oo_.occbin.piecewise-orig_results.oo_.occbin.piecewise)))>1e-10 +if max(max(abs(oo_.occbin.simul.piecewise-orig_results.oo_.occbin.simul.piecewise)))>1e-10 error('Results do not match') end diff --git a/tests/occbin/model_irrcap_twoconstraints/dynrbc_0_std_shocks.mod b/tests/occbin/model_irrcap_twoconstraints/dynrbc_0_std_shocks.mod index f7c09446dbdad09b5c4c80b1b114e759576bf121..def97c14e5ccf5e09eb1ebaa26a89402e4e400bd 100644 --- a/tests/occbin/model_irrcap_twoconstraints/dynrbc_0_std_shocks.mod +++ b/tests/occbin/model_irrcap_twoconstraints/dynrbc_0_std_shocks.mod @@ -60,7 +60,7 @@ end; @#include "dynrbc_common.inc" orig_results=load(['dynrbc' filesep 'Output' filesep 'dynrbc_results.mat']); -if max(max(abs(oo_.occbin.piecewise-orig_results.oo_.occbin.piecewise)))>1e-10 +if max(max(abs(oo_.occbin.simul.piecewise-orig_results.oo_.occbin.simul.piecewise)))>1e-10 error('Results do not match') end diff --git a/tests/occbin/model_irrcap_twoconstraints/dynrbc_common.inc b/tests/occbin/model_irrcap_twoconstraints/dynrbc_common.inc index 2b3b15e7882ef271bb2b1775d473f65eb8ceff31..768dac606c5471ac7826bd1cb92d069703e21c60 100644 --- a/tests/occbin/model_irrcap_twoconstraints/dynrbc_common.inc +++ b/tests/occbin/model_irrcap_twoconstraints/dynrbc_common.inc @@ -98,7 +98,7 @@ occbin_graph(noconstant) c erra lambdak k i a k; figtitle = 'Smoothed variables (piecewise)'; legendlist = cellstr(char('Simulated','Piecewise smoother')); - shock_vector=[oo_.occbin.shocks_sequence./100; zeros(length(oo_.occbin.endo_piecewise.c)-size(oo_.occbin.shocks_sequence,1),size(oo_.occbin.shocks_sequence,2))]; + shock_vector=[oo_.occbin.simul.shocks_sequence./100; zeros(length(oo_.occbin.endo_piecewise.c)-size(oo_.occbin.simul.shocks_sequence,1),size(oo_.occbin.simul.shocks_sequence,2))]; 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.smoother.SmoothedVariables.c-oo_.occbin.endo_ss.c,oo_.occbin.smoother.SmoothedVariables.lambdak/100,oo_.occbin.smoother.SmoothedVariables.k-oo_.occbin.endo_ss.k,oo_.occbin.smoother.SmoothedVariables.i-oo_.occbin.endo_ss.i,oo_.occbin.smoother.SmoothedVariables.a-oo_.occbin.endo_ss.a, oo_.occbin.smoother.SmoothedShocks.erra/100]; occbin.make_chart(titlelist,legendlist,figtitle,ylabels,cat(3,line1,line2));