Skip to content

Commit 8fe2808

Browse files
authored
Merge pull request #462 from QuantIntellect/fix/australia-substitute-holidays
Observe New Year's, Christmas and Boxing Day substitute holidays in the AUSTRALIA calendar
2 parents 3e90210 + 2c479d3 commit 8fe2808

4 files changed

Lines changed: 64 additions & 2 deletions

File tree

‎financepy/utils/calendar.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,10 @@ def holiday_australia(self, dt: Date, day_in_year: int, weekday: int):
836836
if m == 1 and d == 1: # new years day
837837
return True
838838

839+
# New Year's Day on a Saturday or Sunday is observed on the Monday
840+
if m == 1 and d in (2, 3) and weekday == Date.MON:
841+
return True
842+
839843
if m == 1 and d == 26: # Australia day
840844
return True
841845

@@ -878,7 +882,9 @@ def holiday_australia(self, dt: Date, day_in_year: int, weekday: int):
878882
if m == 12 and d == 26 and weekday == Date.MON: # Xmas
879883
return True
880884

881-
if m == 12 and d == 27 and weekday == Date.MON: # Xmas
885+
# Christmas on a Saturday is observed on Monday 27 December, and
886+
# Christmas on a Sunday on Tuesday 27 December (after Boxing Day)
887+
if m == 12 and d == 27 and weekday in (Date.MON, Date.TUE): # Xmas
882888
return True
883889

884890
if m == 12 and d == 26: # Boxing day
@@ -887,7 +893,9 @@ def holiday_australia(self, dt: Date, day_in_year: int, weekday: int):
887893
if m == 12 and d == 27 and weekday == Date.MON: # Boxing
888894
return True
889895

890-
if m == 12 and d == 28 and weekday == Date.MON: # Boxing
896+
# Boxing Day on a Saturday is observed on Monday 28 December, and
897+
# on a Sunday (Christmas on Saturday) on Tuesday 28 December
898+
if m == 12 and d == 28 and weekday in (Date.MON, Date.TUE): # Boxing
891899
return True
892900

893901
return False

‎tests/regression/golden/regression_test_calendar_GOLDEN.testLog‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,10 @@ RESULTS,AUSTRALIA,MON JUN 14 2021,
10861086
RESULTS,AUSTRALIA,SAT DEC 25 2021,
10871087
RESULTS,AUSTRALIA,SUN DEC 26 2021,
10881088
RESULTS,AUSTRALIA,MON DEC 27 2021,
1089+
RESULTS,AUSTRALIA,TUE DEC 28 2021,
10891090
BANNER,================================
10901091
RESULTS,AUSTRALIA,SAT JAN 01 2022,
1092+
RESULTS,AUSTRALIA,MON JAN 03 2022,
10911093
RESULTS,AUSTRALIA,WED JAN 26 2022,
10921094
RESULTS,AUSTRALIA,FRI APR 15 2022,
10931095
RESULTS,AUSTRALIA,MON APR 18 2022,
@@ -1096,8 +1098,10 @@ RESULTS,AUSTRALIA,MON JUN 13 2022,
10961098
RESULTS,AUSTRALIA,THU SEP 22 2022,
10971099
RESULTS,AUSTRALIA,SUN DEC 25 2022,
10981100
RESULTS,AUSTRALIA,MON DEC 26 2022,
1101+
RESULTS,AUSTRALIA,TUE DEC 27 2022,
10991102
BANNER,================================
11001103
RESULTS,AUSTRALIA,SUN JAN 01 2023,
1104+
RESULTS,AUSTRALIA,MON JAN 02 2023,
11011105
RESULTS,AUSTRALIA,THU JAN 26 2023,
11021106
RESULTS,AUSTRALIA,FRI APR 07 2023,
11031107
RESULTS,AUSTRALIA,MON APR 10 2023,
@@ -1145,8 +1149,10 @@ RESULTS,AUSTRALIA,MON JUN 14 2027,
11451149
RESULTS,AUSTRALIA,SAT DEC 25 2027,
11461150
RESULTS,AUSTRALIA,SUN DEC 26 2027,
11471151
RESULTS,AUSTRALIA,MON DEC 27 2027,
1152+
RESULTS,AUSTRALIA,TUE DEC 28 2027,
11481153
BANNER,================================
11491154
RESULTS,AUSTRALIA,SAT JAN 01 2028,
1155+
RESULTS,AUSTRALIA,MON JAN 03 2028,
11501156
RESULTS,AUSTRALIA,WED JAN 26 2028,
11511157
RESULTS,AUSTRALIA,FRI APR 14 2028,
11521158
RESULTS,AUSTRALIA,MON APR 17 2028,

‎tests/regression/regression_test_calendar.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ def test_australia():
289289
assert not cal.is_business_day(Date(6, 4, 2026)) # Easter Monday
290290
assert not cal.is_business_day(Date(25, 4, 2026)) # ANZAC
291291
assert not cal.is_business_day(Date(25, 12, 2026))
292+
assert not cal.is_business_day(Date(28, 12, 2026)) # Boxing Day observed
293+
assert not cal.is_business_day(Date(28, 12, 2027)) # Boxing Day observed
294+
assert not cal.is_business_day(Date(3, 1, 2028)) # New Year's Day observed
292295

293296

294297
def test_canada():

‎tests/unit/test_calendar.py‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,51 @@ def test_uk_one_off_bank_holidays(cal_type):
319319
assert cal.is_business_day(Date(31, 12, 2010))
320320

321321

322+
def test_australia_new_year_observed():
323+
cal = Calendar(CalendarTypes.AUSTRALIA)
324+
325+
# 1 January falls on a Saturday, so New Year's Day is observed on
326+
# Monday 3 January
327+
for y in [2022, 2028, 2033]:
328+
assert cal.is_holiday(Date(3, 1, y)), y
329+
assert cal.is_business_day(Date(4, 1, y)), y
330+
331+
# 1 January falls on a Sunday, so New Year's Day is observed on
332+
# Monday 2 January
333+
for y in [2012, 2017, 2023]:
334+
assert cal.is_holiday(Date(2, 1, y)), y
335+
assert cal.is_business_day(Date(3, 1, y)), y
336+
337+
assert cal.add_business_days(Date(30, 12, 2022), 1) == Date(3, 1, 2023)
338+
339+
340+
def test_australia_christmas_and_boxing_day_observed():
341+
cal = Calendar(CalendarTypes.AUSTRALIA)
342+
343+
# 25 December falls on a Sunday, so Boxing Day is Monday 26 December
344+
# and Christmas is observed on Tuesday 27 December
345+
for y in [2016, 2022, 2033]:
346+
assert cal.is_holiday(Date(26, 12, y)), y
347+
assert cal.is_holiday(Date(27, 12, y)), y
348+
assert cal.is_business_day(Date(28, 12, y)), y
349+
350+
# 25 December falls on a Saturday, so Christmas is observed on Monday
351+
# 27 December and Boxing Day on Tuesday 28 December
352+
for y in [2021, 2027, 2032]:
353+
assert cal.is_holiday(Date(27, 12, y)), y
354+
assert cal.is_holiday(Date(28, 12, y)), y
355+
assert cal.is_business_day(Date(29, 12, y)), y
356+
357+
# 26 December falls on a Saturday, so Boxing Day is observed on
358+
# Monday 28 December (unchanged)
359+
for y in [2015, 2020, 2026]:
360+
assert cal.is_holiday(Date(28, 12, y)), y
361+
assert cal.is_business_day(Date(29, 12, y)), y
362+
363+
assert cal.add_business_days(Date(23, 12, 2022), 1) == Date(28, 12, 2022)
364+
assert cal.add_business_days(Date(24, 12, 2021), 1) == Date(29, 12, 2021)
365+
366+
322367
@pytest.mark.parametrize(
323368
"cal_type",
324369
[

0 commit comments

Comments
 (0)