当我使用quantmod
包时,我调用buildModel
命令时会出现问题。
library(quantmod)
getSymbols("TSLA",from='2015-03-01')
q.model = specifyModel(Next(OpCl(TSLA)) ~ Lag(OpHi(TSLA),0:3),na.rm = T)
buildModel(q.model,method='lm',training.per=c('2015-09-01','2010-10-01'))
但是当我拨打buildModel
eval(expr,envir,enclos)中的错误:object' Next.OpCl.TSLA'找不到
有谁知道如何解决这个问题?
答案 0 :(得分:1)
正如Pascal指出的那样,你的功能有一个错字:第二次使用2015而不是2010:
buildModel(q.model,method='lm',training.per=c('2015-09-01','2015-10-01'))
^
如果日期按时间顺序排列,我就不再有问题:
quantmod object: lm1446193179.60143 Build date: 2015-10-30 09:17:52
Model Specified:
Next(OpCl(TSLA)) ~ Lag(OpHi(TSLA), 0:3)
Model Target: Next.OpCl.TSLA Product: TSLA
Model Inputs: Lag.OpHi.TSLA.0.3.Lag.0, Lag.OpHi.TSLA.0.3.Lag.1, Lag.OpHi.TSLA.0.3.Lag.2, Lag.OpHi.TSLA.0.3.Lag.3
Fitted Model:
Modelling procedure: lm
Training window: 22 observations from 2015-09-01 to 2015-10-01
Call:
lm(formula = quantmod@model.formula, data = training.data)
Coefficients:
(Intercept) Lag.OpHi.TSLA.0.3.Lag.0 Lag.OpHi.TSLA.0.3.Lag.1
-0.001594 -0.147112 -0.041063
Lag.OpHi.TSLA.0.3.Lag.2 Lag.OpHi.TSLA.0.3.Lag.3
0.261051 -0.023408