From 7d8768e2e42e284a7f12e2c58a4841f4cbb3420a Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Mon, 17 Oct 2016 15:08:11 -0400 Subject: [PATCH] MAINT: Limit perspective offset. Limit the perspective offset to 1. There is a possibility that if a consumer of the AdjustedArrayWindow does not fetch adjustments between the end of the data window and the vantage points beyond the end of the window. Until that case has a solution, e.g. having the consumer of the AdjustedArrayWindow include the perspective offset when calculating the query for adjustments, limit the offsets to 1. --- tests/pipeline/test_adjusted_array.py | 6 +++--- zipline/lib/_windowtemplate.pxi | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/pipeline/test_adjusted_array.py b/tests/pipeline/test_adjusted_array.py index cc6d05e9..57afb44b 100644 --- a/tests/pipeline/test_adjusted_array.py +++ b/tests/pipeline/test_adjusted_array.py @@ -215,7 +215,7 @@ def _gen_multiplicative_adjustment_cases(dtype): adjustments, buffer_as_of, nrows, - perspective_offsets=(0, 1, 2, 1000), + perspective_offsets=(0, 1), ) @@ -318,7 +318,7 @@ def _gen_overwrite_adjustment_cases(dtype): adjustments, buffer_as_of, nrows=6, - perspective_offsets=(0, 1, 2, 1000), + perspective_offsets=(0, 1), ) @@ -421,7 +421,7 @@ def _gen_overwrite_1d_array_adjustment_case(dtype): adjustments, buffer_as_of, nrows=6, - perspective_offsets=(0, 1, 2, 1000), + perspective_offsets=(0, 1), ) diff --git a/zipline/lib/_windowtemplate.pxi b/zipline/lib/_windowtemplate.pxi index 40f900a5..245df436 100644 --- a/zipline/lib/_windowtemplate.pxi +++ b/zipline/lib/_windowtemplate.pxi @@ -53,6 +53,15 @@ cdef class AdjustedArrayWindow: self.adjustment_indices = sorted(adjustments, reverse=True) self.window_length = window_length self.anchor = window_length + offset + if perspective_offset > 1: + # Limit perspective_offset to 1. + # To support an offset greater than 1, work must be done to + # ensure that adjustments are retrieved for the datetimes between + # the end of the window and the vantage point defined by the + # perspective offset. + raise Exception("perspective_offset should not exceed 1, value " + "is perspective_offset={0}".format( + perspective_offset)) self.perspective_offset = perspective_offset self.next_anchor = self.anchor self.max_anchor = data.shape[0]