| GARCH Toolbox™ | ![]() |
| On this page… |
|---|
This section uses an AR(R)/GARCH(P,Q) model to fit a simulated return series to the defined model.
Define an AR(2)/GARCH(1,1) model. Start by creating a specification structure for an AR(2)/GARCH(1,1) composite model. Set the 'Display' parameter 'off' to suppress the optimization details that garchfit normally displays.
spec = garchset('AR',[0.5 -0.8],'C',0,'Regress',[0.5 -0.8],...
'GARCH',0.7,'ARCH',0.1,'K',0.005,...
'Display','off')
spec =
Comment: 'Mean: ARMAX(2,0,?); Variance: GARCH(1,1)'
Distribution: 'Gaussian'
R: 2
C: 0
AR: [0.5000 -0.8000]
Regress: [0.5000 -0.8000]
VarianceModel: 'GARCH'
P: 1
Q: 1
K: 0.0050
GARCH: 0.7000
ARCH: 0.1000
Display: 'off'
In this specification structure, spec:
The model order fields R, M, P, and Q are consistent with the number of coefficients in the AR, MA, GARCH, and ARCH vectors, respectively.
Although the Regress field indicates two regression coefficients, the Comment field still contains a question mark as a placeholder for the number of explanatory variables.
There is no model order field for the Regress vector, analogous to the R, M, P, and Q orders of an ARMA(R,M)/GARCH(P,Q) model.
Fit the model to a simulated return series. Simulate 2000 observations of the innovations, conditional standard deviations, and returns for the AR(2)/GARCH(1,1) process defined in spec. Use the model defined in spec to:
Estimate the parameters of the simulated return series.
Compare the parameter estimates to the original coefficients in spec.
randn('state',0);
rand('twister',0);
[e,s,y] = garchsim(spec,2000,1);
[coeff,errors] = garchfit(spec,y);
garchdisp(coeff,errors)
Mean: ARMAX(2,0,0); Variance: GARCH(1,1)
Conditional Probability Distribution: Gaussian
Number of Model Parameters Estimated: 6
Standard T
Parameter Value Error Statistic
----------- ----------- ------------ -----------
C -0.00044755 0.0034623 -0.1293
AR(1) 0.50257 0.01392 36.1049
AR(2) -0.8002 0.013981 -57.2344
K 0.0050532 0.001971 2.5637
GARCH(1) 0.70954 0.095319 7.4439
ARCH(1) 0.083296 0.022665 3.6752
The estimated parameters, shown in the Value column, are close to the true coefficients in spec.
Because you specified no explanatory regression matrix as input to garchsim and garchfit, these functions ignore the regression coefficients (Regress). The garchdisp output shows a 0 for the order of the regression component.
To illustrate the use of a regression matrix, fit the return series y, an AR(2) process in the mean, to a regression model with two explanatory variables. The regression matrix consists of the first- and second-order lags of the simulated return series y. The return series y was simulated in Fitting a Model to a Simulated Return Series.
Remove the AR component. First, remove the AR component from the specification structure:
spec = garchset(spec,'R',0,'AR',[])
spec =
Comment: 'Mean: ARMAX(0,0,?); Variance: GARCH(1,1)'
Distribution: 'Gaussian'
C: 0
Regress: [0.5000 -0.8000]
VarianceModel: 'GARCH'
P: 1
Q: 1
K: 0.0050
GARCH: 0.7000
ARCH: 0.1000
Display: 'off'
Create the regression matrix. Create a regression matrix of first- and second-order lags using the simulated returns vector y from Fitting a Model to a Simulated Return Series as input. Examine the first 10 rows of y and the corresponding rows of the lags:
X = lagmatrix(y,[1 2]);
[y(1:10) X(1:10,:)]
ans =
0.0562 NaN NaN
0.0183 0.0562 NaN
-0.0024 0.0183 0.0562
-0.1506 -0.0024 0.0183
-0.3937 -0.1506 -0.0024
-0.0867 -0.3937 -0.1506
0.1075 -0.0867 -0.3937
0.2225 0.1075 -0.0867
0.1044 0.2225 0.1075
0.1288 0.1044 0.2225
Examine the regression matrix. A NaN (Not-a-Number) in the resulting matrix X indicates the presence of a missing observation. If you use X to fit a regression model to y, garchfit produces an error:
[coeff,errors] = garchfit(spec,y,X); ??? Error using ==> garchfit Regression matrix 'X' has insufficient number of observations.
The error occurs because there are fewer valid rows (rows without a NaN) in the regression matrix X than there are observations in y. The returns vector y has 2000 observations, but the most recent number of valid observations in X is only 1998.
Repair the regression matrix. You can do one of two things in order to proceed. For a return series of this size, it makes little difference which option you choose:
Strip off the first two observations in y.
Replace all NaNs in X with some reasonable value.
This example continues by replacing all NaNs with the sample mean of y. Use the MATLAB® function isnan to identify NaNs and the function mean to compute the mean of y:
X(isnan(X)) = mean(y);
[y(1:10), X(1:10,:)]
ans =
0.0562 0.0004 0.0004
0.0183 0.0562 0.0004
-0.0024 0.0183 0.0562
-0.1506 -0.0024 0.0183
-0.3937 -0.1506 -0.0024
-0.0867 -0.3937 -0.1506
0.1075 -0.0867 -0.3937
0.2225 0.1075 -0.0867
0.1044 0.2225 0.1075
0.1288 0.1044 0.2225
Note If the number of valid rows in X exceeds the number of observations in y, then garchfit includes in the estimation only the most recent rows of X, equal to the number of observations in y. |
Fit the regression model. Now the explanatory regression matrix X is compatible with the return series vector y. Use garchfit to estimate the model coefficients for the return series using the regression matrix, and display the results:
[coeffX,errorsX] = garchfit(spec,y,X);
garchdisp(coeffX,errorsX)
Mean: ARMAX(0,0,2); Variance: GARCH(1,1)
Conditional Probability Distribution: Gaussian
Number of Model Parameters Estimated: 6
Standard T
Parameter Value Error Statistic
----------- ----------- ------------ -----------
C -0.00044754 0.0034628 -0.1292
Regress(1) 0.50257 0.01392 36.1048
Regress(2) -0.8002 0.013981 -57.2346
K 0.0050526 0.0019708 2.5637
GARCH(1) 0.70957 0.095311 7.4447
ARCH(1) 0.083292 0.022663 3.6752
These estimation results are like those shown for the AR model in the section Fitting a Model to a Simulated Return Series. This similarity illustrates the asymptotic equivalence of autoregressive models and linear regression models.
This part of the example illustrates the extra steps involved in formatting the explanatory matrix. It also highlights the additional complexity involved in modeling conditional means with regression components.
![]() | Introduction | Simulation and Inference Using a Regression Component | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |