%% Infer Loglikelihoods to Conduct a Likelihood Ratio Test
% Infer the loglikelihood objective function values for a ARCH(1) and GARCH(1,1) model fit to NASDAQ Composite Index returns. Conduct a likelihood ratio test that statistically compares the fits of the parisomnious ARCH(1) model against the more complex, but flexible GARCH(1,1) model.
% Load the NASDAQ data included with the toolbox. Consider the NASDAQ price series.

load Data_EquityIdx
nasdaq = DataTable.NASDAQ;

%
% Convert the prices to returns, and then demean the returns. Set aside the first two observations to use as presample data.

r = price2ret(nasdaq);
r = r - mean(r);
r0 = r(1:2);
rn = r(3:end);

%
% Fit an ARCH(1) model (that is, a GARCH(0,1) model) to the returns, and infer the loglikelihood objective function value.

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

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

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

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

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

% The null hypothesis is rejected (h = 1). At the 0.05 significance level, the ARCH(1) model is rejected in favor of the GARCH(1,1) model.
% Copyright 2012 The MathWorks, Inc.