Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R quantmod buildModel() does not fit model

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"
like image 432
Qbik Avatar asked Aug 08 '26 06:08

Qbik


1 Answers

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
like image 151
Tonio Liebrand Avatar answered Aug 10 '26 23:08

Tonio Liebrand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!