Commit ad580b8c authored by Houtan Bastani's avatar Houtan Bastani
Browse files

MS-SBVAR: clean up plotting functions

parent d2127722
......@@ -87,6 +87,7 @@ if options_.ms.regimes
end
for regime_i=1:n_regimes
forecast_title = ['Forecast, Regimes ' num2str(regime_i)];
forecast_data = load([forecastdir filesep 'forecasts_percentiles_regime_' ...
num2str(regime_i-1) '_' options_.ms.output_file_tag ...
'.out'], '-ascii');
......@@ -94,9 +95,7 @@ if options_.ms.regimes
percentiles_size, options_.ms.horizon, forecast_data);
save([forecastdir filesep 'forecast_regime_' num2str(regime_i-1)], ...
'forecast_data');
plot_ms_forecast(M_, options_, forecast_data, ...
['Forecast, Regimes' num2str(regime_i)], ...
options_.graph_save_formats, options_.TeX);
plot_ms_forecast(M_, options_, forecast_data, forecast_title);
end
else
if options_.ms.regime
......@@ -115,7 +114,6 @@ else
forecast_data = reshape_ascii_forecast_data(M_.endo_nbr, ...
percentiles_size, options_.ms.horizon, forecast_data);
save([forecastdir filesep save_filename], 'forecast_data');
plot_ms_forecast(M_, options_, forecast_data, forecast_title, ...
options_.graph_save_formats, options_.TeX);
plot_ms_forecast(M_, options_, forecast_data, forecast_title);
end
end
......@@ -89,14 +89,14 @@ if options_.ms.regimes
end
for regime_i=1:n_regimes
irf_title = ['Impulse Responses, Regime ' num2str(regime_i)];
irf_data = load([irfdir filesep 'ir_percentiles_regime_' ...
num2str(regime_i-1) '_' options_.ms.output_file_tag ...
'.out'], '-ascii');
irf_data = reshape_ascii_irf_data(M_.endo_nbr, percentiles_size, ...
options_.ms.horizon, irf_data);
save([irfdir filesep 'irf_regime_' num2str(regime_i-1)], 'irf_data');
plot_ms_irf(M_, options_, irf_data, ...
['Impulse Responses, Regime ' num2str(regime_i)], varlist);
plot_ms_irf(M_, options_, irf_data, irf_title, varlist);
end
else
if options_.ms.regime
......
......@@ -100,16 +100,14 @@ if options_.ms.regimes
for i_chain=1:n_chains
n_regimes = n_regimes*length(options_.ms.ms_chain(i_chain).regime);
end
for regime_i=1:n_regimes
vd_title = ['Variance Decomposition, Regime ' num2str(regime_i)];
vd_data = load([outfile num2str(regime_i-1) '_' ...
options_.ms.output_file_tag '.out'], '-ascii');
vd_data = reshape_ascii_variance_decomposition_data( ...
M_.endo_nbr, percentiles_size, options_.ms.horizon, vd_data);
save([vddir filesep 'variance_decomposition_regime_' num2str(regime_i-1)], 'vd_data');
plot_ms_variance_decomposition(M_, options_, vd_data, ...
['Variance Decomposition, Regime ' num2str(regime_i)], ...
options_.graph_save_formats, options_.TeX);
plot_ms_variance_decomposition(M_, options_, vd_data, vd_title);
end
else
if options_.ms.regime
......@@ -127,7 +125,6 @@ else
vd_data = reshape_ascii_variance_decomposition_data( ...
M_.endo_nbr, percentiles_size, options_.ms.horizon, vd_data);
save([vddir filesep save_filename], 'vd_data');
plot_ms_variance_decomposition(M_, options_, vd_data, ...
vd_title, options_.graph_save_formats, options_.TeX);
plot_ms_variance_decomposition(M_, options_, vd_data, vd_title);
end
end
function plot_ms_forecast(M_,options_,forecast,title_,save_graph_formats,TeX)
% function plot_ms_forecast(M_,options_,forecast,title_,save_graph_formats,TeX)
function plot_ms_forecast(M_, options_, forecast, figure_name)
% function plot_ms_forecast(M_, options_, forecast, figure_name)
% plots the forecast from the output from a ms-sbvar
%
% INPUTS
% M_
% forecast should be in the form (percentile x horizon x nvar ), if banded otherwise
% ( horizon x nvar )
% 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
%
% title: title
% OUTPUTS
% none
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2011-2012 Dynare Team
%
......@@ -62,34 +67,34 @@ function plot_ms_forecast(M_,options_,forecast,title_,save_graph_formats,TeX)
end
if num_percentiles == 1
plot_point_forecast(forecast, nvars, nr, nc, var_list, title_, ...
save_graph_formats, TeX, names, tex_names, ...
plot_point_forecast(forecast, nvars, nr, nc, var_list, figure_name, ...
options_.graph_save_formats, options_.TeX, names, tex_names, ...
[options_.ms.output_file_tag filesep 'Output' filesep 'Forecast']);
else
plot_banded_forecast(forecast, nvars, nr, nc, var_list, num_percentiles, ...
title_, save_graph_formats, TeX, names, tex_names, ...
figure_name, options_.graph_save_formats, options_.TeX, names, tex_names, ...
[options_.ms.output_file_tag filesep 'Output' filesep 'Forecast']);
end
end
function plot_point_forecast(forecast,nvars,nr,nc,endo_names,title_,save_graph_formats,TeX,names,tex_names,dirname)
function plot_point_forecast(forecast,nvars,nr,nc,endo_names,figure_name,save_graph_formats,TeX,names,tex_names,dirname)
if nvars > nr*nc
graph_name = 'MS-Forecast (1)';
fig = figure('Name','Forecast (I)');
graph_name = ['MS (1) ' figure_name];
figure('Name', graph_name);
else
graph_name = 'MS-Forecast';
fig = figure('Name','Forecast');
graph_name = figure_name;
figure('Name', graph_name);
end
m = 1;
n_fig = 1;
for j=1:nvars
if m > nr*nc
graph_name = ['MS-Forecast (' int2str(n_fig) ')'];
graph_name = ['MS (' int2str(n_fig) ') ' figure_name];
dyn_save_graph(dirname,['MS-forecast-' int2str(n_fig)],...
save_graph_formats,TeX,names,tex_names,graph_name);
n_fig =n_fig+1;
figure('Name',['MS-Forecast (' int2str(n_fig) ')']);
figure('Name', graph_name);
m = 1;
end
subplot(nr,nc,m);
......@@ -105,19 +110,19 @@ function plot_point_forecast(forecast,nvars,nr,nc,endo_names,title_,save_graph_f
end
end
function plot_banded_forecast(forecast,nvars,nr,nc,endo_names,num_percentiles,title_,save_graph_formats,TeX,names,tex_names,dirname)
function plot_banded_forecast(forecast,nvars,nr,nc,endo_names,num_percentiles,figure_name,save_graph_formats,TeX,names,tex_names,dirname)
if nvars > nr*nc
graph_name = 'MS-Forecast (1)';
fig = figure('Name','Forecast (I)');
graph_name = ['MS (1) ' figure_name];
figure('Name', graph_name);
else
graph_name = 'MS-Forecast';
fig = figure('Name','Forecast');
graph_name = figure_name;
figure('Name', graph_name);
end
m = 1;
n_fig = 1;
for j=1:nvars
if m > nr*nc
graph_name = ['MS-Forecast (' int2str(n_fig) ')'];
graph_name = ['MS (' int2str(n_fig) ') ' figure_name];
dyn_save_graph(dirname,['MS-forecast-' int2str(n_fig)],...
save_graph_formats,TeX,names,tex_names,graph_name);
n_fig =n_fig+1;
......
function plot_ms_irf(M_, options_, irf, title_, varlist)
% function plot_ms_irf(M_, options_, irf, title_, varlist)
function plot_ms_irf(M_, options_, irf, figure_name, varlist)
% function plot_ms_irf(M_, options_, irf, figure_name, varlist)
% plots the impulse responses from the output from a ms-sbvar
%
% INPUTS
% M_
% irf should be in the form (percentile x horizon x (nvar x nvar)), if banded otherwise
% ( horizon x (nvar x nvar) )
% title: optional super title
% 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
%
% The element in position (k,i+j*nvars) of ir is the response of the ith
% variable to the jth shock at horizon k. Horizon 0 is the contemporaneous
% response.
% OUTPUTS
% none
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2011-2012 Dynare Team
%
......@@ -30,7 +33,7 @@ function plot_ms_irf(M_, options_, irf, title_, varlist)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if nargin < 4
title_ = '';
figure_name = '';
end
nvars = M_.endo_nbr;
......@@ -79,7 +82,7 @@ function plot_ms_irf(M_, options_, irf, title_, varlist)
end
if size(endo_names,1) ~= nvars
error('The names passed are not the same length as the number of variables')
error('The names passed are not the same length as the number of variables');
end
if num_percentiles == 1
......@@ -90,7 +93,7 @@ function plot_ms_irf(M_, options_, irf, title_, varlist)
shock(:,i) = irf(:,((i-1) + ((s-1)*nvars)+1));
end
plot_point_irf_for_shock(shock, nvars,endo_names, deblank(endo_names(s,:)), ...
title_, [options_.ms.output_file_tag filesep 'Output' filesep 'IRF'], options_, names, tex_names);
figure_name, [options_.ms.output_file_tag filesep 'Output' filesep 'IRF'], options_, names, tex_names);
end
else
for s=1:nvars
......@@ -101,25 +104,25 @@ function plot_ms_irf(M_, options_, irf, title_, varlist)
end
end
plot_banded_irf_for_shock(shock, nvars,endo_names, deblank(endo_names(s,:)), ...
title_, [options_.ms.output_file_tag filesep 'Output' filesep 'IRF'], options_, names, tex_names);
figure_name, [options_.ms.output_file_tag filesep 'Output' filesep 'IRF'], options_, names, tex_names);
end
end
end
function [fig] = plot_point_irf_for_shock(irf,nvars,endo_names,shock_name,title_,dirname,options_,names,tex_names)
fig = figure('Name',title_);
function [fig] = plot_point_irf_for_shock(irf,nvars,endo_names,shock_name,figure_name,dirname,options_,names,tex_names)
fig = figure('Name',figure_name);
for k=1:nvars
subplot(ceil(sqrt(nvars)), ceil(sqrt(nvars)),k);
plot(irf(:,k))
disp([endo_names(k,:) ' shock from ' shock_name]);
title([endo_names(k,:) ' shock from ' shock_name]);
end
dyn_save_graph(dirname,[title_ ' ' shock_name],options_.graph_save_formats, ...
options_.TeX,names,tex_names,[title_ ' ' shock_name]);
dyn_save_graph(dirname,[figure_name ' ' shock_name],options_.graph_save_formats, ...
options_.TeX,names,tex_names,[figure_name ' ' shock_name]);
end
function [fig] = plot_banded_irf_for_shock(irf,nvars, endo_names, shock_name,title_,dirname,options_,names,tex_names)
fig = figure('Name',title_);
function [fig] = plot_banded_irf_for_shock(irf,nvars, endo_names, shock_name,figure_name,dirname,options_,names,tex_names)
fig = figure('Name',figure_name);
npercentiles = size(irf,3);
for k=1:nvars
subplot(ceil(sqrt(nvars)), ceil(sqrt(nvars)),k);
......@@ -131,6 +134,6 @@ function [fig] = plot_banded_irf_for_shock(irf,nvars, endo_names, shock_name,tit
disp([endo_names(k,:) ' shock from ' shock_name]);
title([endo_names(k,:) ' shock from ' shock_name]);
end
dyn_save_graph(dirname,[title_ ' ' shock_name],options_.graph_save_formats, ...
options_.TeX,names,tex_names,[title_ ' ' shock_name]);
dyn_save_graph(dirname,[figure_name ' ' shock_name],options_.graph_save_formats, ...
options_.TeX,names,tex_names,[figure_name ' ' shock_name]);
end
function plot_ms_variance_decomposition(M_, options_, vd, title_, graph_save_formats, TeX, varargin)
% function plot_ms_variance_decomposition(M_, options_, vd, title_, graph_save_formats, TeX, varargin)
function plot_ms_variance_decomposition(M_, options_, vd, figure_name, varargin)
% function plot_ms_variance_decomposition(M_, options_, vd, figure_name, varargin)
% plot the variance decomposition of shocks
%
% Inputs
% M_
% shocks: matrix of the individual shocks Tx(KxK)with J=number of shocks
% INPUTS
% M_: (struct) model structure
% options_: (struct) options
% vd: (matrix) variance decomposition
% figure_name: (string) graph name
%
% Optional Inputs
% 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
......@@ -14,8 +16,11 @@ function plot_ms_variance_decomposition(M_, options_, vd, title_, graph_save_for
% '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
%
% Example:
% plot_historic_decomposition(shocks,'VD','shock_names',shock_names,'series_names',series_names)
% OUTPUTS
% none
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2011-2012 Dynare Team
%
......@@ -35,7 +40,7 @@ function plot_ms_variance_decomposition(M_, options_, vd, title_, graph_save_for
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if length(size(vd)) == 3
plot_ms_variance_decomposition_error_bands(M_, options_, vd, title_);
plot_ms_variance_decomposition_error_bands(M_, options_, vd, figure_name);
return;
end
......@@ -111,7 +116,7 @@ end
% add an extra period to the time series
x(T+1) = x(T) + (x(T) - x(T-1));
figure('Name',title_)
figure('Name',figure_name)
for k=1:K
% Go through each series
subplot(K,1,k);
......@@ -163,5 +168,6 @@ end
end
dyn_save_graph([options_.ms.output_file_tag filesep 'Output' ...
filesep 'Variance_Decomposition'], 'MS-Variance-Decomposition', ...
graph_save_formats, TeX,names,tex_names,'Variance decomposition');
options_.graph_save_formats, options_.TeX, names, tex_names, ...
'Variance decomposition');
end
function plot_ms_variance_decomposition_error_bands(M_, options_, vddata, title_)
% function plot_ms_variance_decomposition_error_bands(M_, options_, vddata, title_)
function plot_ms_variance_decomposition_error_bands(M_, options_, vddata, figure_name)
% function plot_ms_variance_decomposition_error_bands(M_, options_, vddata, figure_name)
% plots the variance decomposition with percentiles
%
% INPUTS
......@@ -7,8 +7,13 @@ function plot_ms_variance_decomposition_error_bands(M_, options_, vddata, title_
% options_: (struct) options
% vddata: (matrix) variance_decomposition (percentile, options_.ms.horizon, nvar
% x nvar)
% title: (string) title
% figure_name: (string) title
%
% OUTPUTS
% none
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2011-2012 Dynare Team
%
......@@ -74,15 +79,15 @@ for s=1:nvars
end
end
plot_banded_vddata_for_shock(shock, nvars, endo_names, ...
deblank(endo_names(s,:)), title_, ...
deblank(endo_names(s,:)), figure_name, ...
[options_.ms.output_file_tag filesep 'Output' filesep 'Variance_Decomposition'], ...
options_, names, tex_names);
end
end
function [fig] = plot_banded_vddata_for_shock(vddata, nvars, endo_names, ...
shock_name, title_, dirname, options_, names, tex_names)
fig = figure('Name', title_);
shock_name, figure_name, dirname, options_, names, tex_names)
fig = figure('Name', figure_name);
npercentiles = size(vddata,3);
for k=1:nvars
subplot(ceil(sqrt(nvars)), ceil(sqrt(nvars)),k);
......@@ -94,7 +99,7 @@ for k=1:nvars
disp([endo_names(k,:) ' contribution to ' shock_name]);
title([endo_names(k,:) ' contribution to ' shock_name]);
end
dyn_save_graph(dirname, [title_ ' ' shock_name], ...
dyn_save_graph(dirname, [figure_name ' ' shock_name], ...
options_.graph_save_formats, options_.TeX, names, tex_names, ...
[title_ ' ' shock_name]);
[figure_name ' ' shock_name]);
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment