%% Forecast GJR Model Conditional Variances
% Forecast conditional variances from a fully specified gjr model object. That is, forecast from an estimated gjr model or a known gjr model in which you specify all parameter values.
% Load the Nelson-Plosser data set. Convert the yearly stock price indices (SP) to returns.

load Data_NelsonPlosser;
sp = price2ret(DataTable.SP);

%
% Create a GJR(1,1) model and fit it to the return series.

Mdl = gjr('GARCHLags',1,'ARCHLags',1,'LeverageLags',1);
EstMdl = estimate(Mdl,sp);

%
% Forecast the conditional variance of the nominal return series 10 years into the future using the estimated GJR model. Specify the entire return series as presample observations. The software infers presample conditional variances using the presample observations and the model.

numPeriods = 10;
vF = forecast(EstMdl,numPeriods,sp);

%
% Plot the forecasted conditional variances of the nominal returns. Compare the forecasts to the observed conditional variances.

v = infer(EstMdl,sp);
nV = size(v,1);
dates = dates((end - nV + 1):end);

figure;
plot(dates,v,'k:','LineWidth',2);
hold on;
plot(dates(end):dates(end) + 10,[v(end);vF],'r','LineWidth',2);
title('Forecasted Conditional Variances of Returns');
ylabel('Conditional variances');
xlabel('Year');
axis tight;
legend({'Estimation Sample Cond. Var.','Forecasted Cond. var.'},...
    'Location','NorthWest');

% Copyright 2015 The MathWorks, Inc.