From cbd4ea36bca615f41e733df3518767fb24b6b9fc Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Fri, 13 May 2016 14:31:33 -0400 Subject: [PATCH 1/4] STY: No need for these to be vertical. --- tests/pipeline/test_technical.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/tests/pipeline/test_technical.py b/tests/pipeline/test_technical.py index c2b1dfc6..335b90c9 100644 --- a/tests/pipeline/test_technical.py +++ b/tests/pipeline/test_technical.py @@ -128,15 +128,6 @@ class BollingerBandsTestCase(WithTechnicalFactor, ZiplineTestCase): closes, ) - assert_equal( - result.upper, - expected_upper, - ) - assert_equal( - result.middle, - expected_middle, - ) - assert_equal( - result.lower, - expected_lower, - ) + assert_equal(result.upper, expected_upper) + assert_equal(result.middle, expected_middle) + assert_equal(result.lower, expected_lower) From 2f906656763c4057153832ee6783121d66cf7955 Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Fri, 13 May 2016 14:31:58 -0400 Subject: [PATCH 2/4] TEST: Add a test for bbands output ordering. --- tests/pipeline/test_technical.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/pipeline/test_technical.py b/tests/pipeline/test_technical.py index 335b90c9..17b7f015 100644 --- a/tests/pipeline/test_technical.py +++ b/tests/pipeline/test_technical.py @@ -131,3 +131,10 @@ class BollingerBandsTestCase(WithTechnicalFactor, ZiplineTestCase): assert_equal(result.upper, expected_upper) assert_equal(result.middle, expected_middle) assert_equal(result.lower, expected_lower) + + def test_bollinger_bands_output_ordering(self): + bbands = BollingerBands(window_length=5, k=2) + lower, middle, upper = bbands + self.assertIs(lower, bbands.lower) + self.assertIs(middle, bbands.middle) + self.assertIs(upper, bbands.upper) From c4b69d6223bd6257b932cab7f90a4fa8abb66273 Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Fri, 13 May 2016 14:32:21 -0400 Subject: [PATCH 3/4] TEST: Don't mask unexpected exceptions from TALIB. We know when we expect the error to be raised. --- tests/pipeline/test_technical.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/pipeline/test_technical.py b/tests/pipeline/test_technical.py index 17b7f015..597aa84c 100644 --- a/tests/pipeline/test_technical.py +++ b/tests/pipeline/test_technical.py @@ -72,17 +72,17 @@ class BollingerBandsTestCase(WithTechnicalFactor, ZiplineTestCase): middle_cols = [] upper_cols = [] for n in range(self.nassets): - try: + close_col = closes[:, n] + if np.isnan(close_col).all(): + # ta-lib doesn't deal well with all nans. + upper, middle, lower = [np.full(self.ndays, np.nan)] * 3 + else: upper, middle, lower = talib.BBANDS( closes[:, n], window_length, k, k, ) - except Exception: - # If the input array is all nan then talib raises an instance - # of Exception. - upper, middle, lower = [np.full(self.ndays, np.nan)] * 3 upper_cols.append(upper) middle_cols.append(middle) From f4d96e065a841e7a7a68fb6f1ccbc6ae0a027999 Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Fri, 13 May 2016 14:44:26 -0400 Subject: [PATCH 4/4] TEST/PERF: Don't slice twice. --- tests/pipeline/test_technical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pipeline/test_technical.py b/tests/pipeline/test_technical.py index 597aa84c..313337e4 100644 --- a/tests/pipeline/test_technical.py +++ b/tests/pipeline/test_technical.py @@ -78,7 +78,7 @@ class BollingerBandsTestCase(WithTechnicalFactor, ZiplineTestCase): upper, middle, lower = [np.full(self.ndays, np.nan)] * 3 else: upper, middle, lower = talib.BBANDS( - closes[:, n], + close_col, window_length, k, k,