%% Compare GARCH Models Using Likelihood Ratio Test
% This example shows how to conduct a likelihood ratio test to choose the number of lags in a GARCH model.
%% Load Data
% Load the Deutschmark/British pound foreign-exchange rate data included with the toolbox. Convert the daily rates to returns.

load Data_MarkPound
Y = Data;
r = price2ret(Y); 
N = length(r);

figure
plot(r)
xlim([0,N])
title('Mark-Pound Exchange Rate Returns')

% The daily returns 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, scale the data to percentage returns.

r = 100*r;

%
%% Fit GARCH(1,1) Model
% Create and fit a GARCH(1,1) model (with a mean offset) to the returns series. Return the value of the loglikelihood objective function.

Mdl1 = garch('Offset',NaN,'GARCHLags',1,'ARCHLags',1);
[EstMdl1,~,logL1] = estimate(Mdl1,r);

%
%% Fit GARCH(2,1) Model
% Create and fit a GARCH(2,1) model with a mean offset.

Mdl2 = garch(2,1);
Mdl2.Offset = NaN;
[EstMdl2,~,logL2] = estimate(Mdl2,r);

%
%% Conduct Likelihood Ratio Test
% Conduct a likelihood ratio test to compare the restricted GARCH(1,1) model fit to the unrestricted GARCH(2,1) model fit. The degree of freedom for this test is one (the number of restrictions).

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

% At the 0.05 significance level, the null GARCH(1,1) model is rejected (h = 1) in favor of the unrestricted GARCH(2,1) alternative.
% Copyright 2015 The MathWorks, Inc.