I am attempting calculate the rolling auto-correlation for a Series object using Pandas (0.23.3)
Setting up the example:
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)
Creating a Rolling object with window size = 5:
r = s.rolling(5)
Getting:
Rolling [window=5,center=False,axis=0]
Now when I try to calculate the correlation (Pretty sure this is the wrong approach):
r.corr(other=r)
I get only NaNs
I tried another approach based on the documentation::
df = pd.DataFrame()
df['a'] = s
df['b'] = s.shift(-1)
df.rolling(window=5).corr()
Getting something like:
...
2018-03-01 a NaN NaN
b NaN NaN
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 here, but jreback solved the problem in a previous bug fix I think.
This is another relevant answer, but it's using pd.rolling_apply, which does not seem to be supported in Pandas version 0.23.3?