Home > matlab > ms-sbvar > plot_ms_irf.m

plot_ms_irf

PURPOSE ^

function plot_ms_irf(M_, options_, irf, figure_name, varlist)

SYNOPSIS ^

function plot_ms_irf(M_, options_, irf, figure_name, varlist)

DESCRIPTION ^

 function plot_ms_irf(M_, options_, irf, figure_name, varlist)
 plots the impulse responses from the output from a ms-sbvar

 INPUTS
    M_:          (struct)    model structure
    options_:    (struct)    options
    irf:         (matrix)    in the form (percentile x horizon x (nvar x nvar)), if banded otherwise
                             ( horizon x (nvar x nvar) )
    figure_name: (string)    title

 OUTPUTS
    none

 SPECIAL REQUIREMENTS
    none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function plot_ms_irf(M_, options_, irf, figure_name, varlist)
0002 % function plot_ms_irf(M_, options_, irf, figure_name, varlist)
0003 % plots the impulse responses from the output from a ms-sbvar
0004 %
0005 % INPUTS
0006 %    M_:          (struct)    model structure
0007 %    options_:    (struct)    options
0008 %    irf:         (matrix)    in the form (percentile x horizon x (nvar x nvar)), if banded otherwise
0009 %                             ( horizon x (nvar x nvar) )
0010 %    figure_name: (string)    title
0011 %
0012 % OUTPUTS
0013 %    none
0014 %
0015 % SPECIAL REQUIREMENTS
0016 %    none
0017 
0018 % Copyright (C) 2011-2012 Dynare Team
0019 %
0020 % This file is part of Dynare.
0021 %
0022 % Dynare is free software: you can redistribute it and/or modify
0023 % it under the terms of the GNU General Public License as published by
0024 % the Free Software Foundation, either version 3 of the License, or
0025 % (at your option) any later version.
0026 %
0027 % Dynare is distributed in the hope that it will be useful,
0028 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0029 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0030 % GNU General Public License for more details.
0031 %
0032 % You should have received a copy of the GNU General Public License
0033 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0034 
0035     if nargin < 4
0036         figure_name = '';
0037     end
0038 
0039     nvars = M_.endo_nbr;
0040     endo_names = M_.endo_names;
0041 
0042     if isempty(varlist)
0043         var_list = endo_names(1:M_.orig_endo_nbr,:);
0044     end
0045 
0046     names = {};
0047     tex_names = {};
0048     m = 1;
0049     for i = 1:size(var_list)
0050         tmp = strmatch(var_list(i,:),endo_names,'exact');
0051         if isempty(tmp)
0052             error([var_list(i,:) ' isn''t and endogenous variable'])
0053         end
0054         tex_name = deblank(M_.endo_names_tex(tmp,:));
0055         if ~isempty(tex_name)
0056             names{m} = deblank(var_list(i,:));
0057             tex_names{m} = tex_name;
0058             m = m + 1;
0059         end
0060     end
0061 
0062     for i=1:M_.exo_nbr
0063         tex_name = deblank(M_.exo_names_tex(i,:));
0064         if ~isempty(tex_name)
0065             names{m} = deblank(M_.exo_names(i,:));
0066             tex_names{m} = tex_name;
0067             m = m + 1;
0068         end
0069     end
0070 
0071     dims = size(irf);
0072     if (length(dims) == 2)
0073         % Point IRF (horizon x (nvarsxnvars) )
0074         horizon = dims(1);
0075         num_percentiles = 1;
0076     elseif (length(dims) == 3)
0077         % Banded IRF
0078         horizon = dims(2);
0079         num_percentiles = dims(1);
0080     else
0081         error('The impulse response matrix passed to be plotted does not appear to be the correct size');
0082     end
0083 
0084     if size(endo_names,1) ~= nvars
0085         error('The names passed are not the same length as the number of variables');
0086     end
0087 
0088     if num_percentiles == 1
0089         % loop through the shocks
0090         for s=1:nvars
0091             shock = zeros(horizon,nvars);
0092             for i=1:nvars
0093                 shock(:,i) = irf(:,((i-1) + ((s-1)*nvars)+1));
0094             end
0095             plot_point_irf_for_shock(shock, nvars,endo_names, deblank(endo_names(s,:)), ...
0096                 figure_name, [options_.ms.output_file_tag filesep 'Output' filesep 'IRF'], options_, names, tex_names);
0097         end
0098     else
0099         for s=1:nvars
0100             shock = zeros(horizon,nvars,num_percentiles);
0101             for n=1:num_percentiles
0102                 for i=1:nvars
0103                     shock(:,i,n) = irf(n,:,((i-1) + ((s-1)*nvars)+1));
0104                 end
0105             end
0106             plot_banded_irf_for_shock(shock, nvars,endo_names, deblank(endo_names(s,:)), ...
0107                 figure_name, [options_.ms.output_file_tag filesep 'Output' filesep 'IRF'], options_, names, tex_names);
0108         end
0109     end
0110 end
0111 
0112 function [fig] = plot_point_irf_for_shock(irf,nvars,endo_names,shock_name,figure_name,dirname,options_,names,tex_names)
0113     fig = figure('Name',figure_name);
0114     for k=1:nvars
0115         subplot(ceil(sqrt(nvars)), ceil(sqrt(nvars)),k);
0116         plot(irf(:,k))
0117         disp([endo_names(k,:) ' shock from ' shock_name]);
0118         title([endo_names(k,:) ' shock from ' shock_name]);
0119     end
0120     dyn_save_graph(dirname,[figure_name ' ' shock_name],options_.graph_save_formats, ...
0121                    options_.TeX,names,tex_names,[figure_name ' ' shock_name]);
0122 end
0123 
0124 function [fig] = plot_banded_irf_for_shock(irf,nvars, endo_names, shock_name,figure_name,dirname,options_,names,tex_names)
0125     fig = figure('Name',figure_name);
0126     npercentiles = size(irf,3);
0127     for k=1:nvars
0128         subplot(ceil(sqrt(nvars)), ceil(sqrt(nvars)),k);
0129         for nn=1:npercentiles
0130             plot(irf(:,k,nn))
0131             hold on
0132         end
0133         hold off
0134         disp([endo_names(k,:) ' shock from ' shock_name]);
0135         title([endo_names(k,:) ' shock from ' shock_name]);
0136     end
0137     dyn_save_graph(dirname,[figure_name ' ' shock_name],options_.graph_save_formats, ...
0138                    options_.TeX,names,tex_names,[figure_name ' ' shock_name]);
0139 end

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