• 收益率取对数
library(timeSeries)
ptd.GZMT <- GZMT$Adjusted # 提取日收盘价信息
rtd.GZMT <- diff(log(ptd.GZMT))*100
• 建立EWMA模型
library(qcc)
data(pistonrings)
attach(pistonrings)
pistonrings
diameter <- qcc.groups(diameter, sample)
q <- ewma(r, lambda=0.94, nsigmas=3)
plot(q)
summary(q)
• 计算VaR
VaR1<-qnorm(0.95)*forecast1@forecast$sigmaFor # VaR = μ + Zα*sigma*sqrt(delta t)
VaR1
ES1<-dnorm(qnorm(0.95))*forecast1@forecast$sigmaFor/0.05
ES1
• 做VaR的回测检验(二项分布或卡方分布)