DEV: Change daily mode to use last minute of session instead of session itself.

This commit is contained in:
Jean Bredeche
2016-07-21 10:00:04 -04:00
parent 2462929368
commit 3305933089
7 changed files with 65 additions and 40 deletions
+21 -7
View File
@@ -3731,12 +3731,18 @@ class TestEquityAutoClose(WithTmpDir, WithTradingCalendar, ZiplineTestCase):
transactions = output['transactions']
initial_fills = transactions.iloc[1]
self.assertEqual(len(initial_fills), len(assets))
last_minute_of_session = \
self.trading_calendar.open_and_close_for_session(
self.test_days[1]
)[1]
for sid, txn in zip(sids, initial_fills):
self.assertDictContainsSubset(
{
'amount': order_size,
'commission': None,
'dt': self.test_days[1],
'dt': last_minute_of_session,
'price': initial_fill_prices[sid],
'sid': sid,
},
@@ -3803,15 +3809,17 @@ class TestEquityAutoClose(WithTmpDir, WithTradingCalendar, ZiplineTestCase):
context.portfolio.cash == context.portfolio.starting_cash
)
now = context.get_datetime()
today_session = self.trading_calendar.minute_to_session_label(
context.get_datetime()
)
if now == first_asset_end_date:
if today_session == first_asset_end_date:
# Equity 0 will no longer exist tomorrow, so this order will
# never be filled.
assert len(context.get_open_orders()) == 0
context.order(context.sid(0), 10)
assert len(context.get_open_orders()) == 1
elif now == first_asset_auto_close_date:
elif today_session == first_asset_auto_close_date:
assert len(context.get_open_orders()) == 0
algo = TradingAlgorithm(
@@ -3829,12 +3837,18 @@ class TestEquityAutoClose(WithTmpDir, WithTradingCalendar, ZiplineTestCase):
original_open_orders = orders_for_date(first_asset_end_date)
assert len(original_open_orders) == 1
last_close_for_asset = \
algo.trading_calendar.open_and_close_for_session(
first_asset_end_date
)[1]
self.assertDictContainsSubset(
{
'amount': 10,
'commission': 0,
'created': first_asset_end_date,
'dt': first_asset_end_date,
'created': last_close_for_asset,
'dt': last_close_for_asset,
'sid': assets[0],
'status': ORDER_STATUS.OPEN,
'filled': 0,
@@ -3848,7 +3862,7 @@ class TestEquityAutoClose(WithTmpDir, WithTradingCalendar, ZiplineTestCase):
{
'amount': 10,
'commission': 0,
'created': first_asset_end_date,
'created': last_close_for_asset,
'dt': first_asset_auto_close_date,
'sid': assets[0],
'status': ORDER_STATUS.CANCELLED,