Home > matlab > ms-sbvar > ms_forecast.m

ms_forecast

PURPOSE ^

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

SYNOPSIS ^

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

DESCRIPTION ^

 function [options_, oo_]=ms_forecast(M_, options_, oo_)
 Markov-switching SBVAR: Forecast

 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_forecast(M_, options_, oo_)
0002 % function [options_, oo_]=ms_forecast(M_, options_, oo_)
0003 % Markov-switching SBVAR: Forecast
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-2012 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 Forecasts');
0035 options_ = set_file_tags(options_);
0036 [options_, oo_] = set_ms_estimation_file(options_.ms.file_tag, options_, oo_);
0037 clean_ms_forecast_files(options_.ms.output_file_tag);
0038 forecastdir = [options_.ms.output_file_tag filesep 'Forecast'];
0039 create_dir(forecastdir);
0040 
0041 % setup command line options
0042 opt = ['-forecast -nodate -seed ' num2str(options_.DynareRandomStreams.seed)];
0043 opt = [opt ' -do ' forecastdir];
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 opt = [opt ' -data ' num2str(options_.ms.forecast_data_obs)];
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 end
0056 
0057 if options_.ms.parameter_uncertainty
0058     options_ = set_ms_simulation_file(options_);
0059     opt = [opt ' -parameter_uncertainty'];
0060     opt = [opt ' -shocks_per_parameter ' num2str(options_.ms.shocks_per_parameter)];
0061 else
0062     opt = [opt ' -shocks_per_parameter ' num2str(options_.ms.shock_draws)];
0063 end
0064 
0065 percentiles_size = 0;
0066 if options_.ms.median
0067     percentiles_size = 1;
0068     opt = [opt ' -percentiles ' num2str(percentiles_size) ' 0.5'];
0069 else
0070     percentiles_size = size(options_.ms.percentiles,2);
0071     opt = [opt ' -percentiles ' num2str(percentiles_size)];
0072     for i=1:size(options_.ms.percentiles,2)
0073         opt = [opt ' ' num2str(options_.ms.percentiles(i))];
0074     end
0075 end
0076 
0077 % forecast
0078 [err] = ms_sbvar_command_line(opt);
0079 mexErrCheck('ms_forecast',err);
0080 
0081 % Plot Forecasts
0082 if options_.ms.regimes
0083     n_chains = length(options_.ms.ms_chain);
0084     n_regimes=1;
0085     for i_chain=1:n_chains
0086         n_regimes = n_regimes*length(options_.ms.ms_chain(i_chain).regime);
0087     end
0088 
0089     for regime_i=1:n_regimes
0090         forecast_title = ['Forecast, Regimes ' num2str(regime_i)];
0091         forecast_data = load([forecastdir filesep 'forecasts_percentiles_regime_' ...
0092             num2str(regime_i-1) '_' options_.ms.output_file_tag ...
0093             '.out'], '-ascii');
0094         forecast_data = reshape_ascii_forecast_data(M_.endo_nbr, ...
0095             percentiles_size, options_.ms.horizon, forecast_data);
0096         save([forecastdir filesep 'forecast_regime_' num2str(regime_i-1)], ...
0097             'forecast_data');
0098         plot_ms_forecast(M_, options_, forecast_data, forecast_title);
0099     end
0100 else
0101     if options_.ms.regime
0102         forecast_data = load([forecastdir filesep 'forecasts_percentiles_regime_' ...
0103             num2str(options_.ms.regime-1) '_' options_.ms.output_file_tag ...
0104             '.out'], '-ascii');
0105         forecast_title = ['Forecast, Regime ' num2str(options_.ms.regime)];
0106         save_filename = ['forecast_regime_' num2str(options_.ms.regime-1)];
0107     else
0108         forecast_data = load([forecastdir filesep 'forecasts_percentiles_' ...
0109             options_.ms.output_file_tag '.out'], '-ascii');
0110         forecast_title = 'Forecast';
0111         save_filename = 'forecast';
0112     end
0113 
0114     forecast_data = reshape_ascii_forecast_data(M_.endo_nbr, ...
0115         percentiles_size, options_.ms.horizon, forecast_data);
0116     save([forecastdir filesep save_filename], 'forecast_data');
0117     plot_ms_forecast(M_, options_, forecast_data, forecast_title);
0118 end
0119 end

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