Skip to content

Commit

Permalink
Merge pull request #131 from AlpacaDB/feature/fix-jpx-2020-calendar
Browse files Browse the repository at this point in the history
Fix XTKS 2020 holidays according to JPX calendar
  • Loading branch information
gerrymanoim authored Mar 31, 2020
2 parents 671136d + d54b42f commit 0a1de07
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 16 deletions.
6 changes: 3 additions & 3 deletions tests/resources/xtks.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5037,10 +5037,9 @@
2020-07-15,2020-07-15 00:01:00,2020-07-15 06:00:00
2020-07-16,2020-07-16 00:01:00,2020-07-16 06:00:00
2020-07-17,2020-07-17 00:01:00,2020-07-17 06:00:00
2020-07-20,2020-07-20 00:01:00,2020-07-20 06:00:00
2020-07-21,2020-07-21 00:01:00,2020-07-21 06:00:00
2020-07-22,2020-07-22 00:01:00,2020-07-22 06:00:00
2020-07-23,2020-07-23 00:01:00,2020-07-23 06:00:00
2020-07-24,2020-07-24 00:01:00,2020-07-24 06:00:00
2020-07-27,2020-07-27 00:01:00,2020-07-27 06:00:00
2020-07-28,2020-07-28 00:01:00,2020-07-28 06:00:00
2020-07-29,2020-07-29 00:01:00,2020-07-29 06:00:00
Expand All @@ -5051,7 +5050,7 @@
2020-08-05,2020-08-05 00:01:00,2020-08-05 06:00:00
2020-08-06,2020-08-06 00:01:00,2020-08-06 06:00:00
2020-08-07,2020-08-07 00:01:00,2020-08-07 06:00:00
2020-08-10,2020-08-10 00:01:00,2020-08-10 06:00:00
2020-08-11,2020-08-11 00:01:00,2020-08-11 06:00:00
2020-08-12,2020-08-12 00:01:00,2020-08-12 06:00:00
2020-08-13,2020-08-13 00:01:00,2020-08-13 06:00:00
2020-08-14,2020-08-14 00:01:00,2020-08-14 06:00:00
Expand Down Expand Up @@ -5093,6 +5092,7 @@
2020-10-07,2020-10-07 00:01:00,2020-10-07 06:00:00
2020-10-08,2020-10-08 00:01:00,2020-10-08 06:00:00
2020-10-09,2020-10-09 00:01:00,2020-10-09 06:00:00
2020-10-12,2020-10-12 00:01:00,2020-10-12 06:00:00
2020-10-13,2020-10-13 00:01:00,2020-10-13 06:00:00
2020-10-14,2020-10-14 00:01:00,2020-10-14 06:00:00
2020-10-15,2020-10-15 00:01:00,2020-10-15 06:00:00
Expand Down
29 changes: 29 additions & 0 deletions tests/test_xtks_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,32 @@ def test_2019_adhocs(self):

for holiday_label in expected_holidays:
self.assertNotIn(holiday_label, self.calendar.all_sessions)

def test_2020(self):
expected_holidays_2020 = [
pd.Timestamp("2020-01-01", tz=UTC), # New Year's holiday
pd.Timestamp("2020-01-02", tz=UTC), # New Year's holiday
pd.Timestamp("2020-01-03", tz=UTC), # New Year's holiday
pd.Timestamp("2020-01-13", tz=UTC), # Coming of Age Day
pd.Timestamp("2020-02-11", tz=UTC), # National Foundation Day
pd.Timestamp("2020-02-23", tz=UTC), # Emperor's Birthday
pd.Timestamp("2020-02-24", tz=UTC), # Emperor's Birthday observed
pd.Timestamp("2020-03-20", tz=UTC), # Vernal Equinox
pd.Timestamp("2020-04-29", tz=UTC), # Showa Day
pd.Timestamp("2020-05-03", tz=UTC), # Constitution Memorial Day
pd.Timestamp("2020-05-04", tz=UTC), # Greenery Day
pd.Timestamp("2020-05-05", tz=UTC), # Children's Day
pd.Timestamp("2020-05-06", tz=UTC), # Constitution Memorial Day
# observed
pd.Timestamp("2020-07-23", tz=UTC), # Marine Day
pd.Timestamp("2020-07-24", tz=UTC), # Sports Day
pd.Timestamp("2020-08-10", tz=UTC), # Mountain Day
pd.Timestamp("2020-09-21", tz=UTC), # Respect for the Aged Day
pd.Timestamp("2020-09-22", tz=UTC), # Autumnal Equinox
pd.Timestamp("2020-11-03", tz=UTC), # Culture Day
pd.Timestamp("2020-11-23", tz=UTC), # Labor Thanksgiving Day
pd.Timestamp("2020-12-31", tz=UTC), # New Year's holiday
]

for session_label in expected_holidays_2020:
self.assertNotIn(session_label, self.calendar.all_sessions)
26 changes: 19 additions & 7 deletions trading_calendars/exchange_calendar_xtks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@
CitizensHolidayGoldenWeek,
ChildrensDay,
MarineDayThrough2002,
MarineDay2003Onwards,
MountainDay,
MarineDay2003OnwardsThrough2019,
MarineDay2020,
MarineDay2021Onwards,
MountainDayThrough2019,
MountainDay2020,
MountainDay2021Onwards,
AutumnalEquinoxes,
CitizensHolidaySilverWeek,
RespectForTheAgedDayThrough2002,
RespectForTheAgedDay2003Onwards,
HealthAndSportsDay,
HealthAndSportsDayThrough2019,
HealthAndSportsDay2020,
HealthAndSportsDay2021Onwards,
CultureDay,
LaborThanksgivingDay,
EmperorAkihitoBirthday,
Expand All @@ -53,7 +59,7 @@ class XTKSExchangeCalendar(TradingCalendar):
NOTE: we are treating the two sessions per day as one session for now,
because we will not be handling minutely data in the immediate future.
Regularly-Observed Holidays (see tse_holidays.py for more info):
Regularly-Observed Holidays (see xtks_holidays.py for more info):
- New Year's Holidays (Dec. 31 - Jan. 3)
- Coming of Age Day (second Monday of January)
- National Foundation Day (Feb. 11)
Expand Down Expand Up @@ -105,11 +111,17 @@ def regular_holidays(self):
CitizensHolidayGoldenWeek,
ChildrensDay,
MarineDayThrough2002,
MarineDay2003Onwards,
MountainDay,
MarineDay2003OnwardsThrough2019,
MarineDay2020,
MarineDay2021Onwards,
MountainDayThrough2019,
MountainDay2020,
MountainDay2021Onwards,
RespectForTheAgedDayThrough2002,
RespectForTheAgedDay2003Onwards,
HealthAndSportsDay,
HealthAndSportsDayThrough2019,
HealthAndSportsDay2020,
HealthAndSportsDay2021Onwards,
CultureDay,
LaborThanksgivingDay,
EmperorAkihitoBirthday,
Expand Down
63 changes: 57 additions & 6 deletions trading_calendars/xtks_holidays.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,53 @@ def next_non_holiday_weekday(holidays, dt):
observance=sunday_to_monday,
)

MarineDay2003Onwards = Holiday(
"Marine Day (2003 onwards)",
MarineDay2003OnwardsThrough2019 = Holiday(
"Marine Day (2003 - 2019)",
month=7,
day=1,
offset=DateOffset(weekday=MO(3)),
start_date='2003-01-01',
end_date='2020-01-01',
)

MountainDay = Holiday(
"Mountain Day",
# Changed due to Tokyo Olympics
MarineDay2020 = Holiday(
"Marine Day (2020)",
month=7,
day=23,
year=2020,
)

MarineDay2021Onwards = Holiday(
"Marine Day (2021 onwards)",
month=7,
day=1,
offset=DateOffset(weekday=MO(3)),
start_date='2021-01-01',
)

MountainDayThrough2019 = Holiday(
"Mountain Day (through 2019)",
month=8,
day=11,
start_date='2016-01-01',
end_date='2020-01-01',
observance=sunday_to_monday,
)

# Changed due to Tokyo Olympics
MountainDay2020 = Holiday(
"Mountain Day (2020)",
month=8,
day=10,
year=2020,
)

MountainDay2021Onwards = Holiday(
"Mountain Day (2021 onwards)",
month=8,
day=11,
start_date="2021-01-01",
observance=sunday_to_monday,
)

Expand Down Expand Up @@ -242,11 +276,28 @@ def next_non_holiday_weekday(holidays, dt):
start_date='2003-01-01',
)

HealthAndSportsDay = Holiday(
"Health and Sports Day",
HealthAndSportsDayThrough2019 = Holiday(
"Health and Sports Day (through 2019)",
month=10,
day=1,
offset=DateOffset(weekday=MO(2)),
end_date="2020-01-01",
)

# Changed due to Tokyo Olympics
HealthAndSportsDay2020 = Holiday(
"Health and Sports Day (2020)",
month=7,
day=24,
year=2020,
)

HealthAndSportsDay2021Onwards = Holiday(
"Health and Sports Day (2021 onwards)",
month=10,
day=1,
offset=DateOffset(weekday=MO(2)),
start_date="2021-01-01",
)

CultureDay = Holiday(
Expand Down

0 comments on commit 0a1de07

Please sign in to comment.