Home > matlab > dyn_forecast.m

dyn_forecast

PURPOSE ^

function dyn_forecast(var_list,task)

SYNOPSIS ^

function info = dyn_forecast(var_list,task)

DESCRIPTION ^

 function dyn_forecast(var_list,task)
   computes mean forecast for a given value of the parameters
   computes also confidence band for the forecast    

 INPUTS
   var_list:    list of variables (character matrix)
   task:        indicates how to initialize the forecast
                either 'simul' or 'smoother'
 OUTPUTS
   nothing is returned but the procedure saves output
   in oo_.forecast.Mean
      oo_.forecast.HPDinf
      oo_.forecast.HPDsup

 SPECIAL REQUIREMENTS
    none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function info = dyn_forecast(var_list,task)
0002 % function dyn_forecast(var_list,task)
0003 %   computes mean forecast for a given value of the parameters
0004 %   computes also confidence band for the forecast
0005 %
0006 % INPUTS
0007 %   var_list:    list of variables (character matrix)
0008 %   task:        indicates how to initialize the forecast
0009 %                either 'simul' or 'smoother'
0010 % OUTPUTS
0011 %   nothing is returned but the procedure saves output
0012 %   in oo_.forecast.Mean
0013 %      oo_.forecast.HPDinf
0014 %      oo_.forecast.HPDsup
0015 %
0016 % SPECIAL REQUIREMENTS
0017 %    none
0018 
0019 % Copyright (C) 2003-2010 Dynare Team
0020 %
0021 % This file is part of Dynare.
0022 %
0023 % Dynare is free software: you can redistribute it and/or modify
0024 % it under the terms of the GNU General Public License as published by
0025 % the Free Software Foundation, either version 3 of the License, or
0026 % (at your option) any later version.
0027 %
0028 % Dynare is distributed in the hope that it will be useful,
0029 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0030 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0031 % GNU General Public License for more details.
0032 %
0033 % You should have received a copy of the GNU General Public License
0034 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0035 
0036 global options_ oo_ M_
0037 
0038 info = 0;
0039 
0040 maximum_lag = M_.maximum_lag;
0041 
0042 endo_names = M_.endo_names;
0043 if isempty(var_list)
0044     var_list = endo_names(1:M_.orig_endo_nbr, :);
0045 end
0046 i_var = [];
0047 for i = 1:size(var_list)
0048     tmp = strmatch(var_list(i,:),endo_names,'exact');
0049     if isempty(tmp)
0050         error([var_list(i,:) ' isn''t and endogenous variable'])
0051     end
0052     i_var = [i_var; tmp];
0053 end
0054 
0055 n_var = length(i_var);
0056 
0057 trend = 0;
0058 switch task
0059   case 'simul'
0060     horizon = options_.periods;
0061     if horizon == 0
0062         horizon = 5;
0063     end
0064     if isempty(M_.endo_histval)
0065         y0 = repmat(oo_.steady_state,1,maximum_lag);
0066     else
0067         y0 = M_.endo_histval;
0068     end
0069   case 'smoother'
0070     horizon = options_.forecast;
0071     y_smoothed = oo_.SmoothedVariables;
0072     y0 = zeros(M_.endo_nbr,maximum_lag);
0073     for i = 1:M_.endo_nbr
0074         v_name = deblank(M_.endo_names(i,:));
0075         y0(i,:) = y_smoothed.(v_name)(end-maximum_lag+1:end)+oo_.dr.ys(i);
0076     end
0077     gend = options_.nobs;
0078     if isfield(oo_.Smoother,'TrendCoeffs')
0079         var_obs = options_.varobs;
0080         endo_names = M_.endo_names;
0081         order_var = oo_.dr.order_var;
0082         i_var_obs = [];
0083         trend_coeffs = [];
0084         for i=1:size(var_obs,1)
0085             tmp = strmatch(var_obs(i,:),endo_names(i_var,:),'exact');
0086             if ~isempty(tmp)
0087                 i_var_obs = [ i_var_obs; tmp];
0088                 trend_coeffs = [trend_coeffs; oo_.Smoother.TrendCoeffs(i)];
0089             end
0090         end         
0091         trend = trend_coeffs*(gend+(1-M_.maximum_lag:horizon));
0092     end
0093     global bayestopt_
0094     if isfield(bayestopt_,'mean_varobs')
0095         trend = trend + repmat(bayestopt_.mean_varobs,1,horizon+M_.maximum_lag);
0096     end
0097   otherwise
0098     error('Wrong flag value')
0099 end 
0100 
0101 if M_.exo_det_nbr == 0
0102     [yf,int_width] = forcst(oo_.dr,y0,horizon,var_list);
0103 else
0104     exo_det_length = size(oo_.exo_det_simul,1)-M_.maximum_lag;
0105     if horizon > exo_det_length
0106         ex = zeros(horizon,M_.exo_nbr);
0107         oo_.exo_det_simul = [ oo_.exo_det_simul;...
0108                             repmat(oo_.exo_det_steady_state',...
0109                                    horizon- ... 
0110                                    exo_det_length,1)];
0111     elseif horizon < exo_det_length 
0112         ex = zeros(exo_det_length,M_.exo_nbr); 
0113     end
0114     [yf,int_width] = simultxdet(y0,ex,oo_.exo_det_simul,...
0115                                 options_.order,var_list,M_,oo_,options_);
0116 end
0117 
0118 if ~isscalar(trend)
0119     yf(i_var_obs,:) = yf(i_var_obs,:) + trend;
0120 end
0121 
0122 for i=1:n_var
0123     eval(['oo_.forecast.Mean.' var_list(i,:) '= yf(' int2str(i) ',maximum_lag+1:end)'';']);
0124     eval(['oo_.forecast.HPDinf.' var_list(i,:) '= yf(' int2str(i) ',maximum_lag+1:end)''-' ...
0125           ' int_width(:,' int2str(i) ');']);
0126     eval(['oo_.forecast.HPDsup.' var_list(i,:) '= yf(' int2str(i) ',maximum_lag+1:end)''+' ...
0127           ' int_width(:,' int2str(i) ');']);
0128 end
0129 
0130 for i=1:M_.exo_det_nbr
0131     eval(['oo_.forecast.Exogenous.' M_.exo_det_names(i,:) '= oo_.exo_det_simul(:,' int2str(i) ');']);
0132 end
0133 
0134 if options_.nograph == 0
0135     forecast_graphs(var_list);
0136 end

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005