mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-13 17:42:42 +08:00
MAINT: Removes the set_first_trading_day method of DataPortal
Since the first trading day is now passed directly to the DataPortal on init, there's no need for a method that does this. Moves all the additional logic/assignments into the init. Also corrects an issue where we would never create certain attributes if self._first_trading_day was None. Adds the ability to specify the first trading day for a data portal in a test case when using the WithDataPortal fixture.
This commit is contained in:
committed by
Jean Bredeche
parent
92600d7695
commit
02a91ec4ab
@@ -27,7 +27,8 @@ from zipline.testing import (
|
||||
from zipline.testing.fixtures import (
|
||||
WithBcolzMinuteBarReader,
|
||||
WithDataPortal,
|
||||
ZiplineTestCase
|
||||
ZiplineTestCase,
|
||||
alias,
|
||||
)
|
||||
|
||||
|
||||
@@ -447,6 +448,7 @@ MINUTE_FIELD_INFO = {
|
||||
class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
|
||||
BCOLZ_DAILY_BAR_SOURCE_FROM_MINUTE = True
|
||||
DATA_PORTAL_FIRST_TRADING_DAY = alias('TRADING_START_DT')
|
||||
|
||||
@classmethod
|
||||
def make_minute_bar_data(cls):
|
||||
@@ -1135,7 +1137,6 @@ class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
def test_history_window_before_first_trading_day(self):
|
||||
# trading_start is 2/3/2014
|
||||
# get a history window that starts before that, and ends after that
|
||||
self.data_portal.set_first_trading_day(self.TRADING_START_DT)
|
||||
first_day_minutes = self.trading_schedule.execution_minutes_for_day(
|
||||
self.TRADING_START_DT
|
||||
)
|
||||
@@ -1643,8 +1644,6 @@ class DailyEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
def test_history_window_before_first_trading_day(self):
|
||||
# trading_start is 2/3/2014
|
||||
# get a history window that starts before that, and ends after that
|
||||
|
||||
self.data_portal.set_first_trading_day(self.TRADING_START_DT)
|
||||
second_day = self.trading_schedule.next_execution_day(
|
||||
self.TRADING_START_DT
|
||||
)
|
||||
|
||||
+17
-15
@@ -556,25 +556,27 @@ class DataPortal(object):
|
||||
self.MINUTE_PRICE_ADJUSTMENT_FACTOR = \
|
||||
self._equity_minute_reader._ohlc_inverse
|
||||
|
||||
self.set_first_trading_day(first_trading_day)
|
||||
|
||||
def set_first_trading_day(self, first_trading_day):
|
||||
self._first_trading_day = first_trading_day
|
||||
|
||||
# Get the first trading minute
|
||||
if self._first_trading_day is not None:
|
||||
self._first_trading_minute, _ = \
|
||||
self.trading_schedule.start_and_end(self._first_trading_day)
|
||||
self._first_trading_minute, _ = (
|
||||
self.trading_schedule.start_and_end(self._first_trading_day)
|
||||
if self._first_trading_day is not None else (None, None)
|
||||
)
|
||||
|
||||
# Store the locs of the first day and first minute
|
||||
self._first_trading_day_loc = \
|
||||
self.trading_schedule.all_execution_days.get_loc(
|
||||
self.trading_schedule.session_date(self._first_trading_day)
|
||||
)
|
||||
self._first_trading_minute_loc = \
|
||||
self.trading_schedule.all_execution_minutes.get_loc(
|
||||
self._first_trading_minute
|
||||
)
|
||||
# Store the locs of the first day and first minute
|
||||
self._first_trading_day_loc = (
|
||||
self.trading_schedule.all_execution_days.get_loc(
|
||||
self.trading_schedule.session_date(self._first_trading_day)
|
||||
)
|
||||
if self._first_trading_day is not None else None
|
||||
)
|
||||
self._first_trading_minute_loc = (
|
||||
self.trading_schedule.all_execution_minutes.get_loc(
|
||||
self._first_trading_minute
|
||||
)
|
||||
if self._first_trading_minute is not None else None
|
||||
)
|
||||
|
||||
def _reindex_extra_source(self, df, source_date_index):
|
||||
return df.reindex(index=source_date_index, method='ffill')
|
||||
|
||||
@@ -1188,18 +1188,21 @@ class WithDataPortal(WithAdjustmentReader,
|
||||
DATA_PORTAL_USE_MINUTE_DATA = True
|
||||
DATA_PORTAL_USE_ADJUSTMENTS = True
|
||||
|
||||
DATA_PORTAL_FIRST_TRADING_DAY = None
|
||||
|
||||
def make_data_portal(self):
|
||||
if self.DATA_PORTAL_USE_MINUTE_DATA:
|
||||
first_trading_day = self.bcolz_minute_bar_reader.first_trading_day
|
||||
elif self.DATA_PORTAL_USE_DAILY_DATA:
|
||||
first_trading_day = self.bcolz_daily_bar_reader.first_trading_day
|
||||
else:
|
||||
first_trading_day = None
|
||||
if self.DATA_PORTAL_FIRST_TRADING_DAY is None:
|
||||
if self.DATA_PORTAL_USE_MINUTE_DATA:
|
||||
self.DATA_PORTAL_FIRST_TRADING_DAY = (
|
||||
self.bcolz_minute_bar_reader.first_trading_day)
|
||||
elif self.DATA_PORTAL_USE_DAILY_DATA:
|
||||
self.DATA_PORTAL_FIRST_TRADING_DAY = (
|
||||
self.bcolz_daily_bar_reader.first_trading_day)
|
||||
|
||||
return DataPortal(
|
||||
self.env.asset_finder,
|
||||
self.trading_schedule,
|
||||
first_trading_day=first_trading_day,
|
||||
first_trading_day=self.DATA_PORTAL_FIRST_TRADING_DAY,
|
||||
equity_daily_reader=(
|
||||
self.bcolz_daily_bar_reader
|
||||
if self.DATA_PORTAL_USE_DAILY_DATA else
|
||||
|
||||
Reference in New Issue
Block a user