From 5dab18613bba1e613c246194af9100f67d2d7ee0 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Thu, 20 Feb 2014 17:33:30 -0500 Subject: [PATCH] BUG: Prevent crash in vwap transform due to non-existent member. The WrongDataForTransform was referencing a `self.fields` member, which did not exist. Add a self.fields member set to `price` and `volume` and use it to iterate over during the check. --- zipline/transforms/vwap.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/zipline/transforms/vwap.py b/zipline/transforms/vwap.py index 48c0b3ba..ffc097af 100644 --- a/zipline/transforms/vwap.py +++ b/zipline/transforms/vwap.py @@ -73,6 +73,7 @@ class VWAPEventWindow(EventWindow): """ def __init__(self, market_aware=True, window_length=None, delta=None): EventWindow.__init__(self, market_aware, window_length, delta) + self.fields = ('price', 'volume') self.flux = 0.0 self.totalvolume = 0.0 @@ -100,7 +101,8 @@ class VWAPEventWindow(EventWindow): # We need numerical price and volume to calculate a vwap. def assert_required_fields(self, event): - if 'price' not in event or 'volume' not in event: - raise WrongDataForTransform( - transform="VWAPEventWindow", - fields=self.fields) + for field in self.fields: + if field not in event: + raise WrongDataForTransform( + transform="VWAPEventWindow", + fields=self.fields)