0001 function info = dyn_forecast(var_list,task)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
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