| GARCH Toolbox™ | ![]() |
| On this page… |
|---|
When estimating the parameters of a composite conditional mean/variance model, you may occasionally encounter convergence problems. For example, the estimation may appear to stall, showing little or no progress. It may terminate prematurely before convergence. Or, it may converge to an unexpected, suboptimal solution.
You can avoid many of these difficulties by selecting the simplest model that adequately describes your data, and then performing a pre-fit analysis. The following pre-estimation analysis example shows how to:
Plot the return series and examine the ACF and PACF.
Perform preliminary tests, including Engle's ARCH test and the Q-test.
More specifically, the example does the following:
Load the MATLAB® binary file garchdata.mat, and view its contents in the Workspace Browser:
load garchdata

The data consists of three single-column vectors of different lengths, DEM2GBP, NASDAQ, and NYSE. Each vector is a separate price series for the named group.
Use the whos command to see all the variables in the current workspace:
whos Name Size Bytes Class DEM2GBP 1975x1 15800 double array NASDAQ 3028x1 24224 double array NYSE 3028x1 24224 double array Grand total is 8031 elements using 64248 bytes
DEM2GBP contains daily price observations of the Deutschemark/British Pound foreign-exchange rate. Use the MATLAB plot function to examine this data. Then, use the set function to set the position of and relabel the x-axis ticks of the current figure:
% plot([0:1974],DEM2GBP)
% set(gca,'XTick',[1 659 1318 1975])
% set(gca,'XTickLabel',{'Jan 1984' 'Jan 1986' 'Jan 1988' ...
% 'Jan 1992'})
%ylabel('Exchange Rate')
%title('Deutschmark/British Pound Foreign-Exchange Rate')

Because GARCH modeling assumes a return series, you need to convert the prices to returns.
Run the utility function price2ret:
dem2gbp = price2ret(DEM2GBP);
Examine the result. The workspace information shows both the 1975-point price series and the 1974-point return series derived from it.
Now, use the plot function to see the return series:
plot(dem2gbp)
set(gca,'XTick',[1 659 1318 1975])
set(gca,'XTickLabel',{'Jan 1984' 'Jan 1986' 'Jan 1988' ...
'Jan 1992'})
ylabel('Return')
title('Deutschmark/British Pound Daily Returns')
The raw return series shows volatility clustering.

Call the functions autocorr and parcorr to examine the sample autocorrelation (ACF) and partial-autocorrelation (PACF) functions, respectively.
Assuming that all autocorrelations are zero beyond lag zero, use the autocorr function to compute and display the sample ACF of the returns and the upper and lower standard deviation confidence bounds:
autocorr(dem2gbp)
title('ACF with Bounds for Raw Return Series')

Use the parcorr function to display the sample PACF with upper and lower confidence bounds:
parcorr(dem2gbp)
title('PACF with Bounds for Raw Return Series')

View the sample ACF and PACF with care (see Box, Jenkins, Reinsel [10], pages 34 and 186). The individual ACF values can have large variances and can also be autocorrelated. However, as preliminary identification tools, the ACF and PACF provide some indication of the broad correlation characteristics of the returns. From these figures for the ACF and PACF, there is little indication that you need to use any correlation structure in the conditional mean. Also, note the similarity between the graphs.
Although the ACF of the observed returns exhibits little correlation, the ACF of the squared returns may still indicate significant correlation and persistence in the second-order moments. Check this by plotting the ACF of the squared returns:
autocorr(dem2gbp.^2)
title('ACF of the Squared Returns')

