From 3a1ca1ddb2db6231cd3744c290ef7003e651140a Mon Sep 17 00:00:00 2001 From: fawce Date: Wed, 16 Oct 2013 14:16:33 -0400 Subject: [PATCH] BUG: Mask of batch_transform columns to match keys in data parameter. The underlying RollingPanel in batch_transform was always accumulating all values to ever appear in data. However, at any given algo time the desired return value is what the current active sids are. Instead, mask down to the sids that are passed in as the data parameter. --- zipline/transforms/batch_transform.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/zipline/transforms/batch_transform.py b/zipline/transforms/batch_transform.py index 96a7baeb..be62a53a 100644 --- a/zipline/transforms/batch_transform.py +++ b/zipline/transforms/batch_transform.py @@ -69,7 +69,8 @@ def downsample_panel(minute_rp, daily_rp, dt): dframe = frame.groupby(lambda d: d.date()).resample('1d', how=func) for stock in sids: day_frame[stock][item] = dframe[stock][dframe.index[-1][0]] - daily_rp.add_frame(dt, day_frame) + # store the frame at midnight instead of the close + daily_rp.add_frame(trading.environment.normalize_date(dt), day_frame) class BatchTransform(object): @@ -263,6 +264,14 @@ class BatchTransform(object): else: sids = self.static_sids + # the panel sent to the transform code will have + # columns masked with this set of sids. This is how + # we guarantee that all (and only) the sids sent to the + # algorithm's handle_data and passed to the batch + # transform. See the get_data method to see it applied. + # N.B. that the underlying panel grows monotonically + # if the set of sids changes over time. + self.latest_sids = sids # Create rolling panel if not existant if self.rolling_panel is None: self._init_panels(sids) @@ -359,6 +368,8 @@ class BatchTransform(object): supplemental_for_dt.combine_first( data[item].ix[dt]) + # screen out sids no longer in the multiverse + data = data.ix[:, :, self.latest_sids] if self.clean_nans: # Fills in gaps of missing data during transform # of multiple stocks. E.g. we may be missing