GARCH模型案例分析
| 分类: 时间序列分析(R语言) |
# (1) read data
library(quantmod)
getSymbols('^HSI', from='1989-12-01',
to='2013-11-30')
dim(HSI)
names(HSI)
chartSeries(HSI,
theme='white')
http://s10/mw690/006pdeFtzy70Uy65aqJ99&690
HSI <-
read.table('HSI.txt')
HSI <-
as.xts(HSI)
# (2) compute return series
ptd.HSI <-
HSI$HSI.Adjusted
rtd.HSI <-
diff(log(ptd.HSI))*100
rtd.HSI <-
rtd.HSI[-1,]
plot(rtd.HSI)
http://s5/mw690/006pdeFtzy70UydPjgw44&690
ptm.HSI <-
to.monthly(HSI)$HSI.Adjusted
rtm.HSI <-
diff(log(ptm.HSI))*100
rtm.HSI <-
rtm.HSI[-1,]
plot(rtm.HSI)
http://s7/mw690/006pdeFtzy70UylFVEa66&690
detach(package:quantmod)
# (3) ARCH效应检验
# rtm.HSI <- as.numeric(rtm.HSI)
ind.outsample <- sub(' ','',substr(index(rtm.HSI), 4, 8)) %in%
'2013'
ind.insample <-
!ind.outsample
rtm.insample <- rtm.HSI[ind.insample]
rtm.outsample <- rtm.HSI[ind.outsample]
Box.test(rtm.insample, lag=12,
type='Ljung-Box')
Box.test(rtm.insample^2, lag=12,
type='Ljung-Box')
FinTS::ArchTest(x=rtm.insample,
lags=12)
# (4) 模型定阶
epst <- rtm.insample -
mean(rtm.insample)
par(mfrow=c(1,2))
acf(as.numeric(epst)^2, lag.max=20, main='平方序列')
pacf(as.numeric(epst)^2, lag.max=20,
main='平方序列')
# (5) 建立GARCH类模型
library(fGarch)
GARCH.model_1 <- garchFit(~garch(1,1), data=rtm.insample,
trace=FALSE)
GARCH.model_2 <- garchFit(~garch(2,1), data=rtm.insample,
trace=FALSE)
GARCH.model_3 <- garchFit(~garch(1,1), data=rtm.insample,
cond.dist='std', trace=FALSE)
GARCH.model_4 <- garchFit(~garch(1,1), data=rtm.insample,
cond.dist='sstd', trace=FALSE)
GARCH.model_5 <- garchFit(~garch(1,1), data=rtm.insample,
cond.dist='ged', trace=FALSE)
GARCH.model_6 <- garchFit(~garch(1,1), data=rtm.insample,
cond.dist='sged', trace=FALSE)
summary(GARCH.model_1)
summary(GARCH.model_3)
plot(GARCH.model_1)
# (6) 提取GARCH类模型信息
vol_1 <-
fBasics::volatility(GARCH.model_1)
sres_1 <- residuals(GARCH.model_1,
standardize=TRUE)
vol_1.ts <- ts(vol_1, frequency=12, start=c(1990, 1))
sres_1.ts <- ts(sres_1, frequency=12, start=c(1990, 1))
par(mfcol=c(2,1))
plot(vol_1.ts, xlab='年', ylab='波动率')
plot(sres_1.ts, xlab='年', ylab='标准化残差')
http://s11/mw690/006pdeFtzy70Uyx7QXUea&690
# (7) 模型检验
par(mfrow=c(2,2))
acf(sres_1, lag=24)
pacf(sres_1, lag=24)
acf(sres_1^2, lag=24)
pacf(sres_1^2, lag=24)
http://s16/mw690/006pdeFtzy70UyzW8vdcf&690
par(mfrow=c(1,1))
qqnorm(sres_1)
qqline(sres_1)
# (8) 模型预测
pred.model_1 <- predict(GARCH.model_1, n.ahead = 11, trace =
FALSE, mse = 'cond', plot=FALSE)
pred.model_2 <- predict(GARCH.model_2, n.ahead = 11, trace =
FALSE, mse = 'cond', plot=FALSE)
pred.model_3 <- predict(GARCH.model_3, n.ahead = 11, trace =
FALSE, mse = 'cond', plot=FALSE)
pred.model_4 <- predict(GARCH.model_4, n.ahead = 11, trace =
FALSE, mse = 'cond', plot=FALSE)
pred.model_5 <- predict(GARCH.model_5, n.ahead = 11, trace =
FALSE, mse = 'cond', plot=FALSE)
pred.model_6 <- predict(GARCH.model_6, n.ahead = 11, trace =
FALSE, mse = 'cond', plot=FALSE)
predVol_1 <-
pred.model_1$standardDeviation
predVol_2 <- pred.model_2$standardDeviation
predVol_3 <- pred.model_3$standardDeviation
predVol_4 <- pred.model_4$standardDeviation
predVol_5 <- pred.model_5$standardDeviation
predVol_6 <- pred.model_6$standardDeviation
et <- abs(rtm.outsample - mean(rtm.outsample))
rtd.HSI.2013 <- rtd.HSI['2013']
rv <- sqrt(aggregate(rtd.HSI.2013^2,
by=substr(index(rtd.HSI.2013), 1, 7), sum))
predVol <-
round(rbind(predVol_1,predVol_2,predVol_3,predVol_4,predVol_5,predVol_6,
colnames(predVol) <- 1:11
rownames(predVol) <-
c('GARCH(1,1)-N模型','GARCH(1,2)-N模型','GARCH(1,1)-t模型','GARCH(1,1)-st模型',
print(predVol)
1 2 3 4 5 6 7 8 9 10 11
GARCH(1,1)-N模型 5.037 5.286 5.513 5.722 5.915 6.094 6.260 6.415 6.560 6.696 6.824
GARCH(1,2)-N模型 4.760 4.747 5.136 5.404 5.661 5.891 6.102 6.296 6.473 6.638 6.789
GARCH(1,1)-t模型 5.347 5.532 5.703 5.864 6.014 6.154 6.286 6.410 6.527 6.638 6.742
GARCH(1,1)-st模型 5.386 5.560 5.722 5.873 6.014 6.146 6.270 6.386 6.495 6.598 6.695
GARCH(1,1)-GED模型 5.168 5.374 5.565 5.741 5.906 6.059 6.203 6.338 6.464 6.583 6.695
GARCH(1,1)-SGED模型 5.229 5.423 5.601 5.767 5.920 6.063 6.197 6.322 6.439 6.548 6.651
残差绝对值 4.147 3.513 3.659 1.464 2.007 7.838 4.584 1.177 4.584 1.026 2.388
已实现波动 3.543 4.114 3.929 4.778 4.374 6.013 5.397 4.634 4.070 3.745 4.395
# (9) 模型选择
cor(t(predVol))

加载中…