3

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"
Qbik
  • 5,885
  • 14
  • 62
  • 93
  • I think something could be masked by function from another package, ps. `require(quantmod)` work fine, so I don't lack an dependencies – Qbik Feb 11 '17 at 19:56

1 Answers1

5

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
Tonio Liebrand
  • 17,189
  • 4
  • 39
  • 59
  • I'm laughing, seriously – Qbik Feb 13 '17 at 22:01
  • Maybe you also now how to figure out how to put two charts on one plot : `par(mfrow=c(1, 2)); chartSeries(GS, TA=NULL); chartSeries(GS, TA=NULL)` doesn't work ? – Qbik Feb 13 '17 at 22:04
  • 1
    at your service ;) `par(mfrow=c(1, 2)); chartSeries(GS, TA=NULL, layout = NULL); chartSeries(GS, TA=NULL, layout = NULL)` – Tonio Liebrand Feb 13 '17 at 22:19