%% Conduct Engle's ARCH Test
% This example shows how to conduct Engle's ARCH test for conditional heteroscedasticity.
%% Load the Data.
% Load the NASDAQ data included with the toolbox. Convert the daily close composite index series to a percentage return series.

load Data_EquityIdx;
y = DataTable.NASDAQ;
r = 100*price2ret(y);
T = length(r);

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

% The returns appear to fluctuate around a constant level, but exhibit volatility clustering. Large changes in the returns tend to cluster together, and small changes tend to cluster together. That is, the series exhibits conditional heteroscedasticity.
% The returns are of relatively high frequency. Therefore, the daily changes can be small. For numerical stability, it is good practice to scale such data.
%
%% Conduct Engle's ARCH Test.
% Conduct Engle's ARCH test for conditional heteroscedasticity on the residual series, using two lags in the alternative hypothesis.

e = r - mean(r);
[h,p,fStat,crit] = archtest(e,'Lags',2)

% The null hypothesis is soundly rejected (h = 1, p = 0) in favor of the ARCH(2) alternative. The F statistic for the test is 399.97, much larger than the critical value from the \chi^2 distribution with two degrees of freedom, 5.99.
% The test concludes there is significant volatility clustering in the residual series.
% Copyright 2015 The MathWorks, Inc.