title: R: Calculate Quartely Returns from Monthly Returns
body: <p>I have dataframe (return.monthly) of the form </p>
  
  <pre><code>Date         Return
  2001-09-1    0.0404775
  2001-10-1   -0.01771575
  2001-11-1   -0.03304925
  etc.
  </code></pre>
  
  <p>i.e. monthly returns over a period of time (2 years). I would like to calculate quarterly returns, i.e just take 3 observations and calculate the sum.</p>
  
  <p>I tried</p>
  
  <pre><code>return.quarterly &lt;- xts(return.monthly[, -1], return.monthly[,1])
  function &lt;- function(x) sum(x)
  time &lt;- 3
  return.quarterly$return_q &lt;- rollapply(return.quarterly$Return, FUN=function, 
  width=time, align="left", na.pad=T)
  </code></pre>
  
  <p>Obviously this formula calculates returns over a rolling window, i.e. it takes observation 1-3 and calculates the sum, then 2-4 and calculates the sum, etc. What I want is however 1-3, 4-6, 7-9...</p>
  
  <p>How could I do that?</p>
  
  <p>Thanks in advance, Dani</p>