Garch 数据的双重自适应套索实现?

问题描述 投票:0回答:0

我尝试按照论文“西安大略大学刘子珍的时间序列分析的双重自适应 LASSO 方法”中的说明进行编码。 该论文可在此处获取https://ir.lib.uwo.ca/etd/2321/ p.74-79enter image description here

这篇论文是为 Arch 数据做的,我想尝试一下 Garch 数据。但我真的无法让它发挥作用。任何人对我必须如何更改代码有任何建议,或者方法不适用于 Garch 数据? 此外,我无论如何都不是 R 专家,任何建议都将不胜感激,无论是计算效率还是不正确的实施

这篇论文是为 Arch 数据做的,我想尝试一下 Garch 数据。但我真的无法让它发挥作用。任何人对我必须如何更改代码有任何建议,或者方法不适用于 Garch 数据? 此外,我无论如何都不是 R 专家,任何建议都将不胜感激,无论是计算效率还是不正确的实施

我的代码

algorithm

alg5<-function(data=data,thetaa,lamda,weight){
  
  spec <- ugarchspec(variance.model = list(model = "sGARCH", 
                                           garchOrder = c(3, 3)), 
                     mean.model = list(armaOrder = c(0, 0), 
                                       include.mean = FALSE),
                     distribution.model = "norm",  
                     fixed.pars = list(omega=thetaa[1], alpha1=thetaa[2]    ,alpha2=thetaa[3],alpha3=thetaa[4] ,beta1=thetaa[5] ,beta2=thetaa[6],beta3=thetaa[7]))
  
  fit <- ugarchfit(spec,solver = "hybrid", data = data,fit.control=list(fixed.se=1),optim.control = list(trace = 0))
  
  
  hess<-fit@fit$hessian
  S_T<-fit@fit$scores%>%colSums()
  S_T
 
  eigen<-eigen(hess)
  eigen_val<-eigen$values
  eigen_vec<-eigen$vectors
  
  orth<-randortho(length(thetaa))
  
  lamda1=abs(diag(eigen_val))
  surro<-eigen_vec%*%lamda1%*%t(eigen_vec)
  
  x_theta=lamda1^.5%*%t(eigen_vec)

  y_theta=abs(eigen_val)^(-.5)%>%diag()%*%t(eigen_vec)%*%(hess%*%thetaa-S_T)
  
  
  a=numeric(length(thetaa[-1])/2)
  ro=pacf((data)^2,plot = FALSE)
  for (i in 1:(length(thetaa[-1])/2)){
    temp0=c(ro$acf[i:(length(thetaa[-1])/2)])**weight[1]
    a[i]<-sum(temp0)
  }
  
  initial=solve(t(x_theta)%*%x_theta)%*%y_theta
  initial=(initial)
  w=1/(sign(initial)*(abs(initial)^weight[2])*(c(0,a,a)^weight[3]))
  w
  w=(lamda*w)
  w[1]=0
  
  temp=numeric(length(thetaa))
  for (i in 1:length(thetaa)) {
    for (j in 1:length(thetaa)) {
      if(j==i)next
      
      temp[i]=(temp[i]+(x_theta[,i]%>%t()%*%x_theta[,i])%*%thetaa[j]-2*t(x_theta[,i])%*%y_theta)}
   
  }
  
  temp3=rep(0,length(thetaa))
  for (i in 1:length(thetaa)) {
    if (is.nan(w[i])) {
      temp3[i] <- 0 
    } else if (temp[i] < (-w[i])) {
      temp3[i] <- ((-w[i]) - (temp[i])) / (2 * (t(x_theta[,i]) %*% x_theta[,i]))
    } else {
      temp3[i] <- 0
    }
  }
  if(sum(temp3) >= 1) {
    temp3 <- temp3 / sum(temp3) * 0.99
  }
  if (norm((temp3-thetaa)%>%as.matrix(),type = "i")>.0005){thetaa=temp3}
  if(sum(thetaa) >= 1) {
  thetaa <- thetaa / sum(thetaa) * 0.99
  thetaa
}

  return(thetaa)
  
  
}

整个算法(第 78 页)看起来像这样 enter image description here 但我相信问题出在 alg5()

r statistics time-series lasso-regression
© www.soinside.com 2019 - 2024. All rights reserved.