报错信息:
Error in my_series_sigma(x) : task 165 failed - "找不到对象'B'"
代码如下:
my_series_sigma <- function(i) {
library(rugarch)
data_temp <- data[(i):(99+i)]
ug_spec <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1, 1)), #这个是必须要加
mean.model = list(armaOrder = c(1, 1)), #这个不要随便改,不然有错误
distribution.model = "std")
ugfit <- ugarchfit(ug_spec, data = data_temp)
fit_temp <- ugarchforecast(ugfit, data = data_temp, n.ahead = 1)
temp_data <- data.frame(t(fit_temp@forecast[["sigmaFor"]]),t(fit_temp@forecast[["seriesFor"]]))
colnames(temp_data) <- c("sigma", 'series')
return(temp_data)
}
install.packages("doParallel")
library(doParallel)
cl <- makeCluster(detectCores())
registerDoParallel(cl) #注册并开始并行计算
result_parallel <- foreach(x=c(1:(1800-100+1)),.combine='rbind') %dopar% my_series_sigma(x)
stopCluster(cl)
write.csv(result_parallel, file = "my_result_sigma_series.csv")