Skip to content

Commit

Permalink
ENH: Adds ExchangeCalendar, TradingSchedule, and implementations
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jfkirk authored and Jean Bredeche committed Jun 8, 2016
1 parent c9b5979 commit c8304e8
Show file tree
Hide file tree
Showing 46 changed files with 9,709 additions and 1,137 deletions.
33 changes: 17 additions & 16 deletions tests/data/test_minute_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
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
Expand All @@ -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]

Expand Down Expand Up @@ -802,10 +797,12 @@ def test_unadjusted_minutes_early_close(self):

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):
Expand All @@ -824,7 +821,9 @@ def test_adjust_non_trading_minutes(self):
'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(
Expand Down Expand Up @@ -866,7 +865,9 @@ def test_adjust_non_trading_minutes_half_days(self):
'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(
Expand Down
9 changes: 4 additions & 5 deletions tests/data/test_us_equity_pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
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')
Expand Down Expand Up @@ -96,11 +97,9 @@ def make_daily_bar_data(cls):
@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):
Expand Down
7 changes: 6 additions & 1 deletion tests/finance/test_slippage.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
WithSimParams,
ZiplineTestCase,
)
from zipline.utils.calendars import default_nyse_schedule


class SlippageTestCase(WithSimParams, WithDataPortal, ZiplineTestCase):
Expand Down Expand Up @@ -93,7 +94,7 @@ def test_volume_share_slippage(self):
)
with tmp_bcolz_minute_bar_reader(self.env, days, assets) as reader:
data_portal = DataPortal(
self.env,
self.env, default_nyse_schedule,
first_trading_day=reader.first_trading_day,
equity_minute_reader=reader,
)
Expand Down Expand Up @@ -482,8 +483,12 @@ def test_orders_stop(self, name, order_data, event_data, expected):
)
with tmp_bcolz_minute_bar_reader(self.env, days, assets) as reader:
data_portal = DataPortal(
<<<<<<< HEAD
self.env,
first_trading_day=reader.first_trading_day,
=======
self.env, default_nyse_schedule,
>>>>>>> ENH: Adds ExchangeCalendar, TradingSchedule, and implementations
equity_minute_reader=reader,
)

Expand Down
9 changes: 5 additions & 4 deletions tests/pipeline/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
ZiplineTestCase,
)
from zipline.utils.memoize import lazyval
from zipline.utils.calendars import default_nyse_schedule


class RollingSumDifference(CustomFactor):
Expand Down Expand Up @@ -826,7 +827,7 @@ def init_class_fixtures(cls):
cls.dates = date_range(
cls.start,
cls.end,
freq=cls.env.trading_day,
freq=default_nyse_schedule.day,
tz='UTC',
)
cls.assets = cls.asset_finder.retrieve_all(cls.asset_ids)
Expand Down Expand Up @@ -985,7 +986,7 @@ def write_nans(self, df):
def test_SMA(self):
engine = SimplePipelineEngine(
lambda column: self.pipeline_loader,
self.env.trading_days,
default_nyse_schedule.all_execution_days,
self.asset_finder,
)
window_length = 5
Expand Down Expand Up @@ -1039,7 +1040,7 @@ def test_drawdown(self):
# valuable.
engine = SimplePipelineEngine(
lambda column: self.pipeline_loader,
self.env.trading_days,
default_nyse_schedule.all_execution_days,
self.asset_finder,
)
window_length = 5
Expand Down Expand Up @@ -1083,7 +1084,7 @@ class ParameterizedFactorTestCase(WithTradingEnvironment, ZiplineTestCase):
@classmethod
def init_class_fixtures(cls):
super(ParameterizedFactorTestCase, cls).init_class_fixtures()
day = cls.env.trading_day
day = default_nyse_schedule.day

cls.dates = dates = date_range(
'2015-02-01',
Expand Down
5 changes: 4 additions & 1 deletion tests/pipeline/test_pipeline_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
WithDataPortal,
ZiplineTestCase,
)
from zipline.utils.tradingcalendar import trading_day
from zipline.utils.calendars import default_nyse_schedule


TEST_RESOURCE_PATH = join(
Expand All @@ -70,6 +70,9 @@
)


trading_day = default_nyse_schedule.day


def rolling_vwap(df, length):
"Simple rolling vwap implementation for testing"
closes = df['close'].values
Expand Down
Loading

0 comments on commit c8304e8

Please sign in to comment.