IBM股票 1967年1月到2009年12月的月对数收益率,共516个观测值。
1.R语言程序
>source("D:/Egarch.R") #编译R语言程序
> da1=read.table("D:/ch2data/m-ibmsp6709.txt",header=T) #打开文件
> dim(da1) #数据框da1的维数,用da1是避免和da混淆
[1] 516 3 #516个观察值,共有3列数据,可用head(da1)look at data
> ibm=log(da1$ibm+1) #对ibm列数据取对数
> Box.test(ibm,lag=12,type='Ljung') #Ljung Box检测
Box-Ljung test
data: ibm
X-squared = 7.4042, df = 12, p-value = 0.8298
#可知Q(12)=7.4042,p值0.8298不显著
> m1=Egarch(ibm) #建立Egarch()模型
Estimation results of EGARCH(1,1) model:
estimates: 0.006732389 -0.5983263 0.217603 -0.4243245 0.92015
std.errors: 0.002877666 0.2349172 0.05916528 0.1683064 0.0388656
t-ratio: 2.339531 -2.546967 3.677882 -2.521144 23.67518
> names(m1)
[1] "residuals" "volatility"
> stresi=m1$residuals/m1$volatility #标准差
> tdx=c(1:516)/12+1967 #时间坐标1967年开始
>par(mfcol=c(2,1))
>plot(tdx,ibm,xlag='year',ylab='logrtn',type='l')
>plot(tdx,stresi,xlab='year',ylab='stresi',type='l')
> Box.test(stresi,lag=10,type="Ljung")
Box-Ljung test
data: stresi
X-squared = 5.2866, df = 10, p-value = 0.8712
#Q(10)=5.2866,p值0.8712
>Box.test(stresi,lag=20,type="Ljung")
Box-Ljung test
data: stresi
X-squared = 20.983, df = 20, p-value = 0.3981
> Box.test(stresi^2,lag=10,type="Ljung")
Box-Ljung test
data: stresi^2
X-squared = 5.0469, df = 10, p-value = 0.888
> Box.test(stresi^2,lag=20,type="Ljung")
Box-Ljung test
data: stresi^2
X-squared = 14.261, df = 20, p-value = 0.817
转载网址:http://rsoftware.h.baike.com/article-1940611.html