ENH: Adds ExchangeCalendar, TradingSchedule, and implementations

Conflicts:
	tests/data/test_minute_bars.py
	tests/data/test_us_equity_pricing.py
	tests/finance/test_slippage.py
	tests/pipeline/test_engine.py
	tests/pipeline/test_us_equity_pricing_loader.py
	tests/serialization_cases.py
	tests/test_algorithm.py
	tests/test_assets.py
	tests/test_bar_data.py
	tests/test_benchmark.py
	tests/test_exception_handling.py
	tests/test_fetcher.py
	tests/test_finance.py
	tests/test_history.py
	tests/test_perf_tracking.py
	tests/test_security_list.py
	tests/utils/test_events.py
	zipline/algorithm.py
	zipline/data/data_portal.py
	zipline/data/us_equity_loader.py
	zipline/errors.py
	zipline/finance/trading.py
	zipline/testing/core.py
	zipline/utils/events.py
This commit is contained in:
jfkirk
2016-06-08 13:34:18 -04:00
committed by Jean Bredeche
parent c9b5979f45
commit c8304e8601
46 changed files with 9709 additions and 1137 deletions
+17 -16
View File
@@ -45,8 +45,7 @@ from zipline.data.minute_bars import (
US_EQUITIES_MINUTES_PER_DAY,
BcolzMinuteWriterColumnMismatch
)
from zipline.finance.trading import TradingEnvironment
from zipline.utils.calendars import get_calendar, default_nyse_schedule
# Calendar is set to cover several half days, to check a case where half
# days would be read out of order in cases of windows which spanned over
@@ -59,15 +58,11 @@ class BcolzMinuteBarTestCase(TestCase):
@classmethod
def setUpClass(cls):
cls.env = TradingEnvironment()
all_market_opens = cls.env.open_and_closes.market_open
all_market_closes = cls.env.open_and_closes.market_close
indexer = all_market_opens.index.slice_indexer(
start=TEST_CALENDAR_START,
end=TEST_CALENDAR_STOP
trading_days = get_calendar('NYSE').trading_days(
TEST_CALENDAR_START, TEST_CALENDAR_STOP
)
cls.market_opens = all_market_opens[indexer]
cls.market_closes = all_market_closes[indexer]
cls.market_opens = trading_days.market_open
cls.market_closes = trading_days.market_close
cls.test_calendar_start = cls.market_opens.index[0]
cls.test_calendar_stop = cls.market_opens.index[-1]
@@ -802,10 +797,12 @@ class BcolzMinuteBarTestCase(TestCase):
data = {sids[0]: data_1, sids[1]: data_2}
start_minute_loc = self.env.market_minutes.get_loc(minutes[0])
minute_locs = [self.env.market_minutes.get_loc(minute) -
start_minute_loc
for minute in minutes]
start_minute_loc = \
default_nyse_schedule.all_execution_minutes.get_loc(minutes[0])
minute_locs = [
default_nyse_schedule.all_execution_minutes.get_loc(minute) \
- start_minute_loc
for minute in minutes]
for i, col in enumerate(columns):
for j, sid in enumerate(sids):
@@ -824,7 +821,9 @@ class BcolzMinuteBarTestCase(TestCase):
'close': arange(1, 781),
'volume': arange(1, 781)
}
dts = array(self.env.minutes_for_days_in_range(start_day, end_day))
dts = array(default_nyse_schedule.execution_minutes_for_days_in_range(
start_day, end_day
))
self.writer.write_cols(sid, dts, cols)
self.assertEqual(
@@ -866,7 +865,9 @@ class BcolzMinuteBarTestCase(TestCase):
'close': arange(1, 601),
'volume': arange(1, 601)
}
dts = array(self.env.minutes_for_days_in_range(start_day, end_day))
dts = array(default_nyse_schedule.execution_minutes_for_days_in_range(
start_day, end_day
))
self.writer.write_cols(sid, dts, cols)
self.assertEqual(
+4 -5
View File
@@ -46,6 +46,7 @@ from zipline.testing.fixtures import (
WithBcolzDailyBarReader,
ZiplineTestCase,
)
from zipline.utils.calendars import get_calendar
TEST_CALENDAR_START = Timestamp('2015-06-01', tz='UTC')
TEST_CALENDAR_STOP = Timestamp('2015-06-30', tz='UTC')
@@ -96,11 +97,9 @@ class BcolzDailyBarTestCase(WithBcolzDailyBarReader, ZiplineTestCase):
@classmethod
def init_class_fixtures(cls):
super(BcolzDailyBarTestCase, cls).init_class_fixtures()
all_trading_days = cls.env.trading_days
cls.trading_days = all_trading_days[
all_trading_days.get_loc(TEST_CALENDAR_START):
all_trading_days.get_loc(TEST_CALENDAR_STOP) + 1
]
cls.trading_days = get_calendar('NYSE').trading_days(
TEST_CALENDAR_START, TEST_CALENDAR_STOP
).index
@property
def assets(self):