简体   繁体   中英

Trying to automate a loop for garch estimation

I am working with the function ugarchfit (package: rugarch). I made a script in order to estimate different garch models but sometimes the model does not converge.

My script is the following:

#bdd contains 5 exogeneous variables
for(i in 1:5)
 {
  specification<-ugarchspec(variance.model=list(garchOrder=c(1,1)), mean.model=list(armaOrder=c(1,1), external.regressors=bdd[,i])
  fitting<-ugarchfit(specification, out.sample=0)
 }

I would like that my loop does not stop when there is a convergence problem but continues to the next index.

This should do the trick, but you are going to have to write the logic to handle other sorts of errors:

for(i in 1:5)
{
  specification <- suppressWarnings(
                     tryCatch(
                       ugarchspec(variance.model=list(garchOrder=c(1,1)), 
                                  mean.model=list(armaOrder=c(1,1), external.regressors=bdd[,i]))
                       error = function(x) return(NA))
  )
  fitting <- suppressWarnings(
    tryCatch(
      ugarchfit(specification, out.sample=0)
      error = function(x) return(NA))
  )
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM