-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from quantopian/add-india
ENH: Add Bombay, Shanghai, Singapore
- Loading branch information
Showing
17 changed files
with
22,860 additions
and
38 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import pandas as pd | ||
|
||
|
||
def T(x): | ||
return pd.Timestamp(x, tz='UTC') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from unittest import TestCase | ||
|
||
from .test_trading_calendar import ExchangeCalendarTestBase | ||
from .test_utils import T | ||
from trading_calendars.exchange_calendar_xbom import XBOMExchangeCalendar | ||
|
||
|
||
class XBOMCalendarTestCase(ExchangeCalendarTestBase, TestCase): | ||
|
||
answer_key_filename = 'xbom' | ||
calendar_class = XBOMExchangeCalendar | ||
|
||
# BSE is open from 9:15 am to 3:30 pm | ||
MAX_SESSION_HOURS = 6.25 | ||
|
||
HAVE_EARLY_CLOSES = False | ||
|
||
def test_normal_year(self): | ||
expected_holidays_2017 = [ | ||
T('2017-01-26'), | ||
T('2017-02-24'), | ||
T('2017-03-13'), | ||
T('2017-04-04'), | ||
T('2017-04-14'), | ||
T('2017-05-01'), | ||
T('2017-06-26'), | ||
T('2017-08-15'), | ||
T('2017-08-25'), | ||
T('2017-10-02'), | ||
T('2017-10-20'), | ||
T('2017-12-25'), | ||
] | ||
|
||
for session_label in expected_holidays_2017: | ||
self.assertNotIn(session_label, self.calendar.all_sessions) | ||
|
||
def test_constrain_construction_dates(self): | ||
# the XBOM calendar currently goes from 1997 to 2020, inclusive. | ||
with self.assertRaises(ValueError) as e: | ||
self.calendar_class(T('1996-12-31'), T('1998-01-01')) | ||
|
||
self.assertEqual( | ||
str(e.exception), | ||
( | ||
'The XBOM holidays are only recorded back to 1997,' | ||
' cannot instantiate the XBOM calendar back to 1996.' | ||
) | ||
) | ||
|
||
with self.assertRaises(ValueError) as e: | ||
self.calendar_class(T('1998-01-01'), T('2021-01-01')) | ||
|
||
self.assertEqual( | ||
str(e.exception), | ||
( | ||
'The XBOM holidays are only recorded to 2020,' | ||
' cannot instantiate the XBOM calendar for 2021.' | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from unittest import TestCase | ||
|
||
from .test_trading_calendar import ExchangeCalendarTestBase | ||
from .test_utils import T | ||
from trading_calendars.exchange_calendar_xses import XSESExchangeCalendar | ||
|
||
|
||
class XSESCalendarTestCase(ExchangeCalendarTestBase, TestCase): | ||
|
||
answer_key_filename = 'xses' | ||
calendar_class = XSESExchangeCalendar | ||
|
||
# Singapore stock exchange is open from 9am to 5pm | ||
# (for now, ignoring lunch break) | ||
MAX_SESSION_HOURS = 8 | ||
|
||
HAVE_EARLY_CLOSES = False | ||
|
||
def test_normal_year(self): | ||
expected_holidays_2017 = [ | ||
T("2017-01-02"), | ||
T("2017-01-30"), | ||
T("2017-04-14"), | ||
T("2017-05-01"), | ||
T("2017-05-10"), | ||
T("2017-06-26"), | ||
T("2017-08-09"), | ||
T("2017-09-01"), | ||
T("2017-10-18"), | ||
T("2017-12-25"), | ||
] | ||
|
||
for session_label in expected_holidays_2017: | ||
self.assertNotIn(session_label, self.calendar.all_sessions) | ||
|
||
def test_constrain_construction_dates(self): | ||
# the XSES calendar currently goes from 1999 to 2025, inclusive. | ||
with self.assertRaises(ValueError) as e: | ||
self.calendar_class(T('1985-12-31'), T('2005-01-01')) | ||
|
||
self.assertEqual( | ||
str(e.exception), | ||
( | ||
'The XSES holidays are only recorded back to 1986,' | ||
' cannot instantiate the XSES calendar back to 1985.' | ||
) | ||
) | ||
|
||
with self.assertRaises(ValueError) as e: | ||
self.calendar_class(T('2005-01-01'), T('2021-01-01')) | ||
|
||
self.assertEqual( | ||
str(e.exception), | ||
( | ||
'The XSES holidays are only recorded to 2020,' | ||
' cannot instantiate the XSES calendar for 2021.' | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from unittest import TestCase | ||
import pandas as pd | ||
|
||
from .test_trading_calendar import ExchangeCalendarTestBase | ||
from .test_utils import T | ||
from trading_calendars.exchange_calendar_xshg import XSHGExchangeCalendar | ||
|
||
|
||
class XSHGCalendarTestCase(ExchangeCalendarTestBase, TestCase): | ||
|
||
answer_key_filename = 'xshg' | ||
calendar_class = XSHGExchangeCalendar | ||
|
||
# Shanghai stock exchange is open from 9:30 am to 3pm | ||
# (for now, ignoring lunch break) | ||
MAX_SESSION_HOURS = 5.5 | ||
|
||
HAVE_EARLY_CLOSES = False | ||
|
||
MINUTE_INDEX_TO_SESSION_LABELS_END = pd.Timestamp('2011-04-07', tz='UTC') | ||
|
||
def test_normal_year(self): | ||
expected_holidays_2017 = [ | ||
T("2017-01-02"), | ||
T("2017-01-27"), | ||
T("2017-01-30"), | ||
T("2017-01-31"), | ||
T("2017-02-01"), | ||
T("2017-02-02"), | ||
T("2017-04-03"), | ||
T("2017-04-04"), | ||
T("2017-05-01"), | ||
T("2017-05-29"), | ||
T("2017-05-30"), | ||
T("2017-10-02"), | ||
T("2017-10-03"), | ||
T("2017-10-04"), | ||
T("2017-10-05"), | ||
T("2017-10-06"), | ||
] | ||
|
||
for session_label in expected_holidays_2017: | ||
self.assertNotIn(session_label, self.calendar.all_sessions) | ||
|
||
def test_constrain_construction_dates(self): | ||
# the XSHG calendar currently goes from 1999 to 2025, inclusive. | ||
with self.assertRaises(ValueError) as e: | ||
self.calendar_class(T('1998-12-31'), T('2005-01-01')) | ||
|
||
self.assertEqual( | ||
str(e.exception), | ||
( | ||
'The XSHG holidays are only recorded back to 1999,' | ||
' cannot instantiate the XSHG calendar back to 1998.' | ||
) | ||
) | ||
|
||
with self.assertRaises(ValueError) as e: | ||
self.calendar_class(T('2005-01-01'), T('2026-01-01')) | ||
|
||
self.assertEqual( | ||
str(e.exception), | ||
( | ||
'The XSHG holidays are only recorded to 2025,' | ||
' cannot instantiate the XSHG calendar for 2026.' | ||
) | ||
) |
Oops, something went wrong.