You are on page 1of 13

125.

811 Advanced Risk Analytics

Week 4
Estimate Volatility models with EViews

1
Estimate the GARCH and EWMA model with Eviews

Autoregressive Conditional Heteroskedasticity (ARCH) model were proposed by Engle (1982), which aims
to capture the volatility clustering and the time-varying (heteroskedasticity) behaviour in the volatility of
the asset returns. This model is then generalized by his student Tim Bollerslev as Generalized ARCH model
(or GARCH, see Bollerslev, 1986). The GARCH-family models are widely used in various areas of
econometrics, particularly for the analysing the financial time series. Nobel Prize in economics for Robert
Engle in 2003 highlights the crucial impact of ARCH type model.

This note will illustrate how you can estimate the GARCH(1,1) model for a S&P 500 returns with a
simplified assumption that the returns of S&P 500 follow a white noise process and is normally distributed,
which needs not to be modelled. White noise process is a random process, with zero autocorrelation (i.e.,
correlation of a variable and its past values), zero mean, and finite variance. In other word, the full
GARCH(1,1) model under this assumption is:

𝑟𝑡 ~𝑖. 𝑖. 𝑑 𝑁(0, 𝜎𝑡2 )


2 2
𝜎𝑡2 = 𝜔 + 𝛼𝑟𝑡−1 + 𝛽𝜎𝑡−1

1. Tests for ARCH effects

Before estimating the model, we need to ensure that there is evidence of the heteroskedasticity, or the
ARCH effect, in the asset returns. If there is evidence of the heteroskedasticity, it means the serial
autocorrelation in the square of asset return is significant. In Eviews, we can employ the correlogram tool
for this initial check.

We first need to estimate the return of the S&P500. Click Quick/Generate Series in EViews

2
To conduct the Correlogram method, generate the square of returns: Click to Quick/Generate Series, and
enter, rsp2 = rsp^2. Double click on the new series rsp2, click to View/Correlogram

Prob = 0.0000 < 0.01 associated with the Q-statistics indicate the serial autocorrelation of the squared
returns are jointly significant, which indicates there is heteroskedasticity in the volatility of the asset
returns. After capturing this characteristic with GARCH-family model, the standardized residuals (i.e.,
𝑟𝑡
𝑧𝑡 = ̂𝑡
) emerged from the estimated model should show no evidence of the heteroskedasticity. This
𝜎
can be a step in the model diagnostics.

2. Estimate GARCH(1,1) model

As there is evidence of the heteroskedasticity, or in other word, the evidence that conditional volatility is
time-varying, we can employ the GARCH family model or EWMA model to capture this behaviour or the
volatility of asset returns. In this section, we illustrate how to estimate the GARCH(1,1) model with Eviews.

We can estimate the GARCH(1,1) by clicking to Quick/Estimate Equation. Type in the box, rsp , and choose
the method ARCH – Autoregressive Conditional Heteroskedasticity

3
A pop-up box appears. In the default setting, the model is GARCH(1,1), the error distribution is normal
distribution and there is no restriction on variance target. You can customize these options to suit your
need and to match with the data you have, e.g., change the distribution of the financial returns to a more
fat-tail distribution such as t-distribution or GED, set the variance target as restriction, change the volatility
model to other types of the GARCH-family models.

In the mean equation (currently we do not model the mean equation, which is the return itself, so that
we simply put as rsp in the box of mean equation), you can also customize it with some explanatory
variables that explain the returns, e.g., some Autoregressive types model, CAPM model and so on.

For example, for the ARMA(1,1) model used for the mean equation: 𝑟𝑡 = 𝜙0 + 𝜙1 𝑟𝑡−1 + 𝛾𝜖𝑡−1 + 𝜖𝑡 , you
can write in the mean equation box as: rsp c ar(1) ma(1)

4
Click ok, you will see the output as follows:

5
For model diagnostics, in this Equation window, click to View/Residual Diagnostics, then you can choose
either Correlogram Squared Residuals or ARCH LM test. If they show no significant serial correlation,
then the model has captured the heteroskedasticity efficiently.

Below are examples. First, we look at the Correlogram of the Squared Residuals:

Prob associated with Q-stat is very high (greater than 0.05), indicating the serial correlation is insignificant.

Second, we can look at the ARCH LM test (say choose lag 5, that is, we jointly test for the serial correlation
from time t-5 up to now)

