occbin_write_regimes: distinguish between smoother and simulations

Closes: #1828
pac-components
Johannes Pfeifer 2021-12-06 16:53:51 +01:00 committed by Sébastien Villemot
parent 018c603035
commit c07508a917
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
11 changed files with 49 additions and 28 deletions

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -87,4 +87,4 @@ else
end
out.exo_pos = options_.occbin.simul.exo_pos;
oo_.occbin=out;
oo_.occbin.simul=out;

View File

@ -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

View File

@ -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

@ -1 +1 @@
Subproject commit 81abea042b09d3027c917155a702fc0cb6f7e34f
Subproject commit a040a7dbdeb5afde955adedac4200612038175ac

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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));