mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-30 04:34:21 +08:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user