I can't ride of an error when fitting model with quantmod, buildModel seems to not work and so use of tradeModel rise error :
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"
Okay, that´s a "mean" documentation. It seems for getSymbols() the function takes over the assignment to a variable but not for buildModel() even though the example in ?buildModel might indicate that.
In short: You need to assign the result from buildModel() to a variable, e.g. q.model. I hope you can laugh about that ;)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With