2

我有时间序列数据。我已返回数据并获得日志返回。我的目标是从模型列表中选择最合适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:6GARCH(p,q)也从1:6。如何使用loopR 中的函数来执行此操作。我想返回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")))
4

0 回答 0