%% Estimate GARCH Model Parameters Using Presample Data
% Fit a GARCH(1,1) model to the daily close NASDAQ Composite Index returns.
% Load the NASDAQ data included with the toolbox. Convert the index to returns.

load Data_EquityIdx
nasdaq = DataTable.NASDAQ;
y = price2ret(nasdaq);
T = length(y);

figure
plot(y)
xlim([0,T])
title('NASDAQ Returns')

% The returns exhibit volatility clustering.
%
% Specify a GARCH(1,1) model, and fit it to the series. One presample innovation is required to initialize this model. Use the first observation of y as the necessary presample innovation.

Mdl = garch(1,1);
[EstMdl,EstParamCov] = estimate(Mdl,y(2:end),'E0',y(1))

% The output EstMdl is a new garch model with estimated parameters.
%
% Use the output variance-covariance matrix to calculate the estimate standard errors.

se = sqrt(diag(EstParamCov))

% These are the standard errors shown in the estimation output display. They correspond (in order) to the constant, GARCH coefficient, and ARCH coefficient.
% Copyright 2015 The MathWorks, Inc.