When I use quantmod
package there is a problem when I call buildModel
command.
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'))
But there is is an error when I call buildModel
Error in eval(expr, envir, enclos) : object 'Next.OpCl.TSLA' not found
Does anyone know how to solve this problem?
As Pascal pointed out, there is a typo in your function : use 2015 instead of 2010 for your second date:
buildModel(q.model,method='lm',training.per=c('2015-09-01','2015-10-01'))
^
If the dates are in chronological order I haven't got the problem any longer :
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 = [email protected], 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