%% Forecast GARCH Model Conditional Variances
% Forecast conditional variances from a fully specified garch model object. That is, forecast from an estimated garch model or a known garch model in which you specify all parameter values. The example follows from Estimate GARCH Model.
% Load the Data_Danish data set.

load Data_Danish;
nr = DataTable.RN;

%
% Create a GARCH(1,1) model with an unknown conditional mean offset, and fit the model to the annual, nominal return series.

Mdl = garch('GARCHLags',1,'ARCHLags',1,'Offset',NaN);
EstMdl = estimate(Mdl,nr);

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

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

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

v = infer(EstMdl,nr);

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 Nominal Returns');
ylabel('Conditional variances');
xlabel('Year');
legend({'Estimation sample cond. var.','Forecasted cond. var.'},...
    'Location','Best');

% Copyright 2015 The MathWorks, Inc.