0001 function plot_ms_irf(M_, options_, irf, figure_name, varlist)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
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
0074 horizon = dims(1);
0075 num_percentiles = 1;
0076 elseif (length(dims) == 3)
0077
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
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