6
Prob is also high, indicating the joint test shows evidence of insignificant serial correlation in the squared
standardized residual.

In summary, the GARCH(1,1) has captured the heteroskedasticity efficiently.

3. Estimate the Exponentially Weighted Moving Average (EWMA) for volatility

EViews does not provide built-in tool to estimate the EWMA, so we need to build a Log likelihood object
to estimate the model. The EWMA model for volatility is:

2 2
𝜎𝑡2 = 𝜆𝜎𝑡−1 + (1 − 𝜆)𝑟𝑡−1

The likelihood function part as presented in the slides which need to be maximized to obtain the optimal
parameter is:

2 𝑟𝑖2
− ln(𝜎𝑖 ) − 2
𝜎𝑖

Note that when the numerical optimization (i.e., EViews will search the optimal value of 𝜆 using an
algorithm using a specified starting value), we will need to declare the 𝜆 and it starting value for the
algorithm to search. So first we need to create an object which tells Eviews which coefficient need to be
estimated and what is the starting value. Click to Object/New Object and choose Matrix-Vector-Coef and
name it with LAMBDA, choose Coefficient Vector with 1 row and 1 column as we only have one
parameter. After the coefficient vector is created, you can edit the starting value, let make it 0.1.

7
Next we need to generate the first value of the 𝜎12 , so that it can be used to generate the 𝜎𝑡2 recursively
given 𝜆. We can proxy this first value as equal to 𝑟12 . Click Quick/Generate Series in EViews

Now we can create the Logl object in EViews following this formula, by clicking to Object/New Object and
choose LogL. Let name it as EWMA for in the Name for Object box,

Type in the box the following commands:

8
Click to Estimate, and a pop-up will appear, type in the sample that we use to estimate the EWMA model
(note that the sample we choose will not include any missing observation) 7/20/2005 8/13/2010

4. Codes for reference

4.1 Codes to estimate the GARCH(1,1) and EWMA

'*********************************************************************************
*******************************************
'Estimate the GARCH(1,1) model
'Estimate EWMA model
'Consider the return is a whitenoise process, which mean the mean equation of returns need not to
be modelled
'*********************************************************************************
*******************************************

'change path to program path


%path=@runpath
cd %path

'Import the XLS data this code is generalized so that you can import file with more than 1 sheet
%names = @tablenames("SP500.xls")
%n = @word(%names,1)
wfopen "SP500.xls" range=%n
for !i=2 to @wcount(%names)
%n = @word(%names, !i)
import "SP500.xls" range=%n
next

' set all sample


smpl @all

9
'Calculate the log return of S&P500
genr rsp=log(sp500/sp500(-1))

'***********************************************************
'Estimate the GARCH(1,1) model
'***********************************************************
equation garchsp.arch(1,1) rsp
garchsp.garch

'***********************************************************
'Estimate the EWMA model
'***********************************************************
' declare coef vectors to use in EWMA likelihood
coef(1) lambda = .1

' set presample values of expressions in logl


sample s0 7/19/2005 7/19/2005
smpl s0
series sig2 = rsp^2

'set up EWMA likelihood (one alternative setup)


'logl ewma
'ewma.append @logl logl
'ewma.append sig2 = (1-lambda(1))*rsp(-1)^2 +lambda(1)*sig2(-1)
'ewma.append z = rsp/@sqrt(sig2)
'ewma.append logl = log(@dnorm(z)) - log(sig2)/2

'set up EWMA likelihood (another setup which is equivalent with the formula derived in the slide
logl ewma
ewma.append @logl logl
ewma.append sig2 = (1-lambda(1))*rsp(-1)^2 +lambda(1)*sig2(-1)
ewma.append z = rsp/@sqrt(sig2)
ewma.append logl = - log(sig2) - z^2

'Estimate and display results


smpl 7/20/2005 8/13/2010
ewma.ml(showopts, m=1000, c=1e-5)
show ewma.output

4.2 Codes to generate the daily Value-at-Risk series using the estimated volatility

This program divided the sample into in-sample used for estimating the GARCH(1,1) model (between
7/18/2005 and 07/07/2009) and out-of-sample used for forecasting (between 07/08/2009 and
08/13/2010).

• The GARCH model is re-estimated every nearly 6 months


• After each estimation, the model parameters are used to generate the volatility forecasting using
the static forecasts (one-step-ahead forecasts)

10
• The forecasted volatilities are then used to calculate the Value-at-Risk in the next day
• Compare the Value-at-Risk and the observed return to see whether the model produce a good
VaR forecasts (i.e., the hit series and loss series, hit=1 meaning not a good forecast due to the
observed returns > the forecasted VaR)

'*******************************************************************************
'Program for moving window forecasting of return quantiles (Value-at-Risk)
'Using the GARCH(1,1) model for returns with constant mean
'Estimation window = 1000 observations
'Re-estimate every 120 observations, i.e every year
‘Hung Do
'*******************************************************************************

'change path to program path


%path=@runpath
cd %path

'Import the XLS data this code is generalized so that you can import file with more than 1 sheet
%names = @tablenames("SP500.xls")
%n = @word(%names,1)
wfopen "SP500.xls" range=%n
for !i=2 to @wcount(%names)
%n = @word(%names, !i)
import "SP500.xls" range=%n
next

'Calculate the log return of S&P500


genr rsp=log(sp500/sp500(-1))

'length of the workfile


!length=@obsrange

'set window size to estimate the model


!window=1000

'set step size (re-estimate every 120 observations)


!step=120

'create an equation object for garch


equation garchsp

'create a matrix to store the coefficients of GARCH(1,1) for each estimation


matrix(((!length-!window)/!step),4) garch_coef

'declare the series for the mean, volatility and return quantile forecasts
series mean_f
series vol_f
series garch_qf1
series garch_hit1

11
series garch_loss1
series garch_qf5
series garch_hit5
series garch_loss5

'indexing of matrix
!j=1

'move the samples by 120 observations at a time

for !i=1 to !length-!window+1-!step step !step

'set sample to estimation period


smpl @first+!i-1 @first+!i+!window-2

'estimate equation
garchsp.arch(1,1,h,m=5000) rsp c

'store the estimated coefficients in the matrix


garch_coef(!j,1)=garchsp.@coefs(1)
garch_coef(!j,2)=garchsp.@coefs(2)
garch_coef(!j,3)=garchsp.@coefs(3)
garch_coef(!j,4)=garchsp.@coefs(4)
!j=!j+1

' reset sample to forecast period


smpl @first+!i+!window-1 8/13/2010

'forecast mean, volatility and quantiles using static forecast (one-step-ahead)


garchsp.fit(f=na) temp_mu temp_vol

'copy data from current forecast sample to the storage series


mean_f=temp_mu
vol_f=temp_vol

next

'reset the sample to the out-of-sample period


smpl 7/08/2009 8/13/2010

'compute the forecasted quantiles from the forecasted mean and volatility, the hit series, and loss
garch_qf5=mean_f+(@qnorm(0.05)*vol_f)
garch_hit5=(rsp<garch_qf5)
garch_loss5=(0.05-garch_hit5)*(rsp-garch_qf5)
garch_qf1=mean_f+(@qnorm(0.01)*vol_f)
garch_hit1=(rsp<garch_qf1)
garch_loss1=(0.01-garch_hit1)*(rsp-garch_qf1)

'plot the observed returns with the forecasted quantiles

12
graph garch_rq5.line rsp garch_qf5
garch_rq5.options size(8,4) linepat
garch_rq5.axis(bottom) -label
garch_rq5.setelem(1) lcolor(blue) lpat(solid) legend(Observed S&P500 return)
garch_rq5.setelem(2) lcolor(red) lpat(solid) legend(Forecasted 5% Quantiles from GARCH(1,1))
%comment= "Out-of-Sample Forecasted 5% Quantiles from GARCH(1,1) Model"
garch_rq5.addtext(t) %comment
show garch_rq5
garch_hit5.stats
garch_loss5.stats

graph garch_rq1.line rsp garch_qf1


garch_rq1.options size(8,4) linepat
garch_rq1.axis(bottom) -label
garch_rq1.setelem(1) lcolor(blue) lpat(solid) legend(Observed S&P500 return)
garch_rq1.setelem(2) lcolor(red) lpat(solid) legend(Forecasted 1% Quantiles from GARCH(1,1))
%comment= "Out-of-Sample Forecasted 1% Quantiles from GARCH(1,1) Model"
garch_rq1.addtext(t) %comment
show garch_rq1
garch_hit1.stats
garch_loss1.stats

13

You might also like