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

G See gsee000 at gmail.com
Thu Apr 12 19:38:38 CEST 2012


Hi Andreas,

Try something like below.  Make sure it's right though, because I
didn't really check my work.

On Thu, Apr 12, 2012 at 11:36 AM, Andreas Voellenklee
<wotuzu17 at gmail.com> wrote:
> - Is there a easy way to display only the (135) rows where
> breakdown[,1] is TRUE?

NOK[breakdown]

> - How to calculate the 1:10 days- returns after the breakdown-events then?

# 10 period return from the current period through 10 periods into the future
lag(ROC(Cl(NOK), 10), -10)[breakdown]

# 1:10 period return from the current period through 1:10 periods into
the future
do.call(cbind, lapply(1:10, function(i) {
    lag(ROC(Cl(NOK), i), -i)[breakdown]
}))


HTH,
Garrett



More information about the R-SIG-Finance mailing list