r - R中ugarchfit函数的循环函数
问题描述
我有时间序列数据。我已返回数据并获得日志返回。我的目标是从模型列表中选择最合适ARMA-GARCH
的模型。我不想单独拟合每个模型,而是想一次拟合这些模型并从中选择最好的。因此,我制作了一个扭曲函数来为我完成这项工作。例如,我想拟合几个模型:
1- ARMA(1,1)-GARCH(1,1)
2- ARMA(1,2)-GARCH(1,1)
3- ARMA(1,3)-GARCH(1,1)
4- ARMA(2,1)-GARCH(1,1)
5- ARMA(2,2)-GARCH(1,1)
6- ARMA(2,3)-GARCH(1,1)
.. ..
1- ARMA(1,1)-GARCH(1,2)
2- ARMA(1,1)-GARCH(1,3)
3- ARMA(1,1)-GARCH(2,1)
等等。也就是说,让ARMA(p,q)
范围从1:6
,GARCH(p,q)
也从1:6
。如何使用loop
R 中的函数来执行此操作。我想返回AIC
所有模型中最小的标准 ( )。换句话说,我希望我的函数在不同的订单之间自动循环。
这是我的尝试:
GarchWarp <- function(n,dat,d){ ## n is the order of the model. d is the dimension of the data, for example, one series, two series.
GarchWarp <- function(n,dat,d){
meanModel <- varModel <- list()
if(n > 1){
for(i in 1:n){
meanModel[i] <- list(armaOrder = c(i,i)) # ARMA
varModel <- list(model = "sGARCH", garchOrder = c(i,i)) # GARCH
uspec <- ugarchspec(varModel, mean.model = meanModel,
distribution.model = "std") # scaled Student t
fitPC <- apply(dat, 2, function(x) ugarchfit(uspec, data = x))
Recrit <- lapply(1:d, function(i) infocriteria(fitPC[[i]]))
}
}
return(Recrit)
}
我的循环功能不起作用
我的数据样本:d=2
.
structure(c(0.00618750144876756, 0.00491561236137983, 0.00178237912109402,
0.0052134813154332, 0.00129554617030614, 0.00232162478086728,
0, 0.0320481134224817, 0.00881819387210214, 0, 0.00569585759405733,
-0.00259413863757629), class = c("xts", "zoo"), index = structure(c(1514851200,
1514937600, 1515024000, 1515110400, 1515369600, 1515456000), tzone = "UTC", tclass = c("POSIXct",
"POSIXt")), .Dim = c(6L, 2L), .Dimnames = list(NULL, c("P_Sha",
"P_Jap")))
解决方案
推荐阅读
- android - 在 Graphql 突变上获取内部服务器错误 500
- javascript - 删除属性和类
- azure - Azure API 管理速率限制(按 Json 正文)
- python - 有没有办法让不和谐的机器人屏幕共享网站
- android - 显示键盘时全屏 AlertDialog 有 janky 动画
- reactjs - jsonserver 不使用重写器重定向
- angular - Kubernetes 中的 Angular 和 dotnetcore 连接抛出 404
- angular - 使用 fakeasync 时出错 - 但它在其他地方有效
- python - kivy Python:等待登录密码检查代码时的动画图片
- python - 多索引数据框删除每组最大值的行