Cosmetic changes and fixed cell/chararray issues.

time-shift
Stéphane Adjemian (Charybdis) 2018-01-10 15:34:58 +01:00
parent f4b25efc5a
commit f4867d30b1
3 changed files with 35 additions and 64 deletions

View File

@ -23,8 +23,8 @@ function [z, endo_names, endo_names_tex, steady_state, i_var, oo_] = annualized_
%
% OUTPUTS
% z: [matrix] shock decomp to plot
% endo_names: [char] updated var names
% endo_names_tex: [char] updated TeX var names
% endo_names: [cell] updated var names
% endo_names_tex: [cell] updated TeX var names
% steady_state: [array] updated stady state of vars
% i_var: [integer array] updated var indices to plot
% oo_: [structure] Storage of results
@ -92,21 +92,21 @@ end
for j=1:nvar
if j>1
endo_names = char(endo_names, sprintf('%s_A', M_.endo_names{i_var(j)}));
endo_names_tex = char(endo_names_tex, sprintf('{%s}^A', M_.endo_names_tex{i_var(j)}));
gendo_names = char(gendo_names,[gtxt endo_names{j}]);
gendo_names_tex = char(gendo_names_tex,[gtex '(' endo_names_tex{j} ')']);
endo_names = vertcat(endo_names, sprintf('%s_A', M_.endo_names{i_var(j)}));
endo_names_tex = vertcat(endo_names_tex, sprintf('{%s}^A', M_.endo_names_tex{i_var(j)}));
gendo_names = vertcat(gendo_names,[gtxt endo_names{j}]);
gendo_names_tex = vertcat(gendo_names_tex,[gtex '(' endo_names_tex{j} ')']);
else
if nvar==1 && ~mytype
endo_names = mytxt;
endo_names_tex = mytex;
gendo_names = gtxt;
gendo_names_tex = gtex;
endo_names = {mytxt};
endo_names_tex = {mytex};
gendo_names = {gtxt};
gendo_names_tex = {gtex};
else
endo_names = sprintf('%s_A', M_.endo_names{i_var(j)});
endo_names_tex = sprintf('{%s}^A', M_.endo_names_tex{i_var(j)});
gendo_names = [gtxt endo_names{j}];
gendo_names_tex = [gtex '(' endo_names_tex{j} ')'];
endo_names = {sprintf('%s_A', M_.endo_names{i_var(j)})};
endo_names_tex = {sprintf('{%s}^A', M_.endo_names_tex{i_var(j)})};
gendo_names = {[gtxt endo_names{j}]};
gendo_names_tex = {[gtex '(' endo_names_tex{j} ')']};
end
end
end
@ -115,8 +115,8 @@ if q2a.plot ==1
endo_names = gendo_names;
endo_names_tex = gendo_names_tex;
elseif q2a.plot ~= 2
endo_names = char(endo_names,gendo_names);
endo_names_tex = char(endo_names_tex,gendo_names_tex);
endo_names = vertcat(endo_names,gendo_names);
endo_names_tex = vertcat(endo_names_tex,gendo_names_tex);
end
% end initialize names
@ -133,26 +133,20 @@ if realtime_==0
z = oo_;
end
z = z(i_var,:,:);
if isstruct(aux)
if ischar(aux.y)
myopts=options_;
myopts.plot_shock_decomp.type='qoq';
myopts.plot_shock_decomp.realtime=0;
[y_aux, steady_state_aux] = plot_shock_decomposition(M_,oo_,myopts,aux.y);
aux.y=y_aux;
aux.yss=steady_state_aux;
if isstruct(aux)
if ischar(aux.y)
myopts=options_;
myopts.plot_shock_decomp.type='qoq';
myopts.plot_shock_decomp.realtime=0;
[y_aux, steady_state_aux] = plot_shock_decomposition(M_,oo_,myopts,aux.y);
aux.y=y_aux;
aux.yss=steady_state_aux;
end
end
end
steady_state=steady_state(i_var);
% endo_names = M_.endo_names(i_var,:);
% endo_names_tex = M_.endo_names_tex(i_var,:);
steady_state=steady_state(i_var);
% make annualized shock decomp
[z, steady_state_a, steady_state_ga] = annualiz(z,t0,q2a,aux,steady_state);
end
% if isstruct(oo_)
% oo_.annualized_shock_decomposition=z;
% end
% realtime
if realtime_ && isstruct(oo_) && isfield(oo_, 'realtime_shock_decomposition')
@ -163,7 +157,6 @@ if realtime_ && isstruct(oo_) && isfield(oo_, 'realtime_shock_decomposition')
myopts.plot_shock_decomp.type='qoq';
myopts.plot_shock_decomp.realtime=1;
myopts.plot_shock_decomp.vintage=i;
% retrieve quarterly shock decomp
z = plot_shock_decomposition(M_,oo_,myopts,[]);
zdim = size(z);
@ -176,7 +169,7 @@ if realtime_ && isstruct(oo_) && isfield(oo_, 'realtime_shock_decomposition')
aux.yss=steady_state_aux;
end
end
% make annualized shock decomp
[z, steady_state_a, steady_state_ga] = annualiz(z,t0,q2a,aux,steady_state);
@ -203,10 +196,10 @@ if realtime_ && isstruct(oo_) && isfield(oo_, 'realtime_shock_decomposition')
aux.yss=steady_state_aux;
end
end
% make annualized shock decomp
z = annualiz(z,t0,q2a,aux,steady_state);
end
oo_.annualized_realtime_forecast_shock_decomposition.(['yr_' int2str(yr)]) = z(:,:,end-nfrcst:end);
if init>nfrcst

