Commit 3f3f49c4 authored by Sébastien Villemot's avatar Sébastien Villemot

Merge branch 'flip_diff' into 'master'

Flip diff

See merge request Dynare/dynare!1677
parents 8586fea2 74e7c12d
......@@ -7349,6 +7349,113 @@ Shock Decomposition
Default: ``0``.
.. option:: plot_init_date = DATE
If passed, plots decomposition using ``plot_init_date`` as initial period.
Default: first observation in estimation
.. option:: plot_end_date = DATE
If passed, plots decomposition using ``plot_end_date`` as last period.
Default: last observation in estimation
.. option:: diff
If passed, plot the decomposition of the first difference of the list of variables.
If used in combination with :opt:`flip`, the ``diff`` operator is first applied.
Default: not activated
.. option:: flip
If passed, plot the decomposition of the opposite of the list of variables.
If used in combination with :opt:`diff`, the ``diff`` operator is first applied.
Default: not activated
.. command:: initial_condition_decomposition [VARIABLE_NAME]...;
initial_condition_decomposition (OPTIONS...) [VARIABLE_NAME]...;
|br| This command computes and plots the decomposition of the effect of
smoothed initial conditions of state variables. The ``variable_names`` provided
govern which variables the decomposition is plotted for.
Further note that, unlike the majority of Dynare commands, the
options specified below are overwritten with their defaults before
every call to ``initial_condition_decomposition``. Hence, if you want to
reuse an option in a subsequent call to
``initial_condition_decomposition``, you must pass it to the command
again.
*Options*
.. option:: colormap = STRING
See :opt:`colormap <colormap = STRING>`.
.. option:: nodisplay
See :opt:`nodisplay`.
.. option:: graph_format = FORMAT
graph_format = ( FORMAT, FORMAT... )
See :opt:`graph_format <graph_format = FORMAT>`.
.. option:: detail_plot
Plots shock contributions using subplots, one per shock (or
group of shocks). Default: not activated
.. option:: steadystate
If passed, the the :math:`y`-axis value of the zero line in
the shock decomposition plot is translated to the steady state
level. Default: not activated
.. option:: type = qoq | yoy | aoa
For quarterly data, valid arguments are: ``qoq`` for
quarter-on-quarter plots, ``yoy`` for year-on-year plots of
growth rates, ``aoa`` for annualized variables, i.e. the value
in the last quarter for each year is plotted. Default value:
empty, i.e. standard period-on-period plots (``qoq`` for
quarterly data).
.. option:: fig_name = STRING
Specifies a user-defined keyword to be appended to the default
figure name set by ``plot_shock_decomposition``. This can
avoid to overwrite plots in case of sequential calls to
``plot_shock_decomposition``.
.. option:: write_xls
Saves shock decompositions to Excel-file in the main
directory, named
``FILENAME_shock_decomposition_TYPE_FIG_NAME_initval.xls``. This
option requires your system to be configured to be able to
write Excel files. [#f7]_
.. option:: plot_init_date = DATE
If passed, plots decomposition using ``plot_init_date`` as initial period.
Default: first observation in estimation
.. option:: plot_end_date = DATE
If passed, plots decomposition using ``plot_end_date`` as last period.
Default: last observation in estimation
.. option:: diff
If passed, plot the decomposition of the first difference of the list of variables.
If used in combination with :opt:`flip`, the ``diff`` operator is first applied.
Default: not activated
.. option:: flip
If passed, plot the decomposition of the opposite of the list of variables.
If used in combination with :opt:`diff`, the ``diff`` operator is first applied.
Default: not activated
Calibrated Smoother
===================
......
......@@ -50,6 +50,32 @@ if ~isempty(opts_decomp.type)
fig_mode1 = ['_' fig_mode];
fig_mode = [fig_mode '_'];
end
if isfield(opts_decomp,'flip')
flip_decomp = opts_decomp.flip ;
else
flip_decomp = 0;
end
if flip_decomp
fig_mode1 = [fig_mode1 '_flip'];
fig_mode = [fig_mode 'flip_'];
end
if isfield(opts_decomp,'diff')
differentiate_decomp = opts_decomp.diff ;
else
differentiate_decomp = 0;
end
if differentiate_decomp
fig_mode1 = [fig_mode1 '_diff'];
fig_mode = [fig_mode 'diff_'];
end
if isfield(opts_decomp,'init_cond_decomp')
init_cond_decomp = opts_decomp.init_cond_decomp ;
else
init_cond_decomp = 0;
end
fig_name_long = opts_decomp.fig_name;
use_shock_groups = DynareOptions.plot_shock_decomp.use_shock_groups;
......@@ -96,10 +122,16 @@ if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp
fprintf(fidTeX,' \n');
end
if opts_decomp.vintage && opts_decomp.realtime>1
preamble_txt = 'Shock decomposition';
if init_cond_decomp
preamble_txt = 'Initial condition decomposition';
preamble_figname = '_initval_decomposition_';
else
preamble_txt = 'Historical shock decomposition';
preamble_figname = '_shock_decomposition_';
if opts_decomp.vintage && opts_decomp.realtime>1
preamble_txt = 'Shock decomposition';
else
preamble_txt = 'Historical shock decomposition';
end
end
if ~(screen_shocks && comp_nbr>18)
......@@ -223,18 +255,18 @@ for j=1:nvar
hold off
if ~DynareOptions.plot_shock_decomp.expand
dyn_saveas(fhandle,[GraphDirectoryName, filesep, DynareModel.fname,'_shock_decomposition_',endo_names{i_var(j)},fig_mode1,fig_name],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
dyn_saveas(fhandle,[GraphDirectoryName, filesep, DynareModel.fname,preamble_figname,endo_names{i_var(j)},fig_mode1,fig_name],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format)))
fprintf(fidTeX,'\\begin{figure}[H]\n');
fprintf(fidTeX,'\\centering \n');
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s/graphs/%s_shock_decomposition_%s}\n',DynareModel.fname,DynareModel.fname,[endo_names{i_var(j)} fig_mode1 fig_name]);
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s/graphs/%s%s}\n',DynareModel.fname,DynareModel.fname,[preamble_figname endo_names{i_var(j)} fig_mode1 fig_name]);
fprintf(fidTeX,'\\label{Fig:shock_decomp:%s}\n',[fig_mode endo_names{i_var(j)} fig_name]);
fprintf(fidTeX,['\\caption{' preamble_txt fig_name_long strrep(fig_mode1, '_', ' ') ': $ %s $.}\n'],DynareModel.endo_names_tex{i_var(j)});
fprintf(fidTeX,'\\end{figure}\n');
fprintf(fidTeX,' \n');
end
else
dyn_saveas(fhandle,[DynareOptions.plot_shock_decomp.filepath, filesep, DynareModel.fname,'_shock_decomposition_',endo_names{i_var(j)},fig_mode1,fig_name],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
dyn_saveas(fhandle,[DynareOptions.plot_shock_decomp.filepath, filesep, DynareModel.fname,preamble_figname,endo_names{i_var(j)},fig_mode1,fig_name],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
end
end
......
......@@ -53,6 +53,30 @@ if ~isempty(opts_decomp.type)
fig_mode1 = ['_' fig_mode];
fig_mode = [fig_mode '_'];
end
if isfield(opts_decomp,'flip')
flip_decomp = opts_decomp.flip ;
else
flip_decomp = 0;
end
if flip_decomp
fig_mode1 = [fig_mode1 '_flip'];
fig_mode = [fig_mode 'flip_'];
end
if isfield(opts_decomp,'diff')
differentiate_decomp = opts_decomp.diff ;
else
differentiate_decomp = 0;
end
if differentiate_decomp
fig_mode1 = [fig_mode1 '_diff'];
fig_mode = [fig_mode 'diff_'];
end
if isfield(opts_decomp,'init_cond_decomp')
init_cond_decomp = opts_decomp.init_cond_decomp ;
else
init_cond_decomp = 0;
end
screen_shocks = opts_decomp.screen_shocks;
if ~isempty(DynareOptions.plot_shock_decomp.use_shock_groups) || comp_nbr<=18
screen_shocks=0;
......@@ -117,10 +141,16 @@ if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp
fprintf(fidTeX,' \n');
end
if opts_decomp.vintage && opts_decomp.realtime>1
preamble_txt = 'Shock decomposition';
if init_cond_decomp
preamble_txt = 'Initial condition decomposition';
preamble_figname = '_initval_decomposition_';
else
preamble_txt = 'Historical shock decomposition';
preamble_figname = '_shock_decomposition_';
if opts_decomp.vintage && opts_decomp.realtime>1
preamble_txt = 'Shock decomposition';
else
preamble_txt = 'Historical shock decomposition';
end
end
ncol=3;
......@@ -248,18 +278,18 @@ for j=1:nvar
end
if ~DynareOptions.plot_shock_decomp.expand
dyn_saveas(fhandle,[GraphDirectoryName, filesep, DynareModel.fname, ...
'_shock_decomposition_', endo_names{i_var(j)}, fig_mode1,fig_name suffix],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
preamble_figname, endo_names{i_var(j)}, fig_mode1,fig_name suffix],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format)))
fprintf(fidTeX,'\\begin{figure}[H]\n');
fprintf(fidTeX,'\\centering \n');
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s/graphs/%s_shock_decomposition_%s}\n',DynareModel.fname,DynareModel.fname,[endo_names{i_var(j)} fig_mode1 fig_name suffix]);
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s/graphs/%s%s}\n',DynareModel.fname,DynareModel.fname,[preamble_figname endo_names{i_var(j)} fig_mode1 fig_name suffix]);
fprintf(fidTeX,'\\label{Fig:shock_decomp_detail:%s}\n',[fig_mode endo_names{i_var(j)} fig_name suffix]);
fprintf(fidTeX,['\\caption{' preamble_txt fig_name_long strrep(fig_mode1, '_', ' ') ': $ %s $ (detail).}\n'], DynareModel.endo_names_tex{i_var(j)});
fprintf(fidTeX,'\\end{figure}\n');
fprintf(fidTeX,' \n');
end
else
dyn_saveas(fhandle,[DynareOptions.plot_shock_decomp.filepath, filesep, DynareModel.fname,'_shock_decomposition_',endo_names{i_var(j)},fig_mode1,fig_name suffix],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
dyn_saveas(fhandle,[DynareOptions.plot_shock_decomp.filepath, filesep, DynareModel.fname,preamble_figname,endo_names{i_var(j)},fig_mode1,fig_name suffix],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format);
end
end
......
......@@ -38,12 +38,18 @@ 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.colormap = options_.initial_condition_decomp.colormap;
options_.plot_shock_decomp.nodisplay = options_.initial_condition_decomp.nodisplay;
options_.plot_shock_decomp.graph_format = options_.initial_condition_decomp.graph_format;
options_.plot_shock_decomp.fig_name = options_.initial_condition_decomp.fig_name;
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;
options_.plot_shock_decomp.diff = options_.initial_condition_decomp.diff;
options_.plot_shock_decomp.flip = options_.initial_condition_decomp.flip;
% indices of endogenous variables
if isempty(varlist)
......@@ -128,11 +134,7 @@ M_.exo_nbr = M_.endo_nbr;
options_.plot_shock_decomp.realtime=0;
options_.plot_shock_decomp.screen_shocks=1;
options_.plot_shock_decomp.use_shock_groups = '';
fig_name = options_.plot_shock_decomp.fig_name;
if ~isempty(fig_name)
options_.plot_shock_decomp.fig_name=[fig_name '_initval'];
else
options_.plot_shock_decomp.fig_name='initval';
end
options_.plot_shock_decomp.init_cond_decomp = 1; % private flag to plotting utilities
plot_shock_decomposition(M_,oo,options_,varlist);
% end
\ No newline at end of file
......@@ -46,12 +46,25 @@ endo_nbr = M_.endo_nbr;
nshocks = M_.exo_nbr;
fig_name='';
if isfield(options_.plot_shock_decomp,'diff') % private trap for uimenu calls
differentiate_decomp=options_.plot_shock_decomp.diff;
else
differentiate_decomp=0;
end
if isfield(options_.plot_shock_decomp,'flip') % private trap for uimenu calls
flip_decomp=options_.plot_shock_decomp.flip;
else
flip_decomp=0;
end
if isfield(options_.plot_shock_decomp,'expand') % private trap for uimenu calls
expand=options_.plot_shock_decomp.expand;
else
expand=0;
options_.plot_shock_decomp.expand=0;
end
if ~isfield(options_.plot_shock_decomp,'init_cond_decomp')
options_.plot_shock_decomp.init_cond_decomp=0;
end
if ~isempty(options_.plot_shock_decomp.fig_name)
fig_name=[' ' options_.plot_shock_decomp.fig_name];
......@@ -229,6 +242,12 @@ if isempty(options_.plot_shock_decomp.colormap)
options_.plot_shock_decomp.colormap = MAP;
end
if differentiate_decomp
z(:,:,2:end) = z(:,:,2:end)-z(:,:,1:end-1);
z(:,:,1) = nan;
steady_state = steady_state*0;
end
switch type
case '' % default
......@@ -337,6 +356,11 @@ switch type
error('plot_shock_decomposition:: Wrong type')
end
if flip_decomp
z = -z;
steady_state = - steady_state;
end
if steadystate
options_.plot_shock_decomp.steady_state=steady_state;
end
......
......@@ -28,9 +28,13 @@ function options = set_default_initial_condition_decomposition_options(options)
% 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.colormap = '';
options.initial_condition_decomp.nodisplay = false;
options.initial_condition_decomp.graph_format = 'eps';
options.initial_condition_decomp.fig_name = '';
options.initial_condition_decomp.detail_plot = false;
options.initial_condition_decomp.steadystate = false;
options.initial_condition_decomp.write_xls = false;
options.initial_condition_decomp.type = '';
options.initial_condition_decomp.plot_init_date = [];
options.initial_condition_decomp.plot_end_date = [];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment