Closed
Description
The numerical stability of the current implementation of rolling_kurt
and rolling_skew
is very poor:
In [14]: x = np.random.rand(10)
In [15]: pd.Series(x).rolling(4).skew()
Out[15]:
0 NaN
1 NaN
2 NaN
3 -0.971467
4 0.596391
5 -1.163135
6 -0.611469
7 -1.624713
8 -0.021832
9 0.754653
dtype: float64
In [16]: pd.Series(x + 5000).rolling(4).skew()
Out[16]:
0 NaN
1 NaN
2 NaN
3 -0.968964
4 0.608522
5 -1.171751
6 -0.619354
7 -1.628942
8 -0.033949
9 0.741304
dtype: float64
In [17]: pd.Series(x).rolling(4).kurt()
Out[17]:
0 NaN
1 NaN
2 NaN
3 2.030185
4 -2.647975
5 1.183004
6 -2.178587
7 2.658058
8 -4.258505
9 0.939264
dtype: float64
In [18]: pd.Series(x + 100).rolling(4).kurt()
Out[18]:
0 NaN
1 NaN
2 NaN
3 2.030230
4 -2.648801
5 1.182382
6 -2.178574
7 2.657934
8 -4.258813
9 0.938661
dtype: float64
This can be solved using an updating algorithm, similar to what is done in #6817 for rolling_var
.