> Trying to get quantmod and the forecast package working together but having
> some trouble with just the simple stuff. Any ideas on why this code doesn't
> work ?
> getSymbols('^GSPC', from='1950-01-06', to=Sys.Date())
> train.model<-rwf(train, drift=TRUE,h=1)
> Seems to work all the way through the acc.train statement but then gets
> hung up at acc.test. I get the following error:
> Error in `[.xts`((c(xx[2:n])/c(xx[1:(n - 1)]) - 1), test - 1) :
> subscript out of bounds
From the documentation for ?accuracy :
test: Indicator of which elements of x and f to test. If
‘test=="all"’, all elements are used. Otherwise test is a
numeric vector containing the indices of the elements to use
in the test.
your 'test' is an xts object, the entire time series, not a numeric
vector of indices.
Also, since your dates don't line up, this can never work.
rwf makes a number of forecasts specified by 'h'. You only make one,
for Feb 2009.
Try summary(train.model), and try some more documentation reading and
examples. From here, it looks like everything is fine so far.