Home > matlab > ms-sbvar > ms_variance_decomposition.m

ms_variance_decomposition

PURPOSE ^

function [options_, oo_]=ms_variance_decomposition(M_, options_, oo_)

SYNOPSIS ^

function [options_, oo_]=ms_variance_decomposition(M_, options_, oo_)

DESCRIPTION ^

 function [options_, oo_]=ms_variance_decomposition(M_, options_, oo_)
 Markov-switching SBVAR: Variance Decomposition

 INPUTS
    M_:          (struct)    model structure
    options_:    (struct)    options
    oo_:         (struct)    results

 OUTPUTS
    options_:    (struct)    options
    oo_:         (struct)    results

 SPECIAL REQUIREMENTS
    none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [options_, oo_]=ms_variance_decomposition(M_, options_, oo_)
0002 % function [options_, oo_]=ms_variance_decomposition(M_, options_, oo_)
0003 % Markov-switching SBVAR: Variance Decomposition
0004 %
0005 % INPUTS
0006 %    M_:          (struct)    model structure
0007 %    options_:    (struct)    options
0008 %    oo_:         (struct)    results
0009 %
0010 % OUTPUTS
0011 %    options_:    (struct)    options
0012 %    oo_:         (struct)    results
0013 %
0014 % SPECIAL REQUIREMENTS
0015 %    none
0016 
0017 % Copyright (C) 2011 Dynare Team
0018 %
0019 % This file is part of Dynare.
0020 %
0021 % Dynare is free software: you can redistribute it and/or modify
0022 % it under the terms of the GNU General Public License as published by
0023 % the Free Software Foundation, either version 3 of the License, or
0024 % (at your option) any later version.
0025 %
0026 % Dynare is distributed in the hope that it will be useful,
0027 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0028 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0029 % GNU General Public License for more details.
0030 %
0031 % You should have received a copy of the GNU General Public License
0032 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0033 
0034 disp('MS-SBVAR Variance Decomposition');
0035 options_ = set_file_tags(options_);
0036 [options_, oo_] = set_ms_estimation_file(options_.ms.file_tag, options_, oo_);
0037 clean_ms_variance_decomposition_files(options_.ms.output_file_tag);
0038 vddir = [options_.ms.output_file_tag filesep 'Variance_Decomposition'];
0039 create_dir(vddir);
0040 
0041 % setup command line options
0042 opt = ['-variance_decomposition -seed ' num2str(options_.DynareRandomStreams.seed)];
0043 opt = [opt ' -do ' vddir];
0044 opt = [opt ' -ft ' options_.ms.file_tag];
0045 opt = [opt ' -fto ' options_.ms.output_file_tag];
0046 opt = [opt ' -horizon ' num2str(options_.ms.horizon)];
0047 opt = [opt ' -thin ' num2str(options_.ms.thinning_factor)];
0048 
0049 if options_.ms.regimes
0050     opt = [opt ' -regimes'];
0051 elseif options_.ms.regime
0052     % regime-1 since regime is 0-indexed in C but 1-indexed in Matlab
0053     opt = [opt ' -regime ' num2str(options_.ms.regime-1)];
0054 elseif options_.ms.filtered_probabilities
0055     opt = [opt ' -filtered'];
0056 end
0057 
0058 if options_.ms.parameter_uncertainty
0059     options_ = set_ms_simulation_file(options_);
0060     opt = [opt ' -parameter_uncertainty'];
0061     opt = [opt ' -shocks_per_parameter ' num2str(options_.ms.shocks_per_parameter)];
0062 else
0063     opt = [opt ' -shocks_per_parameter ' num2str(options_.ms.shock_draws)];
0064 end
0065 
0066 percentiles_size = 1;
0067 outfile = [vddir filesep 'var_decomp_mean_'];
0068 if options_.ms.error_bands
0069     % error_bands / percentiles used differently by
0070     % Dan's variance decomposition code
0071     % no_error_bands => mean is computed
0072     percentiles_size = size(options_.ms.percentiles,2);
0073     opt = [opt ' -percentiles ' num2str(percentiles_size)];
0074     for i=1:size(options_.ms.percentiles,2)
0075         opt = [opt ' ' num2str(options_.ms.percentiles(i))];
0076     end
0077     outfile = [vddir filesep 'var_decomp_percentiles_'];
0078 end
0079 
0080 % variance_decomposition
0081 [err] = ms_sbvar_command_line(opt);
0082 mexErrCheck('ms_variance_decomposition',err);
0083 
0084 if options_.ms.regime || options_.ms.regimes
0085     outfile = [outfile 'regime_'];
0086     if options_.ms.regime
0087         outfile = [outfile num2str(options_.ms.regime-1) ...
0088             '_' options_.ms.output_file_tag '.out'];
0089     end
0090 elseif options_.ms.filtered_probabilities
0091     outfile = [outfile 'filtered_' options_.ms.output_file_tag '.out'];
0092 else
0093     outfile = [outfile 'ergodic_' options_.ms.output_file_tag '.out'];
0094 end
0095 
0096 % Create plots
0097 if options_.ms.regimes
0098     n_chains = length(options_.ms.ms_chain);
0099     n_regimes=1;
0100     for i_chain=1:n_chains
0101         n_regimes = n_regimes*length(options_.ms.ms_chain(i_chain).regime);
0102     end
0103     for regime_i=1:n_regimes
0104         vd_title = ['Variance Decomposition, Regime ' num2str(regime_i)];
0105         vd_data = load([outfile num2str(regime_i-1) '_' ...
0106             options_.ms.output_file_tag '.out'], '-ascii');
0107         vd_data = reshape_ascii_variance_decomposition_data( ...
0108             M_.endo_nbr, percentiles_size, options_.ms.horizon, vd_data);
0109         save([vddir filesep 'variance_decomposition_regime_' num2str(regime_i-1)], 'vd_data');
0110         plot_ms_variance_decomposition(M_, options_, vd_data, vd_title);
0111     end
0112 else
0113     if options_.ms.regime
0114         vd_title = ['Variance Decomposition, Regime ' num2str(options_.ms.regime)];
0115         save_filename = ['variance_decomposition_regime_' num2str(options_.ms.regime-1)];
0116     else
0117         save_filename = 'variance_decomposition';
0118         if options_.ms.filtered_probabilities
0119             vd_title = 'Variance Decomposition Filtered';
0120         else
0121             vd_title = 'Variance Decomposition Ergodic';
0122         end
0123     end
0124     vd_data = load(outfile, '-ascii');
0125     vd_data = reshape_ascii_variance_decomposition_data( ...
0126         M_.endo_nbr, percentiles_size, options_.ms.horizon, vd_data);
0127     save([vddir filesep save_filename], 'vd_data');
0128     plot_ms_variance_decomposition(M_, options_, vd_data, vd_title);
0129 end
0130 end

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