%% Conduct Likelihood Ratio Test for EGARCH Fit Comparison
% Infer the loglikelihood objective function values for an EGARCH(1,1) and EGARCH(2,1) model fit to NASDAQ Composite Index returns. To identify which model is the more parsimonious, adequate fit, conduct a likelihood ratio test.
% Load the NASDAQ data included with the toolbox, and convert the index to returns. Set aside the first two observations to use as presample data.

load Data_EquityIdx
nasdaq = DataTable.NASDAQ;
r = price2ret(nasdaq);
r0 = r(1:2);
rn = r(3:end);

%
% Fit an EGARCH(1,1) model to the returns, and infer the loglikelihood objective function value.

Mdl1 = egarch(1,1);
EstMdl1 = estimate(Mdl1,rn,'E0',r0);
[~,logL1] = infer(EstMdl1,rn,'E0',r0);

%
% Fit an EGARCH(2,1) model to the returns, and infer the loglikelihood objective function value.

Mdl2 = egarch(2,1);
EstMdl2 = estimate(Mdl2,rn,'E0',r0);
[~,logL2] = infer(EstMdl2,rn,'E0',r0);

%
% Conduct a likelihood ratio test, with the more parsimonious EGARCH(1,1) model as the null model, and the EGARCH(2,1) model as the alternative. The degree of freedom for the test is 1, because the EGARCH(2,1) model has one more parameter than the EGARCH(1,1) model (an additional GARCH term).

[h,p] = lratiotest(logL2,logL1,1)

% The null hypothesis is not rejected (h = 0). At the 0.05 significance level, the EGARCH(1,1) model is not rejected in favor of the EGARCH(2,1) model.
% Copyright 2015 The MathWorks, Inc.