diff --git a/matlab/annualized_shock_decomposition.m b/matlab/annualized_shock_decomposition.m index 72591634dba31be8d3d629078b25a6211dfb9d5e..8d6ae2d48ce7409330015eea0611bc21b7b29fd8 100644 --- a/matlab/annualized_shock_decomposition.m +++ b/matlab/annualized_shock_decomposition.m @@ -120,6 +120,7 @@ elseif q2a.plot ~= 2 end % end initialize names +steady_state=steady_state(i_var); if realtime_==0 % usual shock decomp @@ -143,7 +144,6 @@ if isstruct(aux) aux.yss=steady_state_aux; end end -steady_state=steady_state(i_var); % endo_names = M_.endo_names(i_var,:); % endo_names_tex = M_.endo_names_tex(i_var,:); @@ -330,4 +330,4 @@ elseif q2a.plot == 2 z=za; else z=cat(1,za,gza); -end \ No newline at end of file +end diff --git a/matlab/expand_group.m b/matlab/expand_group.m index 1793c9c21eb49a73bf97595a7fe3aa5381624626..4c1563ebc59dc527e94c8d5583f8a8dc957b351f 100644 --- a/matlab/expand_group.m +++ b/matlab/expand_group.m @@ -10,7 +10,7 @@ function expand_group(use_shock_groups,var_list_, ic) % SPECIAL REQUIREMENTS % none -% Copyright (C) 2016-2017 Dynare Team +% Copyright (C) 2016-2018 Dynare Team % % This file is part of Dynare. % @@ -27,21 +27,37 @@ function expand_group(use_shock_groups,var_list_, ic) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. +filename = get(gcf,'filename'); +[filepath, name, ext]=fileparts(filename); M = evalin('base','M_'); oo = evalin('base','oo_'); options = evalin('base','options_'); mydata=get(findobj(gcf,'tag',['group' int2str(ic)]),'userdata'); if isfield(mydata,'shock_decomp') - options.shock_decomp=mydata.shock_decomp; + if isfield(mydata,'plot_shock_decomp') + options.plot_shock_decomp=mydata.plot_shock_decomp; + options.shock_decomp=mydata.shock_decomp; + else + options.plot_shock_decomp=mydata.shock_decomp; + end +else + options.plot_shock_decomp=mydata.plot_shock_decomp; + +end +if isfield(mydata,'first_obs') + options.first_obs=mydata.first_obs; +end +if isfield(mydata,'nobs') + options.nobs=mydata.nobs; end -options.plot_shock_decomp=mydata.plot_shock_decomp; -options.first_obs=mydata.first_obs; -options.nobs=mydata.nobs; % define expanded group label = mydata.shock_group.label; +label = strrep(label,' ','_'); +label = strrep(label,'-','_'); shocks = mydata.shock_group.shocks; options.plot_shock_decomp.fig_name = [mydata.fig_name '. Expand']; -options.plot_shock_decomp.use_shock_groups = strrep(label,' ','_'); %[use_shock_groups_old int2str(ic)]; +options.plot_shock_decomp.use_shock_groups = label; %[use_shock_groups_old int2str(ic)]; +options.plot_shock_decomp.filepath = filepath; for j=1:length(shocks) M.shock_groups.(options.plot_shock_decomp.use_shock_groups).(['group' int2str(j)]).label=shocks{j}; M.shock_groups.(options.plot_shock_decomp.use_shock_groups).(['group' int2str(j)]).shocks=shocks(j); @@ -49,4 +65,18 @@ end options.plot_shock_decomp.interactive=0; options.plot_shock_decomp.expand=1; +options.plot_shock_decomp.nodisplay=0; +options.plot_shock_decomp.write_xls=0; +%% set optimal colormap +func = @(x) colorspace('RGB->Lab',x); +MAP = distinguishable_colors(length(shocks)+1,'w',func); +MAP(end,:) = [0.7 0.7 0.7]; + +options.plot_shock_decomp.colormap = MAP; + +if isfield(mydata,'endo_names') + options.plot_shock_decomp.endo_names = mydata.endo_names; + options.plot_shock_decomp.endo_names_tex = mydata.endo_names_tex; +end + plot_shock_decomposition(M,oo,options,var_list_); diff --git a/matlab/graph_decomp.m b/matlab/graph_decomp.m index 28a01b11001bb3d9dbdaf57bb0ae2ef5c2b39bc2..7e114cdb8b07ee40fec8e88c51a1c65d44fe1fbc 100644 --- a/matlab/graph_decomp.m +++ b/matlab/graph_decomp.m @@ -11,7 +11,7 @@ function []=graph_decomp(z,shock_names,endo_names,i_var,initial_date,DynareModel % DynareModel [structure] Dynare model structure % DynareOptions [structure] Dynare options structure -% Copyright (C) 2010-2017 Dynare Team +% Copyright (C) 2010-2018 Dynare Team % % This file is part of Dynare. % @@ -28,7 +28,9 @@ function []=graph_decomp(z,shock_names,endo_names,i_var,initial_date,DynareModel % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -GraphDirectoryName = CheckPath('graphs',DynareModel.dname); +if ~DynareOptions.plot_shock_decomp.expand + GraphDirectoryName = CheckPath('graphs',DynareModel.dname); +end new_colormap = DynareOptions.plot_shock_decomp.colormap; % number of components equals number of shocks + 1 (initial conditions) @@ -87,7 +89,7 @@ end nvar = length(i_var); %% write LaTeX-Header -if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format))) +if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format))) && ~DynareOptions.plot_shock_decomp.expand fidTeX = fopen([GraphDirectoryName, filesep, DynareModel.fname '_shock_decomp' fig_mode1 fig_name '.tex'],'w'); fprintf(fidTeX,'%% TeX eps-loader file generated by Dynare''s graph_decomp.m.\n'); fprintf(fidTeX,['%% ' datestr(now,0) '\n']); @@ -197,6 +199,9 @@ for j=1:nvar mydata.plot_shock_decomp = DynareOptions.plot_shock_decomp; mydata.first_obs = DynareOptions.first_obs; mydata.nobs = DynareOptions.nobs; + mydata.plot_shock_decomp.zfull = DynareOptions.plot_shock_decomp.zfull(i_var(j),:,:); + mydata.endo_names = deblank(endo_names(i_var(j),:)); + mydata.endo_names_tex = deblank(DynareModel.endo_names_tex(i_var(j),:)); if ~isempty(mydata.shock_group.shocks) c = uicontextmenu; hl.UIContextMenu=c; @@ -216,20 +221,26 @@ for j=1:nvar colormap(new_colormap) end hold off - dyn_saveas(fhandle,[GraphDirectoryName, filesep, DynareModel.fname,'_shock_decomposition_',deblank(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,[deblank(endo_names(i_var(j),:)) fig_mode1 fig_name]); - fprintf(fidTeX,'\\label{Fig:shock_decomp:%s}\n',[fig_mode deblank(endo_names(i_var(j),:)) fig_name]); - fprintf(fidTeX,['\\caption{' preamble_txt fig_name_long strrep(fig_mode1, '_', ' ') ': $ %s $.}\n'],deblank(DynareModel.endo_names_tex(i_var(j),:))); - fprintf(fidTeX,'\\end{figure}\n'); - fprintf(fidTeX,' \n'); + if ~DynareOptions.plot_shock_decomp.expand + + dyn_saveas(fhandle,[GraphDirectoryName, filesep, DynareModel.fname,'_shock_decomposition_',deblank(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,[deblank(endo_names(i_var(j),:)) fig_mode1 fig_name]); + fprintf(fidTeX,'\\label{Fig:shock_decomp:%s}\n',[fig_mode deblank(endo_names(i_var(j),:)) fig_name]); + fprintf(fidTeX,['\\caption{' preamble_txt fig_name_long strrep(fig_mode1, '_', ' ') ': $ %s $.}\n'],deblank(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_',deblank(endo_names(i_var(j),:)),fig_mode1,fig_name],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format); + end end %% write LaTeX-Footer -if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format))) +if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format))) && ~DynareOptions.plot_shock_decomp.expand fprintf(fidTeX,' \n'); fprintf(fidTeX,'%% End of TeX file.\n'); fclose(fidTeX); diff --git a/matlab/graph_decomp_detail.m b/matlab/graph_decomp_detail.m index c39a98282658045011c6fa50060183c6b19d0504..06484a6c3aea8a0113c7431b305b3a0d2b96c03e 100644 --- a/matlab/graph_decomp_detail.m +++ b/matlab/graph_decomp_detail.m @@ -11,7 +11,7 @@ function []=graph_decomp_detail(z,shock_names,endo_names,i_var,initial_date,Dyna % DynareModel [structure] Dynare model structure % DynareOptions [structure] Dynare options structure -% Copyright (C) 2010-2017 Dynare Team +% Copyright (C) 2010-2018 Dynare Team % % This file is part of Dynare. % @@ -28,7 +28,9 @@ function []=graph_decomp_detail(z,shock_names,endo_names,i_var,initial_date,Dyna % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -GraphDirectoryName = CheckPath('graphs',DynareModel.dname); +if ~DynareOptions.plot_shock_decomp.expand + GraphDirectoryName = CheckPath('graphs',DynareModel.dname); +end % interactive = 0; fig_mode=''; fig_mode1=''; @@ -108,7 +110,7 @@ end nvar = length(i_var); %% write LaTeX-Header -if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format))) +if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format))) && ~DynareOptions.plot_shock_decomp.expand fidTeX = fopen([GraphDirectoryName, filesep, DynareModel.fname '_shock_decomp' fig_mode1 fig_name '_detail.tex'],'w'); fprintf(fidTeX,'%% TeX eps-loader file generated by Dynare''s graph_decomp_detail.m.\n'); fprintf(fidTeX,['%% ' datestr(now,0) '\n']); @@ -199,6 +201,9 @@ for j=1:nvar mydata.plot_shock_decomp = DynareOptions.plot_shock_decomp; mydata.first_obs = DynareOptions.first_obs; mydata.nobs = DynareOptions.nobs; + mydata.plot_shock_decomp.zfull = DynareOptions.plot_shock_decomp.zfull(i_var(j),:,:); + mydata.endo_names = deblank(endo_names(i_var(j),:)); + mydata.endo_names_tex = deblank(DynareModel.endo_names_tex(i_var(j),:)); if ~isempty(mydata.shock_group.shocks) c = uicontextmenu; hax.UIContextMenu=c; @@ -241,21 +246,26 @@ for j=1:nvar else suffix = ['_detail']; end - dyn_saveas(fhandle,[GraphDirectoryName, filesep, DynareModel.fname,'_shock_decomposition_',deblank(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,[deblank(endo_names(i_var(j),:)) fig_mode1 fig_name suffix]); - fprintf(fidTeX,'\\label{Fig:shock_decomp_detail:%s}\n',[fig_mode deblank(endo_names(i_var(j),:)) fig_name suffix]); - fprintf(fidTeX,['\\caption{' preamble_txt fig_name_long strrep(fig_mode1, '_', ' ') ': $ %s $ (detail).}\n'],deblank(DynareModel.endo_names_tex(i_var(j),:))); - fprintf(fidTeX,'\\end{figure}\n'); - fprintf(fidTeX,' \n'); + if ~DynareOptions.plot_shock_decomp.expand + dyn_saveas(fhandle,[GraphDirectoryName, filesep, DynareModel.fname,'_shock_decomposition_',deblank(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,[deblank(endo_names(i_var(j),:)) fig_mode1 fig_name suffix]); + fprintf(fidTeX,'\\label{Fig:shock_decomp_detail:%s}\n',[fig_mode deblank(endo_names(i_var(j),:)) fig_name suffix]); + fprintf(fidTeX,['\\caption{' preamble_txt fig_name_long strrep(fig_mode1, '_', ' ') ': $ %s $ (detail).}\n'],deblank(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_',deblank(endo_names(i_var(j),:)),fig_mode1,fig_name suffix],DynareOptions.plot_shock_decomp.nodisplay,DynareOptions.plot_shock_decomp.graph_format); + end end end %% write LaTeX-Footer -if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format))) +if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.plot_shock_decomp.graph_format))) && ~DynareOptions.plot_shock_decomp.expand fprintf(fidTeX,' \n'); fprintf(fidTeX,'%% End of TeX file.\n'); fclose(fidTeX); diff --git a/matlab/gsa/map_calibration.m b/matlab/gsa/map_calibration.m index 8f6aa859ab54760d2b67e69d5d2df2a28ccd7741..30d394b354b97ab4fb5a142ef3ca6899b8300259 100644 --- a/matlab/gsa/map_calibration.m +++ b/matlab/gsa/map_calibration.m @@ -394,6 +394,7 @@ if ~isempty(indx_moment) % For single legend search which has maximum nbr of restrictions maxijv=0; for ij=1:nbr_moment_restrictions + endo_prior_restrictions.moment{ij,3} = sort(endo_prior_restrictions.moment{ij,3}); if length(endo_prior_restrictions.moment{ij,3})>maxijv maxij=ij;maxijv=length(endo_prior_restrictions.moment{ij,3}); end @@ -477,6 +478,7 @@ if ~isempty(indx_moment) % end end for ij=1:nbr_moment_couples + time_matrix{ij} = sort(time_matrix{ij}); if length(time_matrix{ij})>1 if ~DynareOptions.nograph itmp = (find(plot_indx==ij)); @@ -505,7 +507,7 @@ if ~isempty(indx_moment) hold off axis(a) box on - set(gca,'xtick',sort(time_matrix{ij})) +% set(gca,'xtick',sort(time_matrix{ij})) itmp = min(itmp); title([endo_prior_restrictions.moment{itmp,1},' vs ',endo_prior_restrictions.moment{itmp,2}],'interpreter','none'), end diff --git a/matlab/plot_shock_decomposition.m b/matlab/plot_shock_decomposition.m index fe85aa0fba490c26225cb48ff5d68f057b6244ba..92b306aaa2a2d9c00041b7c0a6b192e43881f445 100644 --- a/matlab/plot_shock_decomposition.m +++ b/matlab/plot_shock_decomposition.m @@ -57,6 +57,7 @@ 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 ~isempty(options_.plot_shock_decomp.fig_name) @@ -95,84 +96,119 @@ else end switch realtime_ - - case 0 - z = oo_.shock_decomposition; - fig_name1=fig_name; - - case 1 % realtime - if vintage_ - z = oo_.realtime_shock_decomposition.(['time_' int2str(vintage_)]); - fig_name1=[fig_name ' realtime (vintage ' char(initial_date+vintage_-1) ')']; - else - z = oo_.realtime_shock_decomposition.pool; - fig_name1=[fig_name ' realtime (rolling)']; - end - - case 2 % conditional - if vintage_ - z = oo_.realtime_conditional_shock_decomposition.(['time_' int2str(vintage_)]); - initial_date = initial_date+vintage_-1; - fig_name1=[fig_name ' ' int2str(forecast_) '-step ahead conditional forecast (given ' char(initial_date) ')']; - else - z = oo_.conditional_shock_decomposition.pool; - fig_name1=[fig_name ' 1-step ahead conditional forecast (rolling)']; - end - - case 3 % forecast - if vintage_ - z = oo_.realtime_forecast_shock_decomposition.(['time_' int2str(vintage_)]); - initial_date = initial_date+vintage_-1; - fig_name1=[fig_name ' ' int2str(forecast_) '-step ahead forecast (given ' char(initial_date) ')']; - else - z = oo_.realtime_forecast_shock_decomposition.pool; - fig_name1=[fig_name ' 1-step ahead forecast (rolling)']; - end + + case 0 + if ~(expand && isfield(options_.plot_shock_decomp,'zfull')) + z = oo_.shock_decomposition; + end + fig_name1=fig_name; + + case 1 % realtime + if vintage_ + if ~(expand && isfield(options_.plot_shock_decomp,'zfull')) + z = oo_.realtime_shock_decomposition.(['time_' int2str(vintage_)]); + end + fig_name1=[fig_name ' realtime (vintage ' char(initial_date+vintage_-1) ')']; + else + if ~(expand && isfield(options_.plot_shock_decomp,'zfull')) + z = oo_.realtime_shock_decomposition.pool; + end + fig_name1=[fig_name ' realtime (rolling)']; + end + + case 2 % conditional + if vintage_ + if ~(expand && isfield(options_.plot_shock_decomp,'zfull')) + z = oo_.realtime_conditional_shock_decomposition.(['time_' int2str(vintage_)]); + end + initial_date = initial_date+vintage_-1; + fig_name1=[fig_name ' ' int2str(forecast_) '-step ahead conditional forecast (given ' char(initial_date) ')']; + else + if ~(expand && isfield(options_.plot_shock_decomp,'zfull')) + z = oo_.conditional_shock_decomposition.pool; + end + fig_name1=[fig_name ' 1-step ahead conditional forecast (rolling)']; + end + + case 3 % forecast + if vintage_ + if ~(expand && isfield(options_.plot_shock_decomp,'zfull')) + z = oo_.realtime_forecast_shock_decomposition.(['time_' int2str(vintage_)]); + end + initial_date = initial_date+vintage_-1; + fig_name1=[fig_name ' ' int2str(forecast_) '-step ahead forecast (given ' char(initial_date) ')']; + else + if ~(expand && isfield(options_.plot_shock_decomp,'zfull')) + z = oo_.realtime_forecast_shock_decomposition.pool; + end + fig_name1=[fig_name ' 1-step ahead forecast (rolling)']; + end end -steady_state = oo_.steady_state; +if isfield(oo_.dr,'ys') + steady_state = oo_.dr.ys; +else + steady_state = oo_.steady_state; +end -if isequal(type,'aoa') && isstruct(q2a) && realtime_ - % take all dates where realtime is saved - qqq=options_.initial_date+options_.shock_decomp.save_realtime(:)-1; - % take the first Q4 of saved realtime - t0=min(options_.shock_decomp.save_realtime(qqq.time(:,2)==4)); - if isempty(t0) - error('the realtime decompositions are not stored in Q4! Please check your dates and settings.') - end - if ~isfield(q2a,'var_type') % private trap for aoa calls - q2a.var_type=1; - end - if ~isfield(q2a,'islog') % private trap for aoa calls - q2a.islog=0; - end - if ~isfield(q2a,'GYTREND0') % private trap for aoa calls - q2a.GYTREND0=0; - end - if ~isfield(q2a,'aux') % private trap for aoa calls - q2a.aux=0; +if isequal(type,'aoa') && isstruct(q2a) + if (expand && isfield(options_.plot_shock_decomp,'zfull')) + za = options_.plot_shock_decomp.zfull; + genda = size(za,3); + endo_nbra = size(za,1); + [za, shock_names, M_] = make_the_groups(za,genda,endo_nbra,nshocks,M_, options_); end - if ~isfield(q2a,'cumfix') % private trap for aoa calls - q2a.cumfix=1; - end - if ~isfield(q2a,'plot') % private trap for aoa calls - q2a.plot=1; % growth rate + if realtime_ + % take all dates where realtime is saved + qqq=options_.initial_date+options_.shock_decomp.save_realtime(:)-1; + % take the first Q4 of saved realtime + t0=min(options_.shock_decomp.save_realtime(qqq.time(:,2)==4)); + if isempty(t0) + error('the realtime decompositions are not stored in Q4! Please check your dates and settings.') + end + if ~isfield(q2a,'var_type') % private trap for aoa calls + q2a.var_type=1; + end + if ~isfield(q2a,'islog') % private trap for aoa calls + q2a.islog=0; + end + if ~isfield(q2a,'GYTREND0') % private trap for aoa calls + q2a.GYTREND0=0; + end + if ~isfield(q2a,'aux') % private trap for aoa calls + q2a.aux=0; + end + if ~isfield(q2a,'cumfix') % private trap for aoa calls + q2a.cumfix=1; + end + if ~isfield(q2a,'plot') % private trap for aoa calls + q2a.plot=1; % growth rate + end + + % if isstruct(q2a.aux) && ischar(q2a.aux.y) + % opts=options_; + % opts.plot_shock_decomp.type='qoq'; + % [y_aux, steady_state_aux] = plot_shock_decomposition(M_,oo_,opts,q2a.aux.y); + % q2a.aux.y=y_aux; + % q2a.aux.yss=steady_state_aux; + % end + if ~(expand && isfield(options_.plot_shock_decomp,'zfull')) + if options_.plot_shock_decomp.interactive && ~isempty(options_.plot_shock_decomp.use_shock_groups) + mygroup = options_.plot_shock_decomp.use_shock_groups; + options_.plot_shock_decomp.use_shock_groups=''; + zafull = ... + annualized_shock_decomposition(oo_,M_, options_, i_var, t0, options_.nobs, realtime_, vintage_, steady_state,q2a); + options_.plot_shock_decomp.use_shock_groups = mygroup; + end + [za, endo_names, endo_names_tex, steady_state, i_var, oo_] = ... + annualized_shock_decomposition(oo_,M_, options_, i_var, t0, options_.nobs, realtime_, vintage_, steady_state,q2a); + end + % if realtime_<2 + % initial_date = initial_date1; + % else + % initial_date = initial_date0; + % end end - - % if isstruct(q2a.aux) && ischar(q2a.aux.y) - % opts=options_; - % opts.plot_shock_decomp.type='qoq'; - % [y_aux, steady_state_aux] = plot_shock_decomposition(M_,oo_,opts,q2a.aux.y); - % q2a.aux.y=y_aux; - % q2a.aux.yss=steady_state_aux; - % end - [za, endo_names, endo_names_tex, steady_state, i_var, oo_] = ... - annualized_shock_decomposition(oo_,M_, options_, i_var, t0, options_.nobs, realtime_, vintage_, steady_state,q2a); - % if realtime_<2 - % initial_date = initial_date1; - % else - % initial_date = initial_date0; - % end end @@ -180,36 +216,26 @@ end if ~expand fig_name = fig_name1; end -gend = size(z,3); if options_.plot_shock_decomp.use_shock_groups - shock_groups = M_.shock_groups.(options_.plot_shock_decomp.use_shock_groups); - shock_ind = fieldnames(shock_groups); - ngroups = length(shock_ind); fig_name=[fig_name ' group ' options_.plot_shock_decomp.use_shock_groups]; - shock_names = shock_ind; - for i=1:ngroups - shock_names{i} = (shock_groups.(shock_ind{i}).label); - end - zz = zeros(endo_nbr,ngroups+2,gend); - kcum=[]; - for i=1:ngroups - for j = shock_groups.(shock_ind{i}).shocks - k = find(strcmp(j,cellstr(M_.exo_names))); - zz(:,i,:) = zz(:,i,:) + z(:,k,:); - z(:,k,:) = 0; - kcum = [kcum k]; + if (expand && isfield(options_.plot_shock_decomp,'zfull')) + z = options_.plot_shock_decomp.zfull; + endo_names = options_.plot_shock_decomp.endo_names; + endo_names_tex = options_.plot_shock_decomp.endo_names_tex; + steady_state=steady_state(i_var); + i_var = 1; + if ~(isequal(type,'aoa') && isstruct(q2a)) + gend = size(z,3); + endo_nbr = size(z,1); + [z, shock_names, M_] = make_the_groups(z,gend,endo_nbr,nshocks,M_,options_); + M_.endo_names = endo_names; + M_.endo_names_tex = endo_names_tex; end + else + gend = size(z,3); + zfull = z; + [z, shock_names, M_] = make_the_groups(z,gend,endo_nbr,nshocks,M_,options_); end - zothers = sum(z(:,1:nshocks,:),2); - shock_groups.(['group' int2str(ngroups+1)]).label = 'Others'; - shock_groups.(['group' int2str(ngroups+1)]).shocks = cellstr(M_.exo_names(find(~ismember([1:M_.exo_nbr],kcum)),:))'; - M_.shock_groups.(options_.plot_shock_decomp.use_shock_groups)=shock_groups; - if any(any(zothers)) - shock_names = [shock_names; {'Others + Initial Values'}]; - end - zz(:,ngroups+1,:) = sum(z(:,1:nshocks+1,:),2); - zz(:,ngroups+2,:) = z(:,nshocks+2,:); - z = zz; else shock_names = M_.exo_names; end @@ -281,6 +307,7 @@ switch type q2a.plot=1; % growth rate end + if ~(expand && isfield(options_.plot_shock_decomp,'zfull')) if isstruct(q2a.aux) && ischar(q2a.aux.y) opts=options_; opts.plot_shock_decomp.type='qoq'; @@ -290,8 +317,19 @@ switch type end [za, endo_names, endo_names_tex, steady_state, i_var, oo_] = ... annualized_shock_decomposition(z,M_, options_, i_var, t0, options_.nobs, realtime_, vintage_, steady_state,q2a); + if options_.plot_shock_decomp.interactive && ~isempty(options_.plot_shock_decomp.use_shock_groups) + mygroup = options_.plot_shock_decomp.use_shock_groups; + options_.plot_shock_decomp.use_shock_groups=''; + zafull = ... + annualized_shock_decomposition(z,M_, options_, i_var, t0, options_.nobs, realtime_, vintage_, steady_state,q2a); + options_.plot_shock_decomp.use_shock_groups = mygroup; + end + end end z = za; + if options_.plot_shock_decomp.interactive && ~isempty(options_.plot_shock_decomp.use_shock_groups) + zfull = zafull; + end M_.endo_names = endo_names; M_.endo_names_tex = endo_names_tex; % endo_nbr = size(z,1); @@ -346,12 +384,49 @@ z = z(:,:,a:b); options_.plot_shock_decomp.fig_name=fig_name; options_.plot_shock_decomp.orig_varlist = varlist; +if options_.plot_shock_decomp.interactive && ~isempty(options_.plot_shock_decomp.use_shock_groups) + options_.plot_shock_decomp.zfull = zfull; +end if detail_plot graph_decomp_detail(z,shock_names,M_.endo_names,i_var,my_initial_date,M_,options_) else graph_decomp(z,shock_names,M_.endo_names,i_var,my_initial_date,M_,options_); end -if write_xls - WriteShockDecomp2Excel(z,shock_names,M_.endo_names,i_var,initial_date,M_,options_,options_.plot_shock_decomp); +if write_xls + WriteShockDecomp2Excel(z,shock_names,M_.endo_names,i_var,my_initial_date,M_,options_,options_.plot_shock_decomp); +end + +end + +function [z, shock_names, M_] = make_the_groups(z,gend,endo_nbr,nshocks,M_,options_) + +shock_groups = M_.shock_groups.(options_.plot_shock_decomp.use_shock_groups); +shock_ind = fieldnames(shock_groups); +ngroups = length(shock_ind); +shock_names = shock_ind; +for i=1:ngroups + shock_names{i} = (shock_groups.(shock_ind{i}).label); +end +zz = zeros(endo_nbr,ngroups+2,gend); +kcum=[]; +for i=1:ngroups + for j = shock_groups.(shock_ind{i}).shocks + k = find(strcmp(j,cellstr(M_.exo_names))); + zz(:,i,:) = zz(:,i,:) + z(:,k,:); + z(:,k,:) = 0; + kcum = [kcum k]; + end +end +zothers = sum(z(:,1:nshocks,:),2); +shock_groups.(['group' int2str(ngroups+1)]).label = 'Others'; +shock_groups.(['group' int2str(ngroups+1)]).shocks = cellstr(M_.exo_names(find(~ismember([1:M_.exo_nbr],kcum)),:))'; +M_.shock_groups.(options_.plot_shock_decomp.use_shock_groups)=shock_groups; +if any(any(zothers)) + shock_names = [shock_names; {'Others + Initial Values'}]; +end +zz(:,ngroups+1,:) = sum(z(:,1:nshocks+1,:),2); +zz(:,ngroups+2,:) = z(:,nshocks+2,:); +z = zz; + end diff --git a/matlab/posterior_sampler_initialization.m b/matlab/posterior_sampler_initialization.m index b8b65e8b8dc6a11a7d63300c99014bea463c109e..d870d737dd4391e2a748fb253b2eefce9e0b2d46 100644 --- a/matlab/posterior_sampler_initialization.m +++ b/matlab/posterior_sampler_initialization.m @@ -366,7 +366,9 @@ elseif options_.mh_recover FirstLine = ones(NumberOfBlocks,1); LastFileFullIndicator=1; end - [d,bayestopt_]=set_proposal_density_to_previous_value(record,options_,bayestopt_); + if ~isequal(options_.posterior_sampler_options.posterior_sampling_method,'slice'), + [d,bayestopt_]=set_proposal_density_to_previous_value(record,options_,bayestopt_); + end %% Now find out what exactly needs to be redone % 1. Check if really something needs to be done % How many mh files should we have ? diff --git a/matlab/set_default_option.m b/matlab/set_default_option.m index 44976a15a1d2e286b7bc70a8a0cf26d3366bf346..371025008467de52d71997774da8b3b41305ca75 100644 --- a/matlab/set_default_option.m +++ b/matlab/set_default_option.m @@ -41,9 +41,13 @@ if isempty(options.(field)) return end +if isdates(options.(field)) + return +end + if isnan(options.(field)) options.(field) = default; return end -% 06/07/03 MJ added ; to eval expression \ No newline at end of file +% 06/07/03 MJ added ; to eval expression diff --git a/matlab/utilities/dataset/quarterly2annual.m b/matlab/utilities/dataset/quarterly2annual.m index 8663a09ff4a086ad37f622fdef5a12a58711cce6..4e8a788203a94044bdbc44adec4a334e8255190a 100644 --- a/matlab/utilities/dataset/quarterly2annual.m +++ b/matlab/utilities/dataset/quarterly2annual.m @@ -125,7 +125,8 @@ switch type end % annual growth rate -gyass = GYTREND0*4; +% gyass = GYTREND0*4; % this is for log diff +gyass = exp(4*GYTREND0)-1; % this is for exact growth rate definition gya = (ya+yass)./(lagged(ya,1)+yass).*exp(4*GYTREND0)-1-gyass; if islog diff --git a/tests/gsa/ls2003a.mod b/tests/gsa/ls2003a.mod index 0bca629a714d98c3bee585f378cf8d74ba4bf8ad..f72476b0cfac9b0e9aaaa5c40e3ff10ffca5cca1 100644 --- a/tests/gsa/ls2003a.mod +++ b/tests/gsa/ls2003a.mod @@ -88,7 +88,7 @@ end; moment_calibration; //y_obs,y_obs, [0.8 1.1]; //[unconditional variance] -y_obs,y_obs(-(1:4)), +; //[first year acf] +y_obs,y_obs(1:4), +; //[first year acf] //y_obs,pie_obs(-4:4), -; //[ccf] @#for ilag in -2:2 y_obs,R_obs(@{ilag}), -; //[ccf]