gpt4 book ai didi

R quantmod buildModel()不适合模型

转载 作者:行者123 更新时间:2023-12-01 11:21:30 27 4
gpt4 key购买 nike

当使用 quantmod 拟合模型时,我无法避免错误,buildModel 似乎不起作用,因此使用 tradeModel 会出现错误:

getSymbols('GS',src='yahoo')

q.model = specifyModel(Next(OpCl(GS)) ~ Lag(OpHi(GS),0:3))

buildModel(q.model, method='lm',training.per=c('2007-08-01','2007-09-30'))
> q.model # it seems that model is still 'None fitted' ?

quantmod object: Build date:

Model Specified:
Next(OpCl(GS)) ~ Lag(OpHi(GS), 0:3)

Model Target: Next.OpCl.GS Product: GS
Model Inputs:

Fitted Model:

None Fitted

tradeModel(q.model,plot.model=TRUE,trade.dates=c("2008-01-01","2008-12-31"))

Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "NULL"

最佳答案

好的,这是一个“平均”文档。对于 getSymbols() 函数似乎接管了对变量的赋值,但对于 buildModel() 却没有,即使 ?buildModel 中的示例可能表明。简而言之:您需要将 buildModel() 的结果分配给一个变量,例如q.模型。我希望你能对此大笑 ;)

library(quantmod)
getSymbols(Symbols = 'GS', src = 'yahoo')
q.model <- specifyModel(Next(OpCl(GS)) ~ Lag(OpHi(GS), 0:3))
q.model <- buildModel(q.model, method = 'lm', training.per = c('2007-08-01','2007-09-30'))
q.model

关于R quantmod buildModel()不适合模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42180471/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com