title: apply functions for xts
body: <p>My data is currently an xts or zoo object of daily stock prices per row and each column is a different company.</p>
  
  <pre><code>library(quantmod)
  getSymbols("AAPL;MSFT;YHOO")
  closePrices &lt;- merge(Cl(AAPL),Cl(MSFT),Cl(YHOO))
  </code></pre>
  
  <p>I am still new to R and need some assistance reproducing this <a href="http://i.imgur.com/KMjix.png" rel="nofollow">Excel function</a>.  My first thought was to split the function into numerator and denominator, and then compute the index:</p>
  
  <pre><code>dailyDiff &lt;- abs(diff(closePrices,1))
  numerJ &lt;- diff(closePrices,10)
  denomJ &lt;- as.xts(rollapply(dailyDiff,11, sum))
  idx &lt;- abs(numerJ/denomJ)
  </code></pre>
  
  <p>This was great because the values for each portion were accurate, but are aligned by incorrect dates for denomJ. For example, the tail of numerJ goes to 6/21/2012, while the tail of denomJ goes to 6/14/2012.  </p>
  
  <p>The output that I am looking for is:</p>
  
  <ul>
  <li>6/21/2012 = .11</li>
  <li>6/20/2012 = .27</li>
  <li>6/19/2012 = .46</li>
  <li>6/18/2012 = .39</li>
  <li>6/15/2012 = .22</li>
  </ul>