title: Rolling variance algorithm
body: <p>I'm trying to find an efficient, numerically stable algorithm to calculate a rolling variance (for instance, a variance over a 20-period rolling window). I'm aware of the <a href="http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm" rel="noreferrer">Welford algorithm</a> that efficiently computes the running variance for a stream of numbers (it requires only one pass), but am not sure if this can be adapted for a rolling window. I would also like the solution to avoid the accuracy problems discussed at the top of <a href="http://www.johndcook.com/standard_deviation.html" rel="noreferrer">this article</a> by John D. Cook. A solution in any language is fine.</p>