2011-05-20 14:29:23 +02:00
|
|
|
function [options_, oo_]=ms_variance_decomposition(M_, options_, oo_)
|
2011-10-11 16:35:13 +02:00
|
|
|
% function [options_, oo_]=ms_variance_decomposition(M_, options_, oo_)
|
|
|
|
% Markov-switching SBVAR: Variance Decomposition
|
2011-05-20 14:29:23 +02:00
|
|
|
%
|
|
|
|
% INPUTS
|
2011-06-01 10:48:35 +02:00
|
|
|
% M_: (struct) model structure
|
|
|
|
% options_: (struct) options
|
|
|
|
% oo_: (struct) results
|
2011-05-20 14:29:23 +02:00
|
|
|
%
|
|
|
|
% OUTPUTS
|
2011-06-01 10:48:35 +02:00
|
|
|
% options_: (struct) options
|
|
|
|
% oo_: (struct) results
|
2011-05-20 14:29:23 +02:00
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
|
2012-06-08 18:22:34 +02:00
|
|
|
% Copyright (C) 2011-2012 Dynare Team
|
2011-05-20 14:29:23 +02:00
|
|
|
%
|
|
|
|
% 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/>.
|
|
|
|
|
2011-07-29 14:55:07 +02:00
|
|
|
disp('MS-SBVAR Variance Decomposition');
|
|
|
|
options_ = set_file_tags(options_);
|
2011-10-07 11:13:54 +02:00
|
|
|
[options_, oo_] = set_ms_estimation_file(options_.ms.file_tag, options_, oo_);
|
2011-10-19 17:25:46 +02:00
|
|
|
clean_ms_variance_decomposition_files(options_.ms.output_file_tag);
|
2011-07-29 14:55:07 +02:00
|
|
|
vddir = [options_.ms.output_file_tag filesep 'Variance_Decomposition'];
|
|
|
|
create_dir(vddir);
|
2011-05-20 14:29:23 +02:00
|
|
|
|
2011-10-19 17:25:46 +02:00
|
|
|
% setup command line options
|
|
|
|
opt = ['-variance_decomposition -seed ' num2str(options_.DynareRandomStreams.seed)];
|
|
|
|
opt = [opt ' -do ' vddir];
|
|
|
|
opt = [opt ' -ft ' options_.ms.file_tag];
|
|
|
|
opt = [opt ' -fto ' options_.ms.output_file_tag];
|
|
|
|
opt = [opt ' -horizon ' num2str(options_.ms.horizon)];
|
|
|
|
opt = [opt ' -thin ' num2str(options_.ms.thinning_factor)];
|
2011-05-20 14:29:23 +02:00
|
|
|
|
2011-10-19 17:25:46 +02:00
|
|
|
if options_.ms.regimes
|
|
|
|
opt = [opt ' -regimes'];
|
|
|
|
elseif options_.ms.regime
|
|
|
|
% regime-1 since regime is 0-indexed in C but 1-indexed in Matlab
|
|
|
|
opt = [opt ' -regime ' num2str(options_.ms.regime-1)];
|
|
|
|
elseif options_.ms.filtered_probabilities
|
|
|
|
opt = [opt ' -filtered'];
|
|
|
|
end
|
|
|
|
|
|
|
|
if options_.ms.parameter_uncertainty
|
|
|
|
options_ = set_ms_simulation_file(options_);
|
|
|
|
opt = [opt ' -parameter_uncertainty'];
|
|
|
|
opt = [opt ' -shocks_per_parameter ' num2str(options_.ms.shocks_per_parameter)];
|
|
|
|
else
|
|
|
|
opt = [opt ' -shocks_per_parameter ' num2str(options_.ms.shock_draws)];
|
|
|
|
end
|
2011-05-20 14:29:23 +02:00
|
|
|
|
2011-10-19 17:25:46 +02:00
|
|
|
percentiles_size = 1;
|
|
|
|
outfile = [vddir filesep 'var_decomp_mean_'];
|
|
|
|
if options_.ms.error_bands
|
|
|
|
% error_bands / percentiles used differently by
|
|
|
|
% Dan's variance decomposition code
|
|
|
|
% no_error_bands => mean is computed
|
|
|
|
percentiles_size = size(options_.ms.percentiles,2);
|
|
|
|
opt = [opt ' -percentiles ' num2str(percentiles_size)];
|
|
|
|
for i=1:size(options_.ms.percentiles,2)
|
|
|
|
opt = [opt ' ' num2str(options_.ms.percentiles(i))];
|
|
|
|
end
|
|
|
|
outfile = [vddir filesep 'var_decomp_percentiles_'];
|
2011-08-22 16:20:05 +02:00
|
|
|
end
|
|
|
|
|
2011-10-19 17:25:46 +02:00
|
|
|
% variance_decomposition
|
|
|
|
[err] = ms_sbvar_command_line(opt);
|
|
|
|
mexErrCheck('ms_variance_decomposition',err);
|
2011-05-20 14:29:23 +02:00
|
|
|
|
2011-10-19 17:25:46 +02:00
|
|
|
if options_.ms.regime || options_.ms.regimes
|
|
|
|
outfile = [outfile 'regime_'];
|
|
|
|
if options_.ms.regime
|
|
|
|
outfile = [outfile num2str(options_.ms.regime-1) ...
|
|
|
|
'_' options_.ms.output_file_tag '.out'];
|
|
|
|
end
|
|
|
|
elseif options_.ms.filtered_probabilities
|
|
|
|
outfile = [outfile 'filtered_' options_.ms.output_file_tag '.out'];
|
|
|
|
else
|
|
|
|
outfile = [outfile 'ergodic_' options_.ms.output_file_tag '.out'];
|
|
|
|
end
|
2011-05-20 14:29:23 +02:00
|
|
|
|
2011-10-19 17:25:46 +02:00
|
|
|
% Create plots
|
|
|
|
if options_.ms.regimes
|
|
|
|
n_chains = length(options_.ms.ms_chain);
|
2012-03-08 17:34:34 +01:00
|
|
|
n_regimes=1;
|
2011-10-19 17:25:46 +02:00
|
|
|
for i_chain=1:n_chains
|
2012-03-08 17:34:34 +01:00
|
|
|
n_regimes = n_regimes*length(options_.ms.ms_chain(i_chain).regime);
|
2011-10-19 17:25:46 +02:00
|
|
|
end
|
2012-03-08 17:34:34 +01:00
|
|
|
for regime_i=1:n_regimes
|
2012-03-08 18:25:37 +01:00
|
|
|
vd_title = ['Variance Decomposition, Regime ' num2str(regime_i)];
|
2012-03-08 17:34:34 +01:00
|
|
|
vd_data = load([outfile num2str(regime_i-1) '_' ...
|
2011-10-19 17:25:46 +02:00
|
|
|
options_.ms.output_file_tag '.out'], '-ascii');
|
|
|
|
vd_data = reshape_ascii_variance_decomposition_data( ...
|
|
|
|
M_.endo_nbr, percentiles_size, options_.ms.horizon, vd_data);
|
2012-03-08 17:34:34 +01:00
|
|
|
save([vddir filesep 'variance_decomposition_regime_' num2str(regime_i-1)], 'vd_data');
|
2012-03-08 18:25:37 +01:00
|
|
|
plot_ms_variance_decomposition(M_, options_, vd_data, vd_title);
|
2011-10-19 17:25:46 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
if options_.ms.regime
|
2012-03-08 17:34:34 +01:00
|
|
|
vd_title = ['Variance Decomposition, Regime ' num2str(options_.ms.regime)];
|
2011-10-19 17:25:46 +02:00
|
|
|
save_filename = ['variance_decomposition_regime_' num2str(options_.ms.regime-1)];
|
|
|
|
else
|
|
|
|
save_filename = 'variance_decomposition';
|
|
|
|
if options_.ms.filtered_probabilities
|
|
|
|
vd_title = 'Variance Decomposition Filtered';
|
|
|
|
else
|
|
|
|
vd_title = 'Variance Decomposition Ergodic';
|
|
|
|
end
|
|
|
|
end
|
|
|
|
vd_data = load(outfile, '-ascii');
|
|
|
|
vd_data = reshape_ascii_variance_decomposition_data( ...
|
|
|
|
M_.endo_nbr, percentiles_size, options_.ms.horizon, vd_data);
|
|
|
|
save([vddir filesep save_filename], 'vd_data');
|
2012-03-08 18:25:37 +01:00
|
|
|
plot_ms_variance_decomposition(M_, options_, vd_data, vd_title);
|
2011-05-20 14:29:23 +02:00
|
|
|
end
|
|
|
|
end
|