BUG: Fixes error due to floating point rounding in stddev calc.

Adds a check to see if the s_squared value is near 0.

When the number was very near 0, a very small negative floating
point, the sqrt throws a 'math domain error', this prevents that
case.
This commit is contained in:
Eddie Hebert
2013-02-28 22:19:31 -05:00
parent 46104fcd7c
commit 414e12ecc9
+5
View File
@@ -17,6 +17,8 @@ from numbers import Number
from collections import defaultdict
from math import sqrt
import numpy as np
from zipline.transforms.utils import EventWindow, TransformMeta
@@ -109,5 +111,8 @@ class MovingStandardDevWindow(EventWindow):
average = self.sum / len(self)
s_squared = (self.sum_sqr - self.sum * average) \
/ (len(self) - 1)
if np.allclose(0, s_squared):
return 0.0
stddev = sqrt(s_squared)
return stddev