ENH: Use Kahan summation and Welfords method to calculate rolling var and std
State: closed

- [x] xref #37051
- [x] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

As suggested by @mroeschke Kahan summation fixes the numerical problems. Additionally I used Welfords Method to calculate ``ssqdm``, because previously the tests I have added would return

```
0             NaN
1    3.500000e+34
2    3.000000e+34
3    3.000000e+34
4    3.000000e+34
5    3.000000e+34
6    3.000000e+34
7    3.000000e+34
8    3.000000e+34
9    3.000000e+34
dtype: float64
```

for ``var()``. I am running the asv and will post the results when available

Labels:
name: Performance
description: Memory or execution speed performance
name: Window
description: rolling, ewma, expanding

Comments:
great thanks @phofl 
Hello @phofl! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:



There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2020-10-12 19:04:44 UTC
Unfortunately I chose a bad example, which did miss one bug. Fixed it now and added the corresponding test.
xref https://github.com/pandas-dev/pandas/pull/6817

i guess this was there a long time ago, but i dont' think had enough tests to lock it down.
and maybe some examples from here: https://github.com/pandas-dev/pandas/issues/6929 (though that's obviously a separate issue)
Yes planned to Look into this in the future. Maybe we can improve this in a similar way. 

Delta**2 was the problem with the modified version. Switching to regular welford fixes this 
Looks like this will only help with large numbers.
Interestingly 

BENCHMARKS NOT SIGNIFICANTLY CHANGED.

can you merge master, ping on green
@jreback green
@phofl this PR doesn't the close issue? can u show an example of when 
Yeah thought so too initially, because I was not able to construct a counter example. But our docstrings do the job:
If we remove the line:
```
s = pd.Series([5, 5, 6, 7, 5, 5, 5])
print(s.rolling(3).var())
```

Returns

```
0             NaN
1             NaN
2    3.333333e-01
3    1.000000e+00
4    1.000000e+00
5    1.333333e+00
6    6.661338e-16
dtype: float64
```

Seems like Kahan summation and Welfords method only help for large numbers. Issues with numbers like ``1/3`` like here can't be fixed with that. Rounding issues after multiplication cause there problems.
> Yeah thought so too initially, because I was not able to construct a counter example. But our docstrings do the job:
> If we remove the line:
> 
> ```
> s = pd.Series([5, 5, 6, 7, 5, 5, 5])
> print(s.rolling(3).var())
> ```
> 
> Returns
> 
> ```
> 0             NaN
> 1             NaN
> 2    3.333333e-01
> 3    1.000000e+00
> 4    1.000000e+00
> 5    1.333333e+00
> 6    6.661338e-16
> dtype: float64
> ```
> 
> Seems like Kahan summation and Welfords method only help for large numbers. Issues with numbers like `1/3` like here can't be fixed with that. Rounding issues after multiplication cause there problems.

ok its prob worth adding an xfail test for that one. (followon ok)
thanks @phofl 
@jreback with the line < 1e-14 this test would not fail. I could add a test which passes, but would fail, if somebody removes the line without fixing the underlying problem?