title: Computing Rolling autocorrelation using Pandas.rolling
body: <p>I am attempting calculate the rolling auto-correlation for a Series object using Pandas (0.23.3)</p>
  
  <p>Setting up the example:</p>
  
  <pre><code>dt_index = pd.date_range('2018-01-01','2018-02-01', freq = 'B')
  data = np.random.rand(len(dt_index))
  s = pd.Series(data, index = dt_index)
  </code></pre>
  
  <p>Creating a Rolling object with window size = 5:</p>
  
  <pre><code>r = s.rolling(5)
  </code></pre>
  
  <p>Getting:</p>
  
  <pre><code>Rolling [window=5,center=False,axis=0]
  </code></pre>
  
  <p>Now when I try to calculate the correlation (Pretty sure this is the wrong approach):</p>
  
  <pre><code>r.corr(other=r)
  </code></pre>
  
  <p>I get only NaNs</p>
  
  <p>I tried another approach based on the <a href="https://pandas.pydata.org/pandas-docs/stable/computation.html#computing-rolling-pairwise-covariances-and-correlations" rel="noreferrer">documentation:</a>:</p>
  
  <pre><code>df = pd.DataFrame()
  df['a'] = s
  df['b'] = s.shift(-1)
  df.rolling(window=5).corr()
  </code></pre>
  
  <p>Getting something like:</p>
  
  <pre><code>...
  2018-03-01 a NaN NaN
             b NaN NaN
  </code></pre>
  
  <p>Really not sure where I'm going wrong with this. Any help would be immensely appreciated! The docs use float64 as well. Thinking it's because the correlation is very close to zero and so it's showing NaN? Somebody had raised a bug report <a href="https://github.com/pandas-dev/pandas/issues/18430" rel="noreferrer">here</a>, but jreback solved the problem in a previous bug fix I think.</p>
  
  <p>This is another relevant answer, but it's using <a href="https://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.rolling_apply.html" rel="noreferrer">pd.rolling_apply</a>, which does not seem to be supported in Pandas version 0.23.3?</p>