title: xts::period.apply and cumprod
body: <p>I am trying to calculate cumulative product for subsets of xts object. Here is an example of what I want and a question whether this can be done faster/more elegant using period.apply or some other c++ based fast function?</p>
  
  <pre><code># install.packages("qmao", repos="http://R-Forge.R-project.org")
  require(qmao) # for do.call.rbind()
  
  # I need something like cumprod over xts but by endpoints (subsets of xts)
  test &lt;- xts(rep(0.01, length(as.Date(13514:13523, origin="1970-01-01"))), as.Date(13514:13523, origin="1970-01-01"))
  ep &lt;- c(0, 5, NROW(test))
  # This does not do the trick
  period.prod(test, INDEX=ep)
  # So, try the obvious, but it does not do the trick
  period.apply(test, INDEX=ep, FUN=function(x) cumprod(1 + x))
  
  # Well, write your own
  # Hm, there is no split.xts that takes ep (endpoints) as parameter...
  # OK, split it manually
  test.list &lt;- list(length(ep) - 1)
  k &lt;- 1:(length(ep) - 1)
  test.list &lt;- lapply(k, function(x) test[(ep[x] + 1):ep[x + 1], ])
  # This is what I want...
  do.call.rbind(lapply(test.list, function(x) cumprod(1 + x)))
  # Is there a better/faster way to do this?
  </code></pre>