Home > matlab > ms-sbvar > plot_ms_forecast.m

plot_ms_forecast

PURPOSE ^

function plot_ms_forecast(M_, options_, forecast, figure_name)

SYNOPSIS ^

function plot_ms_forecast(M_, options_, forecast, figure_name)

DESCRIPTION ^

 function plot_ms_forecast(M_, options_, forecast, figure_name)
 plots the forecast from the output from a ms-sbvar

 INPUTS
    M_:          (struct)    model structure
    options_:    (struct)    options
    forecast:    (matrix)    in the form (percentile x horizon x nvar ), if banded otherwise
                             ( horizon 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_forecast(M_, options_, forecast, figure_name)
0002 % function plot_ms_forecast(M_, options_, forecast, figure_name)
0003 % plots the forecast from the output from a ms-sbvar
0004 %
0005 % INPUTS
0006 %    M_:          (struct)    model structure
0007 %    options_:    (struct)    options
0008 %    forecast:    (matrix)    in the form (percentile x horizon x nvar ), if banded otherwise
0009 %                             ( horizon 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     nc = 2;
0036     nr = 2;
0037     nvars = M_.endo_nbr;
0038     endo_names = M_.endo_names;
0039     var_list = endo_names(1:M_.orig_endo_nbr,:);
0040     names = {};
0041     tex_names = {};
0042     m = 1;
0043     for i = 1:size(var_list)
0044         tmp = strmatch(var_list(i,:),endo_names,'exact');
0045         if isempty(tmp)
0046             error([var_list(i,:) ' isn''t and endogenous variable'])
0047         end
0048         tex_name = deblank(M_.endo_names_tex(i,:));
0049         if ~isempty(tex_name)
0050             names{m} = deblank(var_list(i,:));
0051             tex_names{m} = tex_name;
0052             m = m + 1;
0053         end
0054     end
0055 
0056     dims = size(forecast);
0057     if (length(dims) == 2)
0058         % Point Forecast (horizon x nvars )
0059         horizon = dims(1);
0060         num_percentiles = 1;
0061     elseif (length(dims) == 3)
0062         % Banded Forecast
0063         horizon = dims(2);
0064         num_percentiles = dims(1);
0065     else
0066         error('The impulse response matrix passed to be plotted does not appear to be the correct size');
0067     end
0068 
0069     if num_percentiles == 1
0070         plot_point_forecast(forecast, nvars, nr, nc, var_list, figure_name, ...
0071             options_.graph_save_formats, options_.TeX, names, tex_names, ...
0072             [options_.ms.output_file_tag filesep 'Output' filesep 'Forecast']);
0073     else
0074         plot_banded_forecast(forecast, nvars, nr, nc, var_list, num_percentiles, ...
0075             figure_name, options_.graph_save_formats, options_.TeX, names, tex_names, ...
0076             [options_.ms.output_file_tag filesep 'Output' filesep 'Forecast']);
0077     end
0078 
0079 end
0080 
0081 function plot_point_forecast(forecast,nvars,nr,nc,endo_names,figure_name,save_graph_formats,TeX,names,tex_names,dirname)
0082     if nvars > nr*nc
0083         graph_name = ['MS (1) ' figure_name];
0084         figure('Name', graph_name);
0085     else
0086         graph_name = figure_name;
0087         figure('Name', graph_name);
0088     end
0089     m = 1;
0090     n_fig = 1;
0091     for j=1:nvars
0092         if m > nr*nc
0093             graph_name = ['MS (' int2str(n_fig) ') ' figure_name];
0094             dyn_save_graph(dirname,['MS-forecast-' int2str(n_fig)],...
0095                            save_graph_formats,TeX,names,tex_names,graph_name);
0096             n_fig =n_fig+1;
0097             figure('Name', graph_name);
0098             m = 1;
0099         end
0100         subplot(nr,nc,m);
0101         vn = deblank(endo_names(j,:));
0102         plot(forecast(:,j))
0103         title(vn,'Interpreter','none');
0104         grid on;
0105         m = m+1;
0106     end
0107     if m > 1
0108         dyn_save_graph(dirname,['MS-forecast-' int2str(n_fig)],...
0109                        save_graph_formats,TeX,names,tex_names,graph_name);
0110     end
0111 end
0112 
0113 function plot_banded_forecast(forecast,nvars,nr,nc,endo_names,num_percentiles,figure_name,save_graph_formats,TeX,names,tex_names,dirname)
0114     if nvars > nr*nc
0115         graph_name = ['MS (1) ' figure_name];
0116         figure('Name', graph_name);
0117     else
0118         graph_name = figure_name;
0119         figure('Name', graph_name);
0120     end
0121     m = 1;
0122     n_fig = 1;
0123     for j=1:nvars
0124         if m > nr*nc
0125             graph_name = ['MS (' int2str(n_fig) ') ' figure_name];
0126             dyn_save_graph(dirname,['MS-forecast-' int2str(n_fig)],...
0127                            save_graph_formats,TeX,names,tex_names,graph_name);
0128             n_fig =n_fig+1;
0129             figure('Name',graph_name);
0130             m = 1;
0131         end
0132         subplot(nr,nc,m);
0133         vn = deblank(endo_names(j,:));
0134         for k=1:num_percentiles
0135             if ceil(num_percentiles/2) == k
0136                 plot(forecast(k,:,j),'LineWidth',1.5)
0137             else
0138                 plot(forecast(k,:,j),'LineWidth',1.1)
0139             end
0140             if k==1
0141                 hold on;
0142             end
0143         end
0144         title(vn,'Interpreter','none');
0145         hold off
0146         grid on;
0147         m = m+1;
0148     end
0149     if m > 1
0150         dyn_save_graph(dirname,['MS-forecast-' int2str(n_fig)],...
0151                        save_graph_formats,TeX,names,tex_names,graph_name);
0152     end
0153 end

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