UseMethod("predict") 中的错误:没有适用于应用于类“c('uGARCHfit', 'GARCHfit', 'rGARCH')"的对象的“预测"方法;在 R [英] Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "c('uGARCHfit', 'GARCHfit', 'rGARCH')" in R

查看:97
本文介绍了UseMethod("predict") 中的错误:没有适用于应用于类“c('uGARCHfit', 'GARCHfit', 'rGARCH')"的对象的“预测"方法;在 R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过https://api 的 API 动态获取财务数据.coindesk.com/v1/bpi/currentprice/USD.json"为此我使用这个脚本

I dynamically get financial data via API of "https://api.coindesk.com/v1/bpi/currentprice/USD.json" for this i use this script

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)
}    

此脚本在Win8.1中由调度程序每分钟由cmd文件运行

this script run by cmd file every minute by scheduler in Win8.1

"C:\Program Files\R\R-3.5.1\bin\x64\Rcmd.exe" BATCH "E:\Rdev\bitcoin.R"

因此带有 csv 的文件夹由新的 csv 动态更新.

Thus folder with csv dynamically updated by new coming csv.

假设我创建了 GARCH-ARMA 模型

Suppose i created GARCH-ARMA model

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')"

推荐答案

看来您只是使用了错误的函数.试试吧

Seems like you are simply using a wrong function. Try instead

ugarchforecast(garch, n.ahead = 5)

这篇关于UseMethod("predict") 中的错误:没有适用于应用于类“c('uGARCHfit', 'GARCHfit', 'rGARCH')"的对象的“预测"方法;在 R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