From c37f914c68f1cd52874d2b17d6d88350959a32db Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Fri, 5 Jun 2015 14:29:35 -0400 Subject: [PATCH] PERF: Use tolerant_equals instead of np.allclose in order types. np.allclose creates a vector of size 1 if passed a scalar, which showed up as a bottleneck in algorithms with a large number of order_target_percent calls. --- zipline/algorithm.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zipline/algorithm.py b/zipline/algorithm.py index 68e4573c..27b5678b 100644 --- a/zipline/algorithm.py +++ b/zipline/algorithm.py @@ -76,6 +76,7 @@ from zipline.utils.events import ( TimeRuleFactory, ) from zipline.utils.factory import create_simulation_parameters +from zipline.utils.math_utils import tolerant_equals import zipline.protocol from zipline.protocol import Event @@ -728,7 +729,7 @@ class TradingAlgorithm(object): StopLimit order: order(sid, value, limit_price, stop_price) """ last_price = self.trading_client.current_data[sid].price - if np.allclose(last_price, 0): + if tolerant_equals(last_price, 0): zero_message = "Price of 0 for {psid}; can't infer value".format( psid=sid ) @@ -901,7 +902,7 @@ class TradingAlgorithm(object): current value. """ last_price = self.trading_client.current_data[sid].price - if np.allclose(last_price, 0): + if tolerant_equals(last_price, 0): # Don't place an order if self.logger: zero_message = "Price of 0 for {psid}; can't infer value"