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 174 175 176 177 178 179 180 181 182 183 184 185
|
function forecast_graphs(var_list,M_, oo_,options_)
% function forecast_graphs(var_list,M_, oo_,options_)
% Plots the classical forecasts created by dyn_forecast.m
%
% Inputs:
% o var_list character array with variable names
% o M_ model structure
% o oo_ outputs structure
% o options_ options structure
% Copyright (C) 2008-2018 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/>.
nc = 4;
nr = 3;
endo_names = M_.endo_names;
fname = M_.fname;
dname = M_.dname;
yf = oo_.forecast.Mean;
hpdinf = oo_.forecast.HPDinf;
hpdsup = oo_.forecast.HPDsup;
if isempty(var_list)
var_list = endo_names(1:M_.orig_endo_nbr);
end
i_var = [];
for i = 1:length(var_list)
tmp = strmatch(var_list{i}, endo_names, 'exact');
if isempty(tmp)
error([var_list{i} ' isn''t an endogenous variable'])
end
i_var = [i_var; tmp];
end
nvar = length(i_var);
% create subdirectory <dname>/graphs if id doesn't exist
if ~exist(dname, 'dir')
mkdir('.',dname);
end
if ~exist([dname '/graphs'],'dir')
mkdir(dname,'graphs');
end
if options_.TeX && any(strcmp('eps', cellstr(options_.graph_format)))
fidTeX = write_LaTeX_header([M_.dname '/graphs/', fname, '_forcst.tex']);
end
m = 1;
n_fig = 1;
hh = dyn_figure(options_.nodisplay, 'Name', 'Forecasts (I)');
for j= 1:nvar
if m > nc*nr
dyn_saveas(hh,[ dname '/graphs/forcst' int2str(n_fig)], options_.nodisplay, options_.graph_format);
if options_.TeX && any(strcmp('eps', cellstr(options_.graph_format)))
fprintf(fidTeX,'\\begin{figure}[H]\n');
fprintf(fidTeX,'\\centering \n');
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s/graphs/forcst%d}\n',dname,n_fig);
fprintf(fidTeX,'\\label{Fig:forcst:%d}\n',n_fig);
fprintf(fidTeX,'\\caption{Mean forecasts and %2.0f\\%% confidence intervals}\n',options_.forecasts.conf_sig*100);
fprintf(fidTeX,'\\end{figure}\n');
fprintf(fidTeX,' \n');
end
n_fig =n_fig+1;
eval(['hh=dyn_figure(options_.nodisplay,''Name'',''Forecasts (' int2str(n_fig) ')'');']);
m = 1;
end
subplot(nr, nc, m);
vn = endo_names{i_var(j)};
obs = 0;
plot([NaN(obs,1); yf.(vn)],'b-');
hold on
plot([NaN(obs,1); hpdinf.(vn)],'b-');
hold on
plot([NaN(obs,1); hpdsup.(vn)],'b-');
title(vn,'Interpreter','none');
xlim([1 obs+length(hpdsup.(vn))])
hold off
m = m + 1;
end
if m > 1
dyn_saveas(hh,[dname '/graphs/forcst' int2str(n_fig)],options_.nodisplay,options_.graph_format);
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
fprintf(fidTeX,'\\begin{figure}[H]\n');
fprintf(fidTeX,'\\centering \n');
fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s/graphs/forcst%d}\n',dname,n_fig);
fprintf(fidTeX,'\\label{Fig:forcst:%d}\n',n_fig);
fprintf(fidTeX,'\\caption{Mean forecasts and %2.0f\\%% confidence intervals}\n',options_.forecasts.conf_sig*100);
fprintf(fidTeX,'\\end{figure}\n');
fprintf(fidTeX,' \n');
end
end
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
write_LaTeX_footer(fidTeX);
end
if isfield(oo_.forecast,'HPDinf_ME')
var_names=fieldnames(oo_.forecast.HPDinf_ME);
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
fidTeX=write_LaTeX_header([M_.dname '/graphs/',fname,'_forcst_ME.tex']);
end
m = 1;
n_fig = 1;
hh=dyn_figure(options_.nodisplay,'Name','Forecasts including ME (I)');
for j= 1:length(var_names)
if m > nc*nr
dyn_saveas(hh,[ dname '/graphs/forcst_ME' int2str(n_fig)],options_.nodisplay,options_.graph_format);
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
fprintf(fidTeX,'\\begin{figure}[H]\n');
fprintf(fidTeX,'\\centering \n');
fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s/graphs/forcst_ME%d}\n',options_.figures.textwidth*min((m-1)/nc,1),dname,n_fig);
fprintf(fidTeX,'\\label{Fig:forcst_ME:%d}\n',n_fig);
fprintf(fidTeX,'\\caption{Mean forecasts and %2.0f\\%% confidence intervals accounting for measurement error}\n',options_.forecasts.conf_sig*100);
fprintf(fidTeX,'\\end{figure}\n');
fprintf(fidTeX,' \n');
end
n_fig =n_fig+1;
eval(['hh=dyn_figure(options_.nodisplay,''Name'',''Forecasts (' int2str(n_fig) ')'');']);
m = 1;
end
subplot(nr,nc,m);
vn = var_names{j};
obs = 0;
plot([NaN(obs,1); yf.(vn)],'b-');
hold on
plot([NaN(obs,1); oo_.forecast.HPDinf_ME.(vn)],'b-');
hold on
plot([NaN(obs,1); oo_.forecast.HPDsup_ME.(vn)],'b-');
title(vn,'Interpreter','none');
xlim([1 obs+length(oo_.forecast.HPDsup_ME.(vn))])
hold off
m = m + 1;
end
if m > 1
dyn_saveas(hh,[dname '/graphs/forcst_ME' int2str(n_fig)],options_.nodisplay,options_.graph_format);
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
fprintf(fidTeX,'\\begin{figure}[H]\n');
fprintf(fidTeX,'\\centering \n');
fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s/graphs/forcst_ME%d}\n',options_.figures.textwidth*min((m-1)/nc,1),dname,n_fig);
fprintf(fidTeX,'\\label{Fig:forcst_ME:%d}\n',n_fig);
fprintf(fidTeX,'\\caption{Mean forecasts and %2.0f\\%% confidence intervals accounting for measurement error}\n',options_.forecasts.conf_sig*100);
fprintf(fidTeX,'\\end{figure}\n');
fprintf(fidTeX,' \n');
end
end
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
write_LaTeX_footer(fidTeX);
end
end
function fidTeX=write_LaTeX_header(fname)
%% write LaTeX-Header
fidTeX = fopen(fname,'w');
fprintf(fidTeX,'%% TeX eps-loader file generated by Dynare''s forecast_graphs.m.\n');
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
fprintf(fidTeX,' \n');
function write_LaTeX_footer(fidTeX)
%% write LaTeX-Footer
fprintf(fidTeX,' \n');
fprintf(fidTeX,'%% End of TeX file.\n');
fclose(fidTeX);
|