1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
function plot_ms_variance_decomposition(M_, options_, vd, figure_name, varargin)
% function plot_ms_variance_decomposition(M_, options_, vd, figure_name, varargin)
% plot the variance decomposition of shocks
%
% INPUTS
% M_: (struct) model structure
% options_: (struct) options
% vd: (matrix) variance decomposition
% figure_name: (string) graph name
%
% OPTIONAL INPUTS
% 'data': the actual data, TxK with K=number of data series
% 'steady': the steady state value, TxK
% 'shock_names': to specify the names of the shocks
% 'series_names': to specify the names of the different series
% 'dates': pass a date vector to use, otherwise will just index on 1:T
% 'colors': Jx3 list of the rgb colors to use for each shock
%
% OUTPUTS
% none
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2011-2017 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if length(size(vd)) == 3
plot_ms_variance_decomposition_error_bands(M_, options_, vd, figure_name);
return;
end
nvars = M_.endo_nbr;
endo_names = M_.endo_names;
names = {};
tex_names = {};
m = 1;
for i=1:M_.orig_endo_nbr
tex_name = deblank(M_.endo_names_tex(i,:));
if ~isempty(tex_name)
names{m} = deblank(endo_names(i,:));
tex_names{m} = tex_name;
m = m + 1;
end
end
dims = size(vd);
if length(dims) == 3
T = dims(1);
K = dims(2);
J = dims(3);
shocks = vd;
else
T = dims(1);
K = nvars;
J = nvars;
temp_vd = zeros(T,K,J);
for i=1:nvars
for j=1:nvars
temp_vd(:,i,j) = vd(:,((j-1) + ((i-1)*nvars)+1));
end
end
shocks = temp_vd;
end
for i=1:nvars
shock_names{i} = endo_names(i,:);
series_names{i} = endo_names(i,:);
end
x = [1:T];
plot_dates = 0;
data = 0;
steady = 0;
colors = [ .1 .1 .75
.8 0 0
1 .7 .25
1 1 0
.5 1 .5
.7 .7 .1
.5 .6 .2
.1 .5 .1];
% overide the defaults with optional inputs
for i=1:length(varargin)
if strcmpi(varargin{i},'data')
data = varargin{i+1};
elseif strcmpi(varargin{i},'steady')
steady = varargin{i+1};
elseif strcmpi(varargin{i},'shock_names')
shock_names = varargin{i+1};
elseif strcmpi(varargin{i},'series_names')
series_names = varargin{i+1};
elseif strcmpi(varargin{i}, 'dates')
x = varargin{i+1}; plot_dates = 1;
elseif strcmpi(varargin{i},'colors')
colors = varargin{i+1};
end
end
% add an extra period to the time series
x(T+1) = x(T) + (x(T) - x(T-1));
figure('Name',figure_name)
for k=1:K
% Go through each series
subplot(K,1,k);
sshocks = shocks(:,k,:);
hold on
% plot the stacked shocks
for t=1:T
% step through each time period
pos_position = 0; neg_position = 0;
xt = [x(t) x(t) x(t+1) x(t+1)];
for j=1:J
% stack each shock
st = sshocks(t,1,j);
if st < 0
yi = st+neg_position;
y = [neg_position yi yi neg_position];
neg_position = yi;
else
yi = st+pos_position;
y = [pos_position yi yi pos_position];
pos_position = yi;
end
fill(xt,y,colors(j,:));
XY(t,j,:) = y;
end
end
if data
plot(x(2:end)',data(:,k),'k','LineWidth',2.5);
end
if steady
plot(x(2:end)',steady(:,k), '--k','LineWidth',2.25);
end
if k==K
if isoctave
legend(shock_names,'Location','SouthOutside');
else
legend(shock_names,'Location','BestOutside','Orientation','horizontal');
end
end
hold off
if plot_dates
datetick 'x';
end
xlim([min(x),max(x)])
ylim([0 , 1])
grid on
title(series_names{k});
end
dyn_save_graph([options_.ms.output_file_tag filesep 'Output' ...
filesep 'Variance_Decomposition'], 'MS-Variance-Decomposition', ...
options_.graph_save_formats, options_.TeX, names, tex_names, ...
'Variance decomposition');
end
|