[R-SIG-Finance] ttrTests error
josh.m.ulrich at gmail.com
Fri Jul 9 03:23:34 CEST 2010
A few points of clarification:
On Thu, Jul 8, 2010 at 8:04 PM, Sarbo <cmdr_rogue at hotmail.com> wrote:
> Just type the name of the function into the command line (no parentheses
> or arguments- just type "getYahooData" or "cReturns").
> It looks like your ttr definition is causing the problem- there's no
> "sma" function there unless you've loaded it from another library. Try
> something like this instead:
> library(TTR); library(ttrTests); library(quantmod)
> spData <- as.vector(getYahooData('SPY', start = 19900101, end =
> cr <- cReturns(spData, ttr = 'macd4')
> Note that if you use the functions in the "MovingAverages" function set
> in quantmod, those functions will try to convert a vector series into an
> xts object. Since your vector series has no names for the indices, it's
> a bit of a problem because the conversion results in an error.
The MA functions are actually defined in TTR (not quantmod) and they
*internally* try to convert a vector series to xts, BUT there is no
error if the vector does not have names. In that case, TTR functions
*internally* convert to a matrix. I stress *internally* because TTR
functions will return the same class of object given to them.
num [1:20] NA NA NA NA NA NA NA NA NA 5.5 ...
An ‘xts’ object from 1969-12-31 18:00:01 to 1969-12-31 18:00:20 containing:
Data: num [1:20, 1] NA NA NA NA NA NA NA NA NA 5.5 ...
Indexed by objects of class: [POSIXt,POSIXct] TZ:
‘zoo’ series from 1969-12-31 18:00:01 to 1969-12-31 18:00:20
Data: Named num [1:20] NA NA NA NA NA NA NA NA NA 5.5 ...
- attr(*, "names")= chr [1:20] "1969-12-31 18:00:01" "1969-12-31
18:00:02" "1969-12-31 18:00:03" "1969-12-31 18:00:04" ...
Index: POSIXct[1:20], format: "1969-12-31 18:00:01" "1969-12-31 18:00:02" ...
Time-Series [1:20] from 1 to 20: NA NA NA NA NA NA NA NA NA 5.5 ...
FOSS Trading: www.fosstrading.com
> On Thu, 2010-07-08 at 22:41 +0100, Raghu wrote:
>> spData <-
>> > cr <- cReturns(spData, ttr = "sma", params=c(20))
>> Error in ind[t - k] <- pos[t - k + 1] - pos[t - k] :
>> replacement has length zero
>> I am getting the above error when running the cReturns function. Any ideas
>> on this? How does one drill down into finction codes in R?
>> [[alternative HTML version deleted]]
>> R-SIG-Finance at stat.math.ethz.ch mailing list
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions should go.
> [[alternative HTML version deleted]]
> R-SIG-Finance at stat.math.ethz.ch mailing list
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
More information about the R-SIG-Finance