[R-SIG-Finance] question about subsetting xts, calculating returns

Andreas Voellenklee wotuzu17 at gmail.com
Thu Apr 12 18:36:43 CEST 2012


Hello,

I would like to monitor short-term-returns on simple strategies like
donchian channel price outbreaks. That is, I would like to see the
returns at 1:10 periods after the breakout-event occurs.

For example:
getSymbols("NOK", adjust=TRUE)

# calculate donchian channel for NOK
DC <- DonchianChannel(lag(cbind(Hi(NOK),Lo(NOK))))

# mark days when price closes below the low band of DC
breakdown <- eval(Cl(NOK)<DC[,"low"])
colnames(breakdown) <- c("breakdown")

# how often did that condition occur?
colSums(breakdown, na.rm=TRUE)
#breakdown
#      135


Now I masked out all days when the price closed below the donchian channel.

- Is there a easy way to display only the (135) rows where
breakdown[,1] is TRUE?
- How to calculate the 1:10 days- returns after the breakdown-events then?

I would be grateful for some hints,

Andreas



More information about the R-SIG-Finance mailing list