Home > matlab > ms-sbvar > ms_irf.m

ms_irf

PURPOSE ^

function [options_, oo_]=ms_irf(varlist, M_, options_, oo_)

SYNOPSIS ^

function [options_, oo_]=ms_irf(varlist, M_, options_, oo_)

DESCRIPTION ^

 function [options_, oo_]=ms_irf(varlist, M_, options_, oo_)
 Markov-switching SBVAR: Impulse Response Function

 INPUTS
    varlist:     (chararray) list of selected endogenous variables
    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_irf(varlist, M_, options_, oo_)
0002 % function [options_, oo_]=ms_irf(varlist, M_, options_, oo_)
0003 % Markov-switching SBVAR: Impulse Response Function
0004 %
0005 % INPUTS
0006 %    varlist:     (chararray) list of selected endogenous variables
0007 %    M_:          (struct)    model structure
0008 %    options_:    (struct)    options
0009 %    oo_:         (struct)    results
0010 %
0011 % OUTPUTS
0012 %    options_:    (struct)    options
0013 %    oo_:         (struct)    results
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 disp('MS-SBVAR Impulse Response Function');
0036 options_ = set_file_tags(options_);
0037 [options_, oo_] = set_ms_estimation_file(options_.ms.file_tag, options_, oo_);
0038 clean_ms_irf_files(options_.ms.output_file_tag);
0039 irfdir = [options_.ms.output_file_tag filesep 'IRF'];
0040 create_dir(irfdir);
0041 
0042 % setup command line options
0043 opt = ['-ir -seed ' num2str(options_.DynareRandomStreams.seed)];
0044 opt = [opt ' -do ' irfdir];
0045 opt = [opt ' -ft ' options_.ms.file_tag];
0046 opt = [opt ' -fto ' options_.ms.output_file_tag];
0047 opt = [opt ' -horizon ' num2str(options_.ms.horizon)];
0048 opt = [opt ' -thin ' num2str(options_.ms.thinning_factor)];
0049 
0050 if options_.ms.regimes
0051     opt = [opt ' -regimes'];
0052 elseif options_.ms.regime
0053     % regime-1 since regime is 0-indexed in C but 1-indexed in Matlab
0054     opt = [opt ' -regime ' num2str(options_.ms.regime-1)];
0055 elseif options_.ms.filtered_probabilities
0056     opt = [opt ' -filtered'];
0057 end
0058 
0059 if options_.ms.parameter_uncertainty
0060     options_ = set_ms_simulation_file(options_);
0061     opt = [opt ' -parameter_uncertainty'];
0062     opt = [opt ' -shocks_per_parameter ' num2str(options_.ms.shocks_per_parameter)];
0063 else
0064     opt = [opt ' -shocks_per_parameter ' num2str(options_.ms.shock_draws)];
0065 end
0066 
0067 percentiles_size = 0;
0068 if options_.ms.median
0069     percentiles_size = 1;
0070     opt = [opt ' -percentiles ' num2str(percentiles_size) ' 0.5'];
0071 else
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 end
0078 
0079 % irf
0080 [err] = ms_sbvar_command_line(opt);
0081 mexErrCheck('ms_irf',err);
0082 
0083 % Plot IRFs
0084 if options_.ms.regimes
0085     n_chains = length(options_.ms.ms_chain);
0086     n_regimes=1;
0087     for i_chain=1:n_chains
0088         n_regimes = n_regimes*length(options_.ms.ms_chain(i_chain).regime);
0089     end
0090 
0091     for regime_i=1:n_regimes
0092         irf_title = ['Impulse Responses, Regime ' num2str(regime_i)];
0093         irf_data = load([irfdir filesep 'ir_percentiles_regime_' ...
0094             num2str(regime_i-1) '_' options_.ms.output_file_tag ...
0095             '.out'], '-ascii');
0096         irf_data = reshape_ascii_irf_data(M_.endo_nbr, percentiles_size, ...
0097             options_.ms.horizon, irf_data);
0098         save([irfdir filesep 'irf_regime_' num2str(regime_i-1)], 'irf_data');
0099         plot_ms_irf(M_, options_, irf_data, irf_title, varlist);
0100     end
0101 else
0102     if options_.ms.regime
0103         irf_data = load([irfdir filesep 'ir_percentiles_regime_' ...
0104             num2str(options_.ms.regime-1) '_' options_.ms.output_file_tag ...
0105             '.out'], '-ascii');
0106         irf_title = ['Impulse Response, Regime ' num2str(options_.ms.regime)];
0107         save_filename = ['irf_regime_' num2str(options_.ms.regime-1)];
0108     elseif options_.ms.filtered_probabilities
0109         irf_data = load([irfdir filesep 'ir_percentiles_filtered_' ...
0110             options_.ms.output_file_tag '.out'], '-ascii');
0111         irf_title = 'Impulse Response Filtered';
0112         save_filename = 'irf';
0113     else
0114         irf_data = load([irfdir filesep 'ir_percentiles_ergodic_' ...
0115             options_.ms.output_file_tag '.out'], '-ascii');
0116         irf_title = 'Impulse Response Ergodic';
0117         save_filename = 'irf';
0118     end
0119 
0120     irf_data = reshape_ascii_irf_data(M_.endo_nbr, percentiles_size, ...
0121         options_.ms.horizon, irf_data);
0122     save([irfdir filesep save_filename], 'irf_data');
0123     plot_ms_irf(M_, options_, irf_data, irf_title, varlist);
0124 end
0125 end

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