%% Estimate EGARCH Model
% Fit an EGARCH model to an annual time series of Danish nominal stock returns from 1922-1999.
% Load the Data_Danish data set. Plot the nominal returns (RN).

load Data_Danish;
nr = DataTable.RN;

figure;
plot(dates,nr);
hold on;
plot([dates(1) dates(end)],[0 0],'r:'); % Plot y = 0
hold off;
title('Danish Nominal Stock Returns');
ylabel('Nominal return (%)');
xlabel('Year');

% The nominal return series seems to have a nonzero conditional mean offset and seems to exhibit volatility clustering. That is, the variability is smaller for earlier years than it is for later years. For this example, assume that an EGARCH(1,1) model is appropriate for this series.
%
% Create an EGARCH(1,1) model. The conditional mean offset is zero by default. To estimate the offset, specify that it is NaN. Include a leverage lag.

Mdl = egarch('GARCHLags',1,'ARCHLags',1,'LeverageLags',1,'Offset',NaN);

%
% Fit the EGARCH(1,1) model to the data.

EstMdl = estimate(Mdl,nr);

% EstMdl is a fully specified egarch model object. That is, it does not contain NaN values. You can assess the adequacy of the model by generating residuals using infer, and then analyzing them.
% To simulate conditional variances or responses, pass EstMdl to simulate.
% To forecast innovations, pass EstMdl to forecast.
% Copyright 2015 The MathWorks, Inc.