This figure shows that, although the returns themselves are largely uncorrelated, the variance process exhibits some correlation. This is consistent with the earlier discussion in the section, The Default Model. The ACF shown in this figure appears to die out slowly, indicating the possibility of a variance process close to being nonstationary.
Quantify the preceding qualitative checks for correlation using formal hypothesis tests, such as the Ljung-Box-Pierce Q-test and Engle's ARCH test.
The lbqtest function implements the Ljung-Box-Pierce Q-test for a departure from randomness based on the ACF of the data. The Q-test is most often used as a post-estimation lack-of-fit test applied to the fitted innovations (residuals). In this case, however, you can also use it as part of the pre-fit analysis. This is because the default model assumes that returns are a simple constant plus a pure innovations process. Under the null hypothesis of no serial correlation, the Q-test statistic is asymptotically Chi-Square distributed (see Box, Jenkins, Reinsel [10], page 314).
The function archtest implements Engle's test for the presence of ARCH effects. Under the null hypothesis that a time series is a random sequence of Gaussian disturbances (that is, no ARCH effects exist), this test statistic is also asymptotically Chi-Square distributed (see Engle [14], pages 999-1000).
Both functions return identical outputs. The first output, H, is a Boolean decision flag. H = 0 implies that no significant correlation exists (that is, do not reject the null hypothesis). H = 1 means that significant correlation exists (that is, reject the null hypothesis). The remaining outputs are the p-value (pValue), the test statistic (Stat), and the critical value of the Chi-Square distribution (CriticalValue).
Use lbqtest to verify (approximately) that no significant correlation is present in the raw returns when tested for up to 10, 15, and 20 lags of the ACF at the 0.05 level of significance:
[H,pValue,Stat,CriticalValue] = ...
lbqtest(dem2gbp-mean(dem2gbp),[10 15 20]',0.05);
[H pValue Stat CriticalValue]
ans =
0 0.7278 6.9747 18.3070
0 0.2109 19.0628 24.9958
0 0.1131 27.8445 31.4104
However, there is significant serial correlation in the squared returns when you test them with the same inputs:
[H,pValue,Stat,CriticalValue] = ...
lbqtest((dem2gbp-mean(dem2gbp)).^2,[10 15 20]',0.05);
[H pValue Stat CriticalValue]
ans =
1.0000 0 392.9790 18.3070
1.0000 0 452.8923 24.9958
1.0000 0 507.5858 31.4104
Perform Engle's ARCH test using the function archtest:
[H,pValue,Stat,CriticalValue] = ...
archtest(dem2gbp-mean(dem2gbp),[10 15 20]',0.05);
[H pValue Stat CriticalValue]
ans =
1.0000 0 192.3783 18.3070
1.0000 0 201.4652 24.9958
1.0000 0 203.3018 31.4104
This test also shows significant evidence in support of GARCH effects (heteroscedasticity). Each of these examples extracts the sample mean from the actual returns. This is consistent with the definition of the conditional mean equation of the default model, in which the innovations process is εt = yt – C, and C is the mean of yt.
This section continues the Pre-Estimation Analysis example. It estimates model parameters, then examines the estimated GARCH model.
The presence of heteroscedasticity, shown in the previous analysis, indicates that GARCH modeling is appropriate. Use the estimation function garchfit to estimate the model parameters. Assume the default GARCH model described in The Default Model. This only requires that you specify the return series of interest as an argument to the garchfit function:
[coeff,errors,LLF,innovations,sigmas,summary] = ... garchfit(dem2gbp);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Diagnostic Information Number of variables: 4 Functions Objective: garchllfn Gradient: finite-differencing Hessian: finite-differencing (or Quasi-Newton) Nonlinear constraints: armanlc Gradient of nonlinear constraints: finite-differencing Constraints Number of nonlinear inequality constraints: 0 Number of nonlinear equality constraints: 0 Number of linear inequality constraints: 1 Number of linear equality constraints: 0 Number of lower bound constraints: 4 Number of upper bound constraints: 4 Algorithm selected medium-scale %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% End diagnostic information
max Directional First-order Iter F-count f(x) constraint Step-size derivative optimality 1 28 -7916.01 -2.01e-006 7.63e-006 857 1.42e+005 2 36 -7959.65 -1.508e-006 0.25 389 9.8e+007 3 45 -7963.98 -3.113e-006 0.125 131 5.29e+006 4 52 -7965.59 -1.586e-006 0.5 55.9 4.45e+007 5 65 -7966.9 -1.574e-006 0.00781 101 1.46e+007 6 74 -7969.46 -2.201e-006 0.125 14.9 2.77e+007 7 83 -7973.56 -2.663e-006 0.125 36.6 1.45e+007 8 90 -7982.09 -1.332e-006 0.5 -6.39 5.59e+006 9 103 -7982.13 -1.399e-006 0.00781 6.49 1.32e+006 10 111 -7982.53 -1.049e-006 0.25 12.5 1.87e+007 11 120 -7982.56 -1.186e-006 0.125 3.72 3.8e+006 12 128 -7983.69 -1.11e-006 0.25 0.184 4.91e+006 13 134 -7983.91 -7.813e-007 1 0.732 1.22e+006 14 140 -7983.98 -9.265e-007 1 0.186 1.17e+006 15 146 -7984 -8.723e-007 1 0.0427 9.52e+005 16 154 -7984 -8.775e-007 0.25 0.0152 6.33e+005 17 160 -7984 -8.75e-007 1 0.00197 6.98e+005 18 166 -7984 -8.763e-007 1 0.000931 7.38e+005 19 173 -7984 -8.759e-007 0.5 0.000469 7.37e+005 20 179 -7984 -8.761e-007 1 0.00012 7.22e+005 21 199 -7984 -8.761e-007 -6.1e-005 0.0167 7.37e+005 22 213 -7984 -8.761e-007 0.00391 0.00582 7.26e+005 Optimization terminated successfully: Search direction less than 2*options.TolX and maximum constraint violation is less than options.TolCon No Active Constraints
The default value of the Display parameter in the specification structure is 'on'. As a result, garchfit prints diagnostic optimization and summary information to the command window in the following example. (For information about the Display parameter, see the Optimization Toolbox™ fmincon function.)
Once you complete the estimation, display the parameter estimates and their standard errors using the garchdisp function:
garchdisp(coeff,errors)
Mean: ARMAX(0,0,0); Variance: GARCH(1,1)
Conditional Probability Distribution: Gaussian
Number of Parameters Estimated: 4
Standard T
Parameter Value Error Statistic
----------- ----------- ------------ -----------
C -6.1919e-005 8.4331e-005 -0.7342
K 1.0761e-006 1.323e-007 8.1341
GARCH(1) 0.80598 0.016561 48.6685
ARCH(1) 0.15313 0.013974 10.9586
If you substitute these estimates in the definition of the default model, Equation 2-7 and Equation 2-8, the estimation process implies that the constant conditional mean/GARCH(1,1) conditional variance model that best fits the observed data is
![]()
where G1 = GARCH(1) = 0.80598 and A1 = ARCH(1) = 0.15313. In addition, C = C = -6.1919e-005 and κ = K = 1.0761e-006.
The post-estimation analysis example continues the Pre-Estimation Analysis and Parameter Estimation examples.
This example does the following:
Compares the residuals, conditional standard deviations, and returns.
Uses plots and quantitative techniques to compare correlation of the standardized innovations.
Quantifies and compares correlation of the standardized innovations.
In addition to the parameter estimates and standard errors, garchfit also returns the optimized log-likelihood function value (LLF), the residuals (innovations), and conditional standard deviations (sigmas).
Use the garchplot function to inspect the relationship between the innovations (residuals) derived from the fitted model, the corresponding conditional standard deviations, and the observed returns.
garchplot(innovations,sigmas,dem2gbp)

Both the innovations (shown in the top plot) and the returns (shown in the bottom plot) exhibit volatility clustering. Also, the sum, G1 + A1 = 0.80598 + 0.15313 = 0.95911, is close to the integrated, nonstationary boundary given by the constraints associated with Equation 2-4.
The figure in Comparing the Residuals, Conditional Standard Deviations, and Returns shows that the fitted innovations exhibit volatility clustering.
Plot the standardized innovations (the innovations divided by their conditional standard deviation):
plot(innovations./sigmas)
ylabel('Innovation')
title('Standardized Innovations')

The standardized innovations appear generally stable with little clustering.
Plot the ACF of the squared standardized innovations:
autocorr((innovations./sigmas).^2)
title('ACF of the Squared Standardized Innovations')

The standardized innovations also show no correlation. Now compare the ACF of the squared standardized innovations in this figure to the ACF of the squared returns before fitting the default model. (See Pre-Estimation Analysis.) The comparison shows that the default model sufficiently explains the heteroscedasticity in the raw returns.
Compare the results of the Q-test and the ARCH test with the results of these same tests in Pre-Estimation Analysis:
[H, pValue,Stat,CriticalValue] = ...
lbqtest((innovations./sigmas).^2,[10 15 20]',0.05);
[H pValue Stat CriticalValue]
ans =
0 0.5262 9.0626 18.3070
0 0.3769 16.0777 24.9958
0 0.6198 17.5072 31.4104
[H, pValue, Stat, CriticalValue] = ...
archtest(innovations./sigmas,[10 15 20]',0.05);
[H pValue Stat CriticalValue]
ans =
0 0.5625 8.6823 18.3070
0 0.4408 15.1478 24.9958
0 0.6943 16.3557 31.4104
In the pre-estimation analysis, both the Q-test and the ARCH test indicate rejection (H = 1 with pValue = 0) of their respective null hypotheses. This shows significant evidence in support of GARCH effects. The post-estimate analysis uses standardized innovations based on the estimated model. These same tests now indicate acceptance (H = 0 with highly significant pValues) of their respective null hypotheses. These results confirm the explanatory power of the default model.
![]() | Primary Toolbox Functions | GARCH Specification Structures | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |