r - UseMethod(“predict”)中的错误:没有适用于“predict”的方法应用于 R 中类“c('uGARCHfit','GARCHfit','rGARCH')”的对象
问题描述
我通过“ https://api.coindesk.com/v1/bpi/currentprice/USD.json ”的API动态获取财务数据,为此我使用此脚本
library("rjson")
json_file <- "https://api.coindesk.com/v1/bpi/currentprice/USD.json"
numOfTimes <- 2L # how many times to run in total
sleepTime <- 60L # time to wait between iterations (in seconds)
iteration <- 0L
while (iteration < numOfTimes) {
# gather data
json_data <- fromJSON(paste(readLines(json_file), collapse=""))
# get json content as data.frame
x = data.frame(json_data$time$updated,json_data$time$updatedISO,json_data$time$updateduk,json_data$bpi$USD)
# create file to save in 'C:/Myfolder'
# alternatively, create just one .csv file and update it in each iteration
nameToSave <- nameToSave <- paste('C:/Myfolder/',
gsub('\\D','',format(Sys.time(),'%F%T')),
'json_data.csv', sep = '_')
# save the file
write.csv(x, nameToSave)
# update counter and wait
iteration <- iteration + 1L
Sys.sleep(sleepTime)
}
此脚本由 cmd 文件每分钟由 Win8.1 中的调度程序运行
"C:\Program Files\R\R-3.5.1\bin\x64\Rcmd.exe" BATCH "E:\Rdev\bitcoin.R"
因此,带有 csv 的文件夹会被新的 csv 动态更新。
假设我创建了 GARCH-ARMA 模型
require(rugarch)
#We can then compute the ARMA(1,1)-GARCH(1,1) model as an example:
spec <- ugarchspec(variance.model = list(model = "sGARCH",
garchOrder = c(1, 1),
submodel = NULL,
external.regressors = NULL,
variance.targeting = FALSE),
mean.model = list(armaOrder = c(1, 1),
external.regressors = NULL,
distribution.model = "norm",
start.pars = list(),
fixed.pars = list()))
garch <- ugarchfit(spec = spec, data = df$rate_float, solver.control = list(trace=0))
现在当我这样做的时候
predict(garch, n.ahead = 5)
我得到了错误
Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "c('uGARCHfit', 'GARCHfit', 'rGARCH')"
解决方案
似乎您只是使用了错误的功能。试试吧
ugarchforecast(garch, n.ahead = 5)
推荐阅读
- java - 如何在 gridbaglayout 中使 jtextarea 可滚动
- mongodb - 如何重置 MongoDB 连接?
- css - Shopify 液体模板中带有文本叠加的图像
- docker - Zeppelin 中的 python.sql 错误:NameError: name 'pd' is not defined
- filter - ffmpeg过滤器使视频矩形/正方形
- c# - 如何并行化/异步此方法?
- angular - 如何根据父div是否有焦点有条件地显示div的孩子?
- domain-driven-design - 我可以说轴突命令和事件被视为贫血模型吗?
- game-development - 玩家无法在程序生成的地图中正确生成
- python - 使用 python mutagen 获取歌词