title: How to calculate the historical monthly volatility from daily returns in R?
body: <p>First I created an xts object, which contains 36 time series showing daily prices from 1980-01-02 to 2020-10-06.</p>
  <pre><code>ENERGY_data$time &lt;- as.Date(ENERGY_data$time, format(&quot;%Y/%m/%d&quot;))
  ENERGY_xts &lt;- ENERGY_data[order(ENERGY_data$time), ]
  ENERGY_xts &lt;- as.xts(ENERGY_xts[, 2:37], order.by=ENERGY_xts$time)
  </code></pre>
  <p>Then I calculated the continuously compounded daily returns by using the PerformanceAnalytics function CalculateReturns()</p>
  <pre><code>ENERGY_returns.cc &lt;- CalculateReturns(ENERGY_xts, method=&quot;compound&quot;)
  </code></pre>
  <p>Now I would like to calculate the volatility for each month going from 1980-01-02 to 2020-10-06 on the basis of this formula:
  <a href="https://i.stack.imgur.com/Ieh8l.png" rel="nofollow noreferrer">MONTHLY VOLATILITY FORMULA</a></p>
  <p>Could you please give me some hints (in terms of coding)?</p>