Set default graph options and extend graph_decomp.m accordingly.
parent
e174d04579
commit
a092cc3b73
|
@ -721,9 +721,15 @@ options_.discretionary_tol = 1e-7;
|
|||
|
||||
% Shock decomposition
|
||||
options_.parameter_set = [];
|
||||
options_.use_shock_groups = [];
|
||||
options_.use_shock_groups = '';
|
||||
options_.colormap = '';
|
||||
options_.shock_decomp.detail_plot=0;
|
||||
options_.shock_decomp.fig_names='';
|
||||
options_.shock_decomp.init_state = 0;
|
||||
options_.shock_decomp.interactive = 0;
|
||||
options_.shock_decomp.steadystate=0;
|
||||
options_.shock_decomp.type = '';
|
||||
options_.shock_decomp.write_xls=0;
|
||||
|
||||
% Nonlinearfilters
|
||||
options_.nonlinear_filter = [];
|
||||
|
|
|
@ -33,12 +33,41 @@ new_colormap = DynareOptions.colormap;
|
|||
% number of components equals number of shocks + 1 (initial conditions)
|
||||
comp_nbr = size(z,2)-1;
|
||||
|
||||
SteadyState=[];
|
||||
% fig_mode='';
|
||||
% fig_mode1='';
|
||||
% fig_names='';
|
||||
% screen_shocks=0;
|
||||
opts_decomp = DynareOptions.shock_decomp;
|
||||
if isfield(opts_decomp,'steady_state')
|
||||
SteadyState = opts_decomp.steady_state;
|
||||
end
|
||||
if isfield(opts_decomp,'fig_mode') && ~isempty(opts_decomp.fig_mode)
|
||||
fig_mode = opts_decomp.fig_mode;
|
||||
fig_mode1 = ['_' fig_mode];
|
||||
fig_mode = [fig_mode '_'];
|
||||
end
|
||||
if isfield(opts_decomp,'fig_names')
|
||||
fig_names = opts_decomp.fig_names;
|
||||
end
|
||||
if isfield(opts_decomp,'screen_shocks')
|
||||
if DynareOptions.use_shock_groups,
|
||||
screen_shocks=0;
|
||||
elseif comp_nbr>18
|
||||
screen_shocks = opts_decomp.screen_shocks;
|
||||
end
|
||||
end
|
||||
if screen_shocks
|
||||
fig_names = [fig_names '_screen'];
|
||||
end
|
||||
|
||||
|
||||
gend = size(z,3);
|
||||
if isempty(initial_date)
|
||||
x = 0:gend;
|
||||
else
|
||||
freq = initial_date.freq;
|
||||
initial_period = initial_date.time(1) + initial_date.time(2)/freq;
|
||||
initial_period = initial_date.time(1) + (initial_date.time(2)-1)/freq;
|
||||
x = initial_period-1/freq:(1/freq):initial_period+(gend-1)/freq;
|
||||
end
|
||||
|
||||
|
@ -46,28 +75,45 @@ nvar = length(i_var);
|
|||
|
||||
%% write LaTeX-Header
|
||||
if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.graph_format)))
|
||||
fidTeX = fopen([DynareModel.fname '_shock_decomp.tex'],'w');
|
||||
fidTeX = fopen([DynareModel.fname '_shock_decomp' fig_mode1 fig_names '.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by Dynare''s graph_decomp.m.\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
|
||||
fprintf(fidTeX,' \n');
|
||||
end
|
||||
|
||||
if ~(screen_shocks && comp_nbr>18),
|
||||
screen_shocks=0;
|
||||
end
|
||||
comp_nbr0=comp_nbr;
|
||||
%%plot decomposition
|
||||
for j=1:nvar
|
||||
z1 = squeeze(z(i_var(j),:,:));
|
||||
if screen_shocks,
|
||||
[junk, isort] = sort(mean(abs(z1(1:end-2,:)')), 'descend');
|
||||
labels = char(char(shock_names(isort(1:16),:)),'Others', 'Initial values');
|
||||
zres = sum(z1(isort(17:end),:),1);
|
||||
z1 = [z1(isort(1:16),:); zres; z1(comp_nbr0:end,:)];
|
||||
comp_nbr=18;
|
||||
func = @(x) colorspace('RGB->Lab',x);
|
||||
new_colormap = distinguishable_colors(size(z1,1)-1,'w',func);
|
||||
new_colormap(end,:) = [0.7 0.7 0.7];
|
||||
else
|
||||
labels = char(char(shock_names),'Initial values');
|
||||
end
|
||||
xmin = x(1);
|
||||
xmax = x(end);
|
||||
ix = z1 > 0;
|
||||
ymax = max(sum(z1.*ix));
|
||||
ix = z1 < 0;
|
||||
ymin = min(sum(z1.*ix));
|
||||
xmax = x(end)+1/freq;
|
||||
ix = z1(1:comp_nbr,:) > 0;
|
||||
ymax = max(sum(z1(1:comp_nbr,:).*ix))*1.1;
|
||||
ix = z1(1:comp_nbr,:) < 0;
|
||||
ymin = min(sum(z1(1:comp_nbr,:).*ix))*1.1;
|
||||
if ymax-ymin < 1e-6
|
||||
continue
|
||||
end
|
||||
fhandle = dyn_figure(DynareOptions,'Name',['Shock decomposition: ',endo_names(i_var(j),:)]);
|
||||
ax=axes('Position',[0.1 0.1 0.6 0.8]);
|
||||
plot(ax,x(2:end),z1(end,:),'k-','LineWidth',2)
|
||||
axis(ax,[xmin xmax ymin ymax]);
|
||||
fhandle = dyn_figure(DynareOptions,'Name',['Shock decomposition: ',endo_names(i_var(j),:)], 'PaperPositionMode', 'auto','PaperOrientation','landscape','renderermode','auto');
|
||||
set(fhandle,'position' ,[50 50 1500 750])
|
||||
ax=axes('Position',[0.1 0.1 0.6 0.8],'box','on');
|
||||
% plot(ax,x(2:end),z1(end,:),'k-','LineWidth',2)
|
||||
% axis(ax,[xmin xmax ymin ymax]);
|
||||
hold on;
|
||||
for i=1:gend
|
||||
i_1 = i-1;
|
||||
|
@ -76,27 +122,47 @@ for j=1:nvar
|
|||
for k = 1:comp_nbr
|
||||
zz = z1(k,i);
|
||||
if zz > 0
|
||||
fill([x(i) x(i) x(i+1) x(i+1)],[yp yp+zz yp+zz yp],k);
|
||||
fill([x(i) x(i) x(i+1) x(i+1)]+(1/freq/2),[yp yp+zz yp+zz yp],k);
|
||||
yp = yp+zz;
|
||||
else
|
||||
fill([x(i) x(i) x(i+1) x(i+1)],[ym ym+zz ym+zz ym],k);
|
||||
fill([x(i) x(i) x(i+1) x(i+1)]+(1/freq/2),[ym ym+zz ym+zz ym],k);
|
||||
ym = ym+zz;
|
||||
end
|
||||
hold on;
|
||||
end
|
||||
end
|
||||
plot(ax,x(2:end),z1(end,:),'k-','LineWidth',2)
|
||||
if ~isempty(SteadyState)
|
||||
if ymin+SteadyState(i_var(j))<0 && ymax+SteadyState(i_var(j))>0,
|
||||
plot(ax,[xmin xmax],SteadyState(i_var(j))*[-1 -1],'k--','linewidth',1)
|
||||
ytick=get(ax,'ytick');
|
||||
ytick1=ytick-SteadyState(i_var(j));
|
||||
ind1=min(find(ytick1>=ymin));
|
||||
ind2=max(find(ytick1<=ymax));
|
||||
dytick=ytick(2)-ytick(1);
|
||||
if ind1>1,
|
||||
ytick1 = [ytick1(ind1:end) ytick1(end)+dytick:dytick:ymax];
|
||||
elseif ind2<length(ytick)
|
||||
ytick1= [sort(ytick1(1)-dytick:-dytick:ymin) ytick1(1:ind2)];
|
||||
end
|
||||
set(ax,'ytick',ytick1),
|
||||
end
|
||||
ylabel = ytick1'+SteadyState(i_var(j));
|
||||
ylabel(abs(ylabel)<eps)=0;
|
||||
set(ax,'yticklabel',num2str(ylabel,'%4.2g'))
|
||||
end
|
||||
set(ax,'xlim',[xmin xmax]);
|
||||
hold off;
|
||||
|
||||
|
||||
axes('Position',[0.75 0.1 0.2 0.8]);
|
||||
axis([0 1 0 1]);
|
||||
axis off;
|
||||
hold on;
|
||||
y1 = 0;
|
||||
height = 1/comp_nbr;
|
||||
labels = char(char(shock_names),'Initial values');
|
||||
|
||||
for i=1:comp_nbr
|
||||
for i=comp_nbr:-1:1
|
||||
% for i=1:comp_nbr
|
||||
fill([0 0 0.2 0.2],[y1 y1+0.7*height y1+0.7*height y1],i);
|
||||
hold on
|
||||
text(0.3,y1+0.3*height,labels(i,:),'Interpreter','none');
|
||||
|
@ -107,12 +173,12 @@ for j=1:nvar
|
|||
if ~isempty(new_colormap)
|
||||
colormap(new_colormap)
|
||||
end
|
||||
dyn_saveas(fhandle,[DynareModel.fname,'_shock_decomposition_',deblank(endo_names(i_var(j),:))],DynareOptions);
|
||||
hold off
|
||||
dyn_saveas(fhandle,[DynareModel.fname,'_shock_decomposition_',fig_mode,deblank(endo_names(i_var(j),:)),fig_names],DynareOptions);
|
||||
if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.graph_format)))
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,['\\includegraphics[width=0.8\\textwidth]{%s_shock_decomposition_%s}\n'],DynareModel.fname,deblank(endo_names(i_var(j),:)));
|
||||
fprintf(fidTeX,['\\includegraphics[width=0.8\\textwidth]{%s_shock_decomposition_%s}\n'],DynareModel.fname,[fig_mode deblank(endo_names(i_var(j),:)) fig_names]);
|
||||
fprintf(fidTeX,'\\label{Fig:shock_decomp:%s}\n',deblank(endo_names(i_var(j),:)));
|
||||
fprintf(fidTeX,'\\caption{Historical shock decomposition: $ %s $}\n',deblank(DynareModel.endo_names_tex(i_var(j),:)));
|
||||
fprintf(fidTeX,'\\end{figure}\n');
|
||||
|
|
Loading…
Reference in New Issue