mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-15 12:15:22 +08:00
MAINT: Removes the ability to reference a global TradingEnvironment
This commit removes the ability to reference a shared TradingEnvironment through the zipline.finance.trading module. In place, the classes that require a TradingEnvironment, or its child AssetFinder, contain their own references to those objects. This commit also adds serialization utilities that allow for the pickling/unpickling of objects without unintentionally their TradingEnvironments or AssetFinders.
This commit is contained in:
@@ -34,8 +34,12 @@ from six import (
|
||||
|
||||
from zipline.utils.data import MutableIndexRollingPanel
|
||||
from zipline.protocol import Event
|
||||
from zipline.finance.trading import TradingEnvironment
|
||||
|
||||
from zipline.finance import trading
|
||||
# HACK the BatchTransform module stores a trading environment to be used by
|
||||
# the transforms
|
||||
# TODO remove this hack, if not this whole module
|
||||
_batch_transform_env = TradingEnvironment()
|
||||
|
||||
log = logbook.Logger('BatchTransform')
|
||||
func_map = {'open_price': 'first',
|
||||
@@ -67,8 +71,8 @@ def downsample_panel(minute_rp, daily_rp, mkt_close):
|
||||
cur_panel = minute_rp.get_current()
|
||||
sids = minute_rp.minor_axis
|
||||
day_frame = pd.DataFrame(columns=sids, index=cur_panel.items)
|
||||
dt1 = trading.environment.normalize_date(mkt_close)
|
||||
dt2 = trading.environment.next_trading_day(mkt_close)
|
||||
dt1 = _batch_transform_env.normalize_date(mkt_close)
|
||||
dt2 = _batch_transform_env.next_trading_day(mkt_close)
|
||||
by_close = functools.partial(get_date, mkt_close, dt1, dt2)
|
||||
for item in minute_rp.items:
|
||||
frame = cur_panel[item]
|
||||
@@ -333,11 +337,11 @@ class BatchTransform(object):
|
||||
# we may get events from non-trading sources which occurr on
|
||||
# non-trading days. The book-keeping for market close and
|
||||
# trading day counting should only consider trading days.
|
||||
if trading.environment.is_trading_day(event.dt):
|
||||
_, mkt_close = trading.environment.get_open_and_close(event.dt)
|
||||
if _batch_transform_env.is_trading_day(event.dt):
|
||||
_, mkt_close = _batch_transform_env.get_open_and_close(event.dt)
|
||||
if self.bars == 'daily':
|
||||
# Daily bars have their dt set to midnight.
|
||||
mkt_close = trading.environment.normalize_date(mkt_close)
|
||||
mkt_close = _batch_transform_env.normalize_date(mkt_close)
|
||||
if event.dt == mkt_close:
|
||||
if self.downsample:
|
||||
downsample_panel(self.rolling_panel,
|
||||
|
||||
Reference in New Issue
Block a user