View File

@ -44,14 +44,7 @@ endo_nbr = M_.endo_nbr;
% number of shocks
nshocks = M_.exo_nbr;
% type = '';
fig_name='';
% detail_plot=0;
% realtime_=0; % 0 is standard; 1 is realtime (pool/vintage); 2 is conditional (pool/vintage); 3 is forecast (pool/vintage)
% vintage_=0; % 0 pool realtime/conditional; int: forecast/conditional shock decompositions
% forecast_=0;
% steadystate=0;
% write_xls=0;
if isfield(options_.plot_shock_decomp,'expand') % private trap for uimenu calls
expand=options_.plot_shock_decomp.expand;
@ -134,9 +127,9 @@ steady_state = oo_.steady_state;
if isequal(type,'aoa') && isstruct(q2a) && realtime_
% take all dates where realtime is saved
qqq=options_.initial_date+options_.shock_decomp.save_realtime(:)-1;
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));
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
@ -158,25 +151,10 @@ if isequal(type,'aoa') && isstruct(q2a) && realtime_
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
[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
if ~expand
fig_name = fig_name1;
end
@ -301,7 +279,7 @@ switch type
initial_date = initial_date0;
end
else
% this is for quarterly-annualized variables already defined in model, so we can just take Q4
% this is for quarterly-annualized variables already defined in model, so we can just take Q4
t0=4-initial_date.time(2)+1;
initial_date = initial_date0;
z=z(:,:,t0:4:end);

View File

@ -110,7 +110,7 @@ if fast_realtime
fprintf(['%s'],newString);
options_.nobs=fast_realtime;
[oo0,M_,junk1,junk2,Smoothed_Variables_deviation_from_mean0] = evaluate_smoother(parameter_set,varlist,M_,oo_,options_,bayestopt_,estim_params_);
gend0 = size(oo0.SmoothedShocks.(deblank(M_.exo_names(1,:))),1);
gend0 = size(oo0.SmoothedShocks.(M_.exo_names{1}),1);
prctdone=0.5;
if isoctave
printf([running_text,' %3.f%% done\r'], prctdone*100);
@ -121,7 +121,7 @@ if fast_realtime
end
options_.nobs=nobs;
[oo2,M_,junk1,junk2,Smoothed_Variables_deviation_from_mean2] = evaluate_smoother(parameter_set,varlist,M_,oo_,options_,bayestopt_,estim_params_);
gend2 = size(oo2.SmoothedShocks.(deblank(M_.exo_names(1,:))),1);
gend2 = size(oo2.SmoothedShocks.(M_.exo_names{1}),1);
prctdone=1;
if isoctave
printf([running_text,' %3.f%% done\r'], prctdone*100);
@ -143,7 +143,7 @@ for j=presample+1:nobs
options_.nobs=j;
if ~fast_realtime
[oo,M_,junk1,junk2,Smoothed_Variables_deviation_from_mean] = evaluate_smoother(parameter_set,varlist,M_,oo_,options_,bayestopt_,estim_params_);
gend = size(oo.SmoothedShocks.(deblank(M_.exo_names(1,:))),1);
gend = size(oo.SmoothedShocks.(M_.exo_names{1}),1);
else
gend = gend0+j-fast_realtime;
if j>fast_realtime