Given the definition of standard deviation as:
the square root of the expectation of X-squared minus the expectation of X, squared;
why do the following two calculations of exponentially weighted standard deviation not result in the same values?
import numpy
import pandas
x = pandas.Series(numpy.random.default_rng(0).normal(size=1000))
com = 2
a = x.ewm(com).std()
b = numpy.sqrt((x**2).ewm(com).mean() - (x.ewm(com).mean())**2)
pandas.concat([a,b], axis=1).tail(5)
Output:
a | b | |
---|---|---|
995 | 1.535113 | 1.373047 |
996 | 1.302008 | 1.164551 |
997 | 1.320120 | 1.180751 |
998 | 1.215099 | 1.086818 |
999 | 1.002668 | 0.896814 |