ttrTests error
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 =
? ? ? ?20081231)[,'Close'])
? ? ? ?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. For example:
str(SMA(1:20,10))
num [1:20] NA NA NA NA NA NA NA NA NA 5.5 ...
str(SMA(.xts(1:20,1:20),10))
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: xts Attributes: NULL
str(SMA(as.zoo(.xts(1:20,1:20)),10))
?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" ...
str(SMA(as.ts(.xts(1:20,1:20)),10))
Time-Series [1:20] from 1 to 20: NA NA NA NA NA NA NA NA NA 5.5 ... Best, -- Joshua Ulrich FOSS Trading: www.fosstrading.com
On Thu, 2010-07-08 at 22:41 +0100, Raghu wrote:
spData <-
as.vector(getYahooData("SPY",start="19900101",end="20081231")[,"Close"])
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? Tx Raghu ? ? ? [[alternative HTML version deleted]]
_______________________________________________ R-SIG-Finance at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- 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 https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- 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.