使用最大似然估计GARCH

时间:2016-09-06 10:44:27

标签: r optimization volatility

我正在尝试使用模拟数据的最大似然估计GARCH(1,1)模型。这就是我得到的:

library(fGarch)
set.seed(1)
garch11<-garchSpec(model = list())
x<-garchSim(garch11, n = 1000)
y <- t(x)
r <- y[1, ]

### Calculate Residuals
CalcResiduals <- function(theta, r)
{
  n <- length(r)
  omega<-theta[1]
  alpha11<-theta[2]
  beta11<-theta[3]
  sigma.sqs <- vector(length = n)
  sigma.sqs[1] <- 0.02
  for (i in 1:(n-1)){
    sigma.sqs[i+1] <- omega + alpha11*(r[i]^2) + beta11*sigma.sqs[i]
  }
  return(list(et=r, ht=sigma.sqs))
}

###Calculate the log-likelihood

GarchLogl <- function(theta, r){
  res <- CalcResiduals(theta,r)
  sigma.sqs <- res$ht
  r <- res$et
  return(-sum(dnorm(r[-1], mean = 0, sd = sqrt(sigma.sqs[-1]), log = TRUE)))
}

fit2 <- nlm(GarchLogl, # function call 
            p = rep(1,3), # initial values = 1 for all parameters
            hessian = FALSE, # also return the hessian matrix
            r = r , # data to be used
            iterlim = 500) # maximum iteration

很遗憾,我收到以下错误消息但没有结果

  

有50个或更多警告(使用警告()查看前50个)   1:在sqrt(sigma.sqs [-1])中:生成NaNs

     

2:在nlm中(GarchLogl,p = rep(1,3),hessian = FALSE,数据&lt; -r,...:   NA / Infdurchgrößte正面Zahl ersetzt

你知道我的代码有什么问题吗?非常感谢!

0 个答案:

没有答案