diff --git a/zipline/utils/math_utils.py b/zipline/utils/math_utils.py index 647ac0b6..43e4d380 100644 --- a/zipline/utils/math_utils.py +++ b/zipline/utils/math_utils.py @@ -14,7 +14,22 @@ # limitations under the License. import math +import numpy as np def tolerant_equals(a, b, atol=10e-7, rtol=10e-7): return math.fabs(a - b) <= (atol + rtol * math.fabs(b)) + + +nanmean = np.nanmean +nanstd = np.nanstd +nansum = np.nansum + + +try: + import bottleneck as bn + nanmean = bn.nanmean + nanstd = bn.nanstd + nansum = bn.nansum +except ImportError: + pass