Stephen, On Mon, Dec 20, 2010 at 8:42 PM, Stephen Choularton <step...@organicfoodmarkets.com.au> wrote: > Hi > > I am having a bit of a problem with ROC. I am doing some quick backtesting > and at one point I use this: > > ret <- ROC(price) > ret[1] <- 0 > > having established the spread between two stocks earlier like this: > > price <- spread$Close - spread$Close.1 > > when I have been working before this has always been positive as the first > share has always been greater in value than the second. But just now I have > done this with two stocks which are approximately the same value and whose > values have crossed each other and I get a lot of NAN's > <snip> > > As you can see when the spread goes negative ROC returns 0. > > Is there some way of getting it to produce the right result? > You're trying to take the log of a negative number. What would you consider to be the right result?
I suspect you want: ROC(price, type="discrete") Documentation and the source are available. Please use them to investigate "odd" behavior. -- Joshua Ulrich | FOSS Trading: www.fosstrading.com > It should work out if there is as later on I go to do this: > > # Calculate equity curves > eq_up <- cumprod(1+ret*sigup) > eq_dn <- cumprod(1+ret*sigdn*-1) > eq_all <- cumprod(1+ret*sig) > > so that should work appropriately on negative and positive returns > (shouldn't it) > > > -- > > > Stephen Choularton Ph.D., FIoD > > _______________________________________________ > R-SIG-Finance@r-project.org 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. > _______________________________________________ R-SIG-Finance@r-project.org 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.