Friday, November 29, 2013

Testing AutoRegressive Conditional Heteroskedasticity (ARCH) Effect within R

Even though title as it self "AutoRegressive Conditional Heteroskedasticity (ARCH)" sounds scary, base idea is simple: conditional volatility (heteroskedasticity) of a time series is self (auto) regressive (ARMA (p,q)), in other words volatility is not constant over time:
$$ \sigma_t^2=\alpha_0 + \alpha_1 \epsilon_{t-1}^2 + \cdots + \alpha_q \epsilon_{t-q}^2 = \alpha_0 + \sum_{i=1}^q \alpha_i \epsilon_{t-i}^2 $$

In this text, i explain how to test if a time series has ARCH effect. In above formula, if null hypothesis is chosen as $ \alpha_t=0 $, we can conclude it has ARCH effect if null hypothesis is rejected. Box.test command in R can be used for this purpose. Note Box.test computes Ljung–Box test statistic for examining the null hypothesis of independence in a given time series. Below we analyse log return of Intel from 1973 to 2008.

>data=read.table("http://www.mif.vu.lt/~rlapinskas/DUOMENYS/Tsay_fts3/m-intc7308.txt",header=T)
>ret=log(data[,2]+1)
# lets find out lag 
>a=pacf(ret)
>summary(a)
       Length Class  Mode     
acf    26     -none- numeric  
type    1     -none- character
n.used  1     -none- numeric  
lag    26     -none- numeric  
series  1     -none- character
snames  0     -none- NULL  
# now test if there is a serial correlation
>Box.test(ret,lag=26,type='Ljung')

 Box-Ljung test

data:  ret
X-squared = 37.0152, df = 26, p-value = 0.07452

## As we can not reject the null hypothesis (independence) , we assume there is no serial correlation. 
## So we can now test if variance is constant or not.
> var=(ret-mean(ret))^2
> Box.test(var,lag=26,type='Ljung')

 Box-Ljung test

data:  var
X-squared = 104.7286, df = 26, p-value = 2.073e-11
Box.test shows we can reject the null hypothesis (independence) on variance, so it has significant serial correlation, in other words ARCH effect.

No comments: