| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Econometrics Toolbox |
| Contents | Index |
| Learn more about Econometrics 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.
strm = RandStream('mt19937ar','Seed',24685);
RandStream.setDefaultStream(strm);
[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.0022416 0.0033929 0.6607
AR(1) 0.50379 0.014943 33.7136
AR(2) -0.78349 0.01423 -55.0573
K 0.005223 0.0019258 2.7121
GARCH(1) 0.69329 0.092511 7.4941
ARCH(1) 0.098126 0.02558 3.8361The 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 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 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.0123 NaN NaN
0.2196 0.0123 NaN
0.0547 0.2196 0.0123
-0.1138 0.0547 0.2196
-0.1543 -0.1138 0.0547
-0.0566 -0.1543 -0.1138
0.0523 -0.0566 -0.1543
-0.0136 0.0523 -0.0566
0.0482 -0.0136 0.0523
0.0138 0.0482 -0.0136Examine 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.0123 -0.0002 -0.0002
0.2196 0.0123 -0.0002
0.0547 0.2196 0.0123
-0.1138 0.0547 0.2196
-0.1543 -0.1138 0.0547
-0.0566 -0.1543 -0.1138
0.0523 -0.0566 -0.1543
-0.0136 0.0523 -0.0566
0.0482 -0.0136 0.0523
0.0138 0.0482 -0.0136Note 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.0022417 0.0033928 0.6607
Regress(1) 0.50379 0.014944 33.7130
Regress(2) -0.78349 0.014231 -55.0562
K 0.0052229 0.001926 2.7118
GARCH(1) 0.69331 0.092516 7.4940
ARCH(1) 0.098114 0.025579 3.8358These estimation results are like those shown for the AR model in the section Fitting a 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 | Regression in Simulation | ![]() |
View demos and recorded presentations led by industry experts.
Now On Demand
Network with industry peers and learn the latest applications of the leading software product for computational finance.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |