Home > matlab > ms-sbvar > plot_ms_variance_decomposition.m

plot_ms_variance_decomposition

PURPOSE ^

function plot_ms_variance_decomposition(M_, options_, vd, figure_name, varargin)

SYNOPSIS ^

function plot_ms_variance_decomposition(M_, options_, vd, figure_name, varargin)

DESCRIPTION ^

 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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function plot_ms_variance_decomposition(M_, options_, vd, figure_name, varargin)
0002 % function plot_ms_variance_decomposition(M_, options_, vd, figure_name, varargin)
0003 % plot the variance decomposition of shocks
0004 %
0005 % INPUTS
0006 %    M_:          (struct)    model structure
0007 %    options_:    (struct)    options
0008 %    vd:          (matrix)    variance decomposition
0009 %    figure_name: (string)    graph name
0010 %
0011 % OPTIONAL INPUTS
0012 %        'data': the actual data, TxK with K=number of data series
0013 %        'steady': the steady state value, TxK
0014 %        'shock_names': to specify the names of the shocks
0015 %        'series_names': to specify the names of the different series
0016 %        'dates': pass a date vector to use, otherwise will just index on 1:T
0017 %        'colors': Jx3 list of the rgb colors to use for each shock
0018 %
0019 % OUTPUTS
0020 %    none
0021 %
0022 % SPECIAL REQUIREMENTS
0023 %    none
0024 
0025 % Copyright (C) 2011-2012 Dynare Team
0026 %
0027 % This file is part of Dynare.
0028 %
0029 % Dynare is free software: you can redistribute it and/or modify
0030 % it under the terms of the GNU General Public License as published by
0031 % the Free Software Foundation, either version 3 of the License, or
0032 % (at your option) any later version.
0033 %
0034 % Dynare is distributed in the hope that it will be useful,
0035 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0036 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0037 % GNU General Public License for more details.
0038 %
0039 % You should have received a copy of the GNU General Public License
0040 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0041 
0042 if length(size(vd)) == 3
0043     plot_ms_variance_decomposition_error_bands(M_, options_, vd, figure_name);
0044     return;
0045 end
0046 
0047     nvars = M_.endo_nbr;
0048     endo_names = M_.endo_names;
0049 
0050     names = {};
0051     tex_names = {};
0052     m = 1;
0053     for i=1:M_.orig_endo_nbr
0054         tex_name = deblank(M_.endo_names_tex(i,:));
0055         if ~isempty(tex_name)
0056             names{m} = deblank(endo_names(i,:));
0057             tex_names{m} = tex_name;
0058             m = m + 1;
0059         end
0060     end
0061 
0062     dims = size(vd);
0063     if length(dims) == 3
0064         T = dims(1);
0065         K = dims(2);
0066         J = dims(3);
0067         shocks = vd;
0068     else
0069         T = dims(1);
0070         K = nvars;
0071         J = nvars;
0072         temp_vd = zeros(T,K,J);
0073         for i=1:nvars
0074             for j=1:nvars
0075                 temp_vd(:,i,j) = vd(:,((j-1) + ((i-1)*nvars)+1));
0076             end
0077         end
0078         shocks = temp_vd;
0079     end
0080 
0081     for i=1:nvars
0082         shock_names{i} = endo_names(i,:);
0083         series_names{i} = endo_names(i,:);
0084     end
0085 
0086     x = [1:T];
0087     plot_dates = 0;
0088     data = 0;
0089     steady = 0;
0090     colors = [ .1 .1 .75
0091                .8 0 0
0092                1 .7 .25
0093                1 1 0
0094                .5 1 .5
0095                .7 .7 .1
0096                .5 .6 .2
0097                .1 .5 .1];
0098 
0099     % overide the defaults with optional inputs
0100     for i=1:length(varargin)
0101         if strcmpi(varargin{i},'data')
0102             data = varargin{i+1};
0103         elseif strcmpi(varargin{i},'steady')
0104             steady = varargin{i+1};
0105         elseif strcmpi(varargin{i},'shock_names')
0106             shock_names = varargin{i+1};
0107         elseif strcmpi(varargin{i},'series_names')
0108             series_names = varargin{i+1};
0109         elseif strcmpi(varargin{i}, 'dates')
0110             x = varargin{i+1}; plot_dates = 1;
0111         elseif strcmpi(varargin{i},'colors')
0112             colors = varargin{i+1};
0113         end
0114     end
0115 
0116     % add an extra period to the time series
0117     x(T+1) = x(T) + (x(T) - x(T-1));
0118 
0119     figure('Name',figure_name)
0120     for k=1:K
0121         % Go through each series
0122         subplot(K,1,k);
0123         sshocks = shocks(:,k,:);
0124         hold on
0125         % plot the stacked shocks
0126         for t=1:T
0127             % step through each time period
0128             pos_position = 0; neg_position = 0;
0129             xt = [x(t) x(t) x(t+1) x(t+1)];
0130             for j=1:J
0131                 % stack each shock
0132                 st = sshocks(t,1,j);
0133                 if st < 0
0134                     yi = st+neg_position;
0135                     y = [neg_position yi yi neg_position];
0136                     neg_position = yi;
0137                 else
0138                     yi = st+pos_position;
0139                     y = [pos_position yi yi pos_position];
0140                     pos_position = yi;
0141                 end
0142                 fill(xt,y,colors(j,:));
0143                 XY(t,j,:) = y;
0144             end
0145         end
0146         if data
0147             plot(x(2:end)',data(:,k),'k','LineWidth',2.5);
0148         end
0149         if steady
0150             plot(x(2:end)',steady(:,k), '--k','LineWidth',2.25);
0151         end
0152         if k==K
0153             if exist('OCTAVE_VERSION')
0154                 legend(shock_names,'Location','SouthOutside');
0155             else
0156                 legend(shock_names,'Location','BestOutside','Orientation','horizontal');
0157             end
0158         end
0159 
0160         hold off
0161         if plot_dates
0162             datetick 'x';
0163         end
0164         xlim([min(x),max(x)])
0165         ylim([0 , 1])
0166         grid on
0167         title(series_names{k});
0168     end
0169     dyn_save_graph([options_.ms.output_file_tag filesep 'Output' ...
0170         filesep 'Variance_Decomposition'], 'MS-Variance-Decomposition', ...
0171         options_.graph_save_formats, options_.TeX, names, tex_names, ...
0172         'Variance decomposition');
0173 end

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005