title: Rolling calculation across a column - array-wise
body: <p>I'm trying to get a rolling n-day annualized equity return volatility but am having trouble implementing it. Basically, I would want to see in the last row (index 10) an implementation of sorts that does <code>np.std(df[&quot;log returns“]*np.sqrt(252)</code> for a rolling n-day window (e.g. index 6-10 for a 5-day window). If there aren't n values left, leave empty/fill with np.nan.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Index</th>
  <th>log returns</th>
  <th>annualized volatility</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>0</td>
  <td>0.01</td>
  <td></td>
  </tr>
  <tr>
  <td>1</td>
  <td>-0.005</td>
  <td></td>
  </tr>
  <tr>
  <td>2</td>
  <td>0.021</td>
  <td></td>
  </tr>
  <tr>
  <td>3</td>
  <td>0.01</td>
  <td></td>
  </tr>
  <tr>
  <td>4</td>
  <td>-0.01</td>
  <td></td>
  </tr>
  <tr>
  <td>5</td>
  <td>0.02</td>
  <td></td>
  </tr>
  <tr>
  <td>6</td>
  <td>0.012</td>
  <td></td>
  </tr>
  <tr>
  <td>7</td>
  <td>0.022</td>
  <td></td>
  </tr>
  <tr>
  <td>8</td>
  <td>-0.001</td>
  <td></td>
  </tr>
  <tr>
  <td>9</td>
  <td>-0.01</td>
  <td></td>
  </tr>
  <tr>
  <td>10</td>
  <td>0.01</td>
  <td></td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I thought about doing this with a while loop, but since I'm working with a lot of data I thought an array-wise operation may be smarter. Unfortunately I can't come up with one for the life of me.</p>