From 5fe495852e9b3ee255d13bae7472de60bf0ddfc5 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Thu, 5 Dec 2019 16:50:18 +0100 Subject: [PATCH] Intregrate full list of options to initial_condition_decompositions, including defaults. Adapt figure names when initial conditions are ploteed instead of shocks --- matlab/graph_decomp.m | 23 ++++++++++++++----- matlab/graph_decomp_detail.m | 23 ++++++++++++++----- matlab/initial_condition_decomposition.m | 14 ++++++----- matlab/plot_shock_decomposition.m | 3 +++ ..._initial_condition_decomposition_options.m | 10 +++++--- 5 files changed, 52 insertions(+), 21 deletions(-) diff --git a/matlab/graph_decomp.m b/matlab/graph_decomp.m index 738cbd5c9..2f24e17c7 100644 --- a/matlab/graph_decomp.m +++ b/matlab/graph_decomp.m @@ -70,6 +70,11 @@ 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; @@ -117,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) @@ -244,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 diff --git a/matlab/graph_decomp_detail.m b/matlab/graph_decomp_detail.m index ac4ce6f5e..59e1c4502 100644 --- a/matlab/graph_decomp_detail.m +++ b/matlab/graph_decomp_detail.m @@ -72,6 +72,11 @@ 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; @@ -136,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; @@ -267,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 diff --git a/matlab/initial_condition_decomposition.m b/matlab/initial_condition_decomposition.m index 0c846b1ff..e8a2b72d9 100644 --- a/matlab/initial_condition_decomposition.m +++ b/matlab/initial_condition_decomposition.m @@ -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 . +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 diff --git a/matlab/plot_shock_decomposition.m b/matlab/plot_shock_decomposition.m index a601e8b18..d649fc061 100644 --- a/matlab/plot_shock_decomposition.m +++ b/matlab/plot_shock_decomposition.m @@ -62,6 +62,9 @@ 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]; diff --git a/matlab/set_default_initial_condition_decomposition_options.m b/matlab/set_default_initial_condition_decomposition_options.m index b0591443c..3294d969b 100644 --- a/matlab/set_default_initial_condition_decomposition_options.m +++ b/matlab/set_default_initial_condition_decomposition_options.m @@ -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 . -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 = [];