Skip to content

Commit

Permalink
Merge pull request rsheftel#321 from danilogalisteu/patch-3
Browse files Browse the repository at this point in the history
Added national holiday for BMF calendar (Black Awareness Day, Nov 20th)
  • Loading branch information
rsheftel authored Feb 6, 2024
2 parents 5786635 + 019e18d commit 2eb992d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
15 changes: 12 additions & 3 deletions pandas_market_calendars/calendars/bmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,21 @@
month=11,
day=15,
)
# Day of Black Awareness
# Day of Black Awareness (municipal holiday for the city of São Paulo)
ConscienciaNegra = Holiday(
"Dia da Consciencia Negra",
month=11,
day=20,
start_date="2004-01-01",
end_date="2019-12-31",
)
# Day of Black Awareness (national holiday)
ConscienciaNegraNacional = Holiday(
"Dia da Consciencia Negra",
month=11,
day=20,
start_date="2023-12-22",
)
# Christmas Eve
VesperaNatal = Holiday(
"Vespera Natal",
Expand Down Expand Up @@ -154,12 +161,13 @@ class BMFExchangeCalendar(MarketCalendar):
- Corpus Christi (60 days after Easter)
- Tiradentes (April 21)
- Labor day (May 1)
- Constitutionalist Revolution (July 9 after 1997 until 2021, skipping 2020)
- Constitutionalist Revolution (July 9 from 1997 until 2021, skipping 2020)
- Independence Day (September 7)
- Our Lady of Aparecida Feast (October 12)
- All Souls' Day (November 2)
- Proclamation of the Republic (November 15)
- Day of Black Awareness (November 20 after 2004 until 2021, skipping 2020)
- Day of Black Awareness, municipal holiday for the city of São Paulo (November 20 from 2004 until 2021, skipping 2020)
- Day of Black Awareness, national holiday (November 20 starting in 2024)
- Christmas (December 24 and 25)
- Friday before New Year's Eve (December 30 or 29 if NYE falls on a Saturday or Sunday, respectively)
- New Year's Eve (December 31)
Expand Down Expand Up @@ -197,6 +205,7 @@ def regular_holidays(self):
Finados,
ProclamacaoRepublica,
ConscienciaNegra,
ConscienciaNegraNacional,
VesperaNatal,
Natal,
AnoNovo,
Expand Down
28 changes: 25 additions & 3 deletions tests/test_bmf_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def test_time_zone():
def test_2020_holidays_skip():
# 2020-07-09 - skipped due to covid
# 2020-11-20 - skipped due to covid

holidays = BMFExchangeCalendar().holidays().holidays
for date in ["2019-07-09", "2019-11-20", "2021-07-09", "2021-11-20"]:
assert pd.Timestamp(date, tz="UTC").to_datetime64() in holidays
Expand All @@ -22,6 +23,8 @@ def test_2020_holidays_skip():

def test_post_2022_regulation_change():
# Regional holidays no longer observed: January 25th, July 9th, November 20th
# November 20th was reinstated as a national holiday starting in 2024

holidays = BMFExchangeCalendar().holidays().holidays

for year in [2017, 2018, 2019, 2021]: # skip 2020 due to test above
Expand All @@ -30,9 +33,14 @@ def test_post_2022_regulation_change():
pd.Timestamp(datetime.date(year, month, day), tz="UTC").to_datetime64()
in holidays
)

for year in range(2022, 2040):
for month, day in [(1, 25), (7, 9), (11, 20)]:
for month, day in [(1, 25), (7, 9)]:
assert (
pd.Timestamp(datetime.date(year, month, day), tz="UTC").to_datetime64()
not in holidays
)
for year in range(2022, 2024):
for month, day in [(11, 20)]:
assert (
pd.Timestamp(datetime.date(year, month, day), tz="UTC").to_datetime64()
not in holidays
Expand All @@ -41,10 +49,24 @@ def test_post_2022_regulation_change():

def test_sunday_new_years_eve():
# All instances of December 29th on a Friday should be holidays

holidays = BMFExchangeCalendar().holidays().holidays

for year in range(1994, 2040):
date = pd.Timestamp(datetime.date(year, 12, 29), tz="UTC")
if date.day_of_week == 4:
# December 29th on a Friday
assert date.to_datetime64() not in holidays

assert date.to_datetime64() in holidays


def test_post_2022_nov20():
# November 20th national holiday should be present from 2024

holidays = BMFExchangeCalendar().holidays().holidays

for year in range(2024, 2040):
assert (
pd.Timestamp(datetime.date(year, 11, 20), tz="UTC").to_datetime64()
in holidays
)

0 comments on commit 2eb992d

Please sign in to comment.