Skip to content

Commit

Permalink
ENH: Adds QuantopianUSFuturesCalendar (quantopian#1414)
Browse files Browse the repository at this point in the history
For trading US futures across the exchanges supported by Zipline.
  • Loading branch information
Andrew Daniels committed Aug 19, 2016
1 parent 653865b commit 5fb415e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
6 changes: 6 additions & 0 deletions zipline/utils/calendars/calendar_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from zipline.utils.calendars.exchange_calendar_bmf import BMFExchangeCalendar
from zipline.utils.calendars.exchange_calendar_lse import LSEExchangeCalendar
from zipline.utils.calendars.exchange_calendar_tsx import TSXExchangeCalendar
from zipline.utils.calendars.us_futures_calendar import (
QuantopianUSFuturesCalendar,
)


NYSE_CALENDAR_EXCHANGE_NAMES = frozenset([
Expand All @@ -31,6 +34,8 @@
LSE_CALENDAR_EXCHANGE_NAMES = frozenset(["LSE"])
TSX_CALENDAR_EXCHANGE_NAMES = frozenset(["TSX"])

US_FUTURES_CALENDAR_NAMES = frozenset(["us_futures"])

_default_calendar_factories = {
NYSE_CALENDAR_EXCHANGE_NAMES: NYSEExchangeCalendar,
CME_CALENDAR_EXCHANGE_NAMES: CMEExchangeCalendar,
Expand All @@ -39,6 +44,7 @@
BMF_CALENDAR_EXCHANGE_NAMES: BMFExchangeCalendar,
LSE_CALENDAR_EXCHANGE_NAMES: LSEExchangeCalendar,
TSX_CALENDAR_EXCHANGE_NAMES: TSXExchangeCalendar,
US_FUTURES_CALENDAR_NAMES: QuantopianUSFuturesCalendar,
}


Expand Down
60 changes: 60 additions & 0 deletions zipline/utils/calendars/us_futures_calendar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from datetime import time

from pandas.tseries.holiday import GoodFriday
from pytz import timezone

from zipline.utils.calendars import TradingCalendar
from zipline.utils.calendars.trading_calendar import HolidayCalendar
from zipline.utils.calendars.us_holidays import (
USNewYearsDay,
Christmas
)


class QuantopianUSFuturesCalendar(TradingCalendar):
"""Synthetic calendar for trading US futures.
This calendar is a superset of all of the US futures exchange
calendars provided by Zipline (CFE, CME, ICE), and is intended for
trading across all of these exchanges.
Notes
-----
Open Time: 6:00 PM, US/Eastern
Close Time: 6:00 PM, US/Eastern
Regularly-Observed Holidays:
- New Years Day
- Good Friday
- Christmas
In order to align the hours of each session, we ignore the Sunday
CME Pre-Open hour (5-6pm).
"""
@property
def name(self):
return "us_futures"

@property
def tz(self):
return timezone('US/Eastern')

@property
def open_time(self):
return time(18, 1)

@property
def close_time(self):
return time(18)

@property
def open_offset(self):
return -1

@property
def regular_holidays(self):
return HolidayCalendar([
USNewYearsDay,
GoodFriday,
Christmas,
])

0 comments on commit 5fb415e

Please sign in to comment.