pydata/pandas — pull request #8270 by behzadnouri (2014-09-14 20:13:46+00:00)
Title: use z-scores in rolling skew/kurt calculations

adds _some_ stability to rolling `skew` and `kurt` calculation by using the `z-scores` instead of original values; related: https://github.com/pydata/pandas/issues/6929

on master:

In [3]: np.random.seed(2718281)
In [4]: xs = np.random.rand(10)

In [5]: pd.stats.moments.rolling_skew(xs, 4) - pd.stats.moments.rolling_skew(xs + 5000, 4)
Out[5]:
array([ nan, nan, nan,
-1.64816426e-03, 1.10392004e-03, 1.09544324e-03,
7.99253200e-03, 8.66733795e-05, -4.48450842e-03,
-6.03475754e-03])

In [6]: pd.stats.moments.rolling_kurt(xs, 4) - pd.stats.moments.rolling_kurt(xs + 100, 4)
Out[6]:
array([ nan, nan, nan,
-1.39880824e-04, -2.91491317e-04, -2.35463343e-04,
-7.36046530e-04, -3.99141811e-04, -8.61177376e-05,
9.26058376e-06])

on branch:

In [9]: pd.stats.moments.rolling_skew(xs, 4) - pd.stats.moments.rolling_skew(xs + 5000, 4)
Out[9]:
array([ nan, nan, nan,
-1.03506093e-12, 7.35966843e-13, 2.42628140e-12,
-2.43866038e-12, -1.86006766e-12, -1.06070708e-12,
1.66766601e-12])

In [10]: pd.stats.moments.rolling_kurt(xs, 4) - pd.stats.moments.rolling_kurt(xs + 100, 4)
Out[10]:
array([ nan, nan, nan,
-1.24344979e-13, -9.41469125e-14, 7.10542736e-14,
-1.03028697e-13, -5.68434189e-14, -1.13686838e-13,
-5.86197757e-14])

This does _not_ handle all situations that causes instability I believe it is generally more stable to work with z-scores; In particular, affine transformations generate same results.

Also, `input` is a python 3 built-in. I suggest renaming all instances of `input` in `algo.pyx` file to `inp` or something else.