Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Adds last_available_{session, minute} args to DataPortal #1528

Merged
merged 2 commits into from Oct 7, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion zipline/data/data_portal.py
Expand Up @@ -104,6 +104,10 @@ class DataPortal(object):
adjustment_reader : SQLiteAdjustmentWriter, optional
The adjustment reader. This is used to apply splits, dividends, and
other adjustment data to the raw data from the readers.
last_available_session : pd.Timestamp, optional
The last session to make available in session-level data.
last_available_minute : pd.Timestamp, optional
The last minute to make available in minute-level data.
"""
def __init__(self,
asset_finder,
Expand All @@ -113,7 +117,9 @@ def __init__(self,
equity_minute_reader=None,
future_daily_reader=None,
future_minute_reader=None,
adjustment_reader=None):
adjustment_reader=None,
last_available_session=None,
last_available_minute=None):

self.trading_calendar = trading_calendar
self.asset_finder = asset_finder
Expand Down Expand Up @@ -169,12 +175,14 @@ def __init__(self,
self.trading_calendar,
self.asset_finder,
aligned_minute_readers,
last_available_minute,
)

_dispatch_session_reader = AssetDispatchSessionBarReader(
self.trading_calendar,
self.asset_finder,
aligned_session_readers,
last_available_session,
)

self._pricing_readers = {
Expand Down
17 changes: 15 additions & 2 deletions zipline/data/dispatch_bar_reader.py
Expand Up @@ -35,11 +35,21 @@ class AssetDispatchBarReader(with_metaclass(ABCMeta)):
- readers : dict
A dict mapping Asset type to the corresponding
[Minute|Session]BarReader
- last_available_dt : pd.Timestamp or None, optional
If not provided, infers it by using the min of the
last_available_dt values of the underlying readers.
"""
def __init__(self, trading_calendar, asset_finder, readers):
def __init__(
self,
trading_calendar,
asset_finder,
readers,
last_available_dt=None,
):
self._trading_calendar = trading_calendar
self._asset_finder = asset_finder
self._readers = readers
self._last_available_dt = last_available_dt

for t, r in iteritems(self._readers):
assert trading_calendar == r.trading_calendar, \
Expand Down Expand Up @@ -72,7 +82,10 @@ def trading_calendar(self):

@lazyval
def last_available_dt(self):
return min(r.last_available_dt for r in self._readers.values())
if self._last_available_dt is not None:
return self._last_available_dt
else:
return min(r.last_available_dt for r in self._readers.values())

@lazyval
def first_trading_day(self):
Expand Down