使用方法错误(“预测”):没有适用于';预测';适用于“类”的对象;c(“uGARCHfit';,';GARCHfit';,';rGARCH';)”;在R
我通过“”的API动态获取财务数据。为此,我使用此脚本使用方法错误(“预测”):没有适用于';预测';适用于“类”的对象;c(“uGARCHfit';,';GARCHfit';,';rGARCH';)”;在R,r,time-series,R,Time Series,我通过“”的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 &
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)
}
因此,带有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))
我得到了错误
Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "c('uGARCHfit', 'GARCHfit', 'rGARCH')"
看起来您只是使用了一个错误的函数。试试看
ugarchforecast(garch, n.ahead = 5)
看起来您只是使用了一个错误的函数。试试看
ugarchforecast(garch, n.ahead = 5)
另外,package
rugarch
使用S4类,predict
S3类。@Julius Vainora,我将从spec@cbool的这一行每隔5分钟运行一次预测脚本,理解您最初问题的这一部分有点困难,但听起来您可以继续加载csv文件,重新绑定新的预测并保存它,不如果没有帮助,那么是的,你可以发布一个新的问题,但是要确保那里的代码是最少的。例如,添加garch@fit$sigma
回答这个问题。@Julius Vainora,一个liitle位否,我也创建了一个新帖子,packagerugarch
使用S4类,predict
S3类。@Julius Vainora,我将从这行spec@cbool中每隔5分钟运行一次预测脚本,要理解你最初问题的这一部分有点困难,但听起来你可以继续加载csv文件,然后重新绑定新的预测并保存,不是吗?如果没有帮助,那么是的,你可以发布一个新的问题,但是要确保那里的代码是最少的。例如,添加garch@fit$sigma
回答这个问题。@Julius Vainora,不,我写了一篇新文章
ugarchforecast(garch, n.ahead = 5)