pandas-market-calendars 4.2.1__py3-none-any.whl → 4.3.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. pandas_market_calendars/calendar_registry.py +26 -25
  2. pandas_market_calendars/calendar_utils.py +1 -1
  3. pandas_market_calendars/calendars/__init__.py +0 -0
  4. pandas_market_calendars/{exchange_calendar_asx.py → calendars/asx.py} +2 -2
  5. pandas_market_calendars/{exchange_calendar_bmf.py → calendars/bmf.py} +1 -1
  6. pandas_market_calendars/{exchange_calendar_bse.py → calendars/bse.py} +1 -1
  7. pandas_market_calendars/{exchange_calendar_cboe.py → calendars/cboe.py} +15 -16
  8. pandas_market_calendars/{exchange_calendar_cme.py → calendars/cme.py} +4 -4
  9. pandas_market_calendars/{exchange_calendar_cme_globex_agriculture.py → calendars/cme_globex_agriculture.py} +5 -11
  10. pandas_market_calendars/{exchange_calendar_cme_globex_base.py → calendars/cme_globex_base.py} +5 -8
  11. pandas_market_calendars/calendars/cme_globex_crypto.py +147 -0
  12. pandas_market_calendars/{exchange_calendar_cme_globex_energy_and_metals.py → calendars/cme_globex_energy_and_metals.py} +10 -18
  13. pandas_market_calendars/{exchange_calendar_cme_globex_equities.py → calendars/cme_globex_equities.py} +3 -3
  14. pandas_market_calendars/{exchange_calendar_cme_globex_fixed_income.py → calendars/cme_globex_fixed_income.py} +3 -4
  15. pandas_market_calendars/{exchange_calendar_cme_globex_fx.py → calendars/cme_globex_fx.py} +3 -3
  16. pandas_market_calendars/{exchange_calendar_eurex.py → calendars/eurex.py} +1 -1
  17. pandas_market_calendars/{exchange_calendar_hkex.py → calendars/hkex.py} +3 -3
  18. pandas_market_calendars/{exchange_calendar_ice.py → calendars/ice.py} +3 -3
  19. pandas_market_calendars/{exchange_calendar_iex.py → calendars/iex.py} +2 -2
  20. pandas_market_calendars/{exchange_calendar_jpx.py → calendars/jpx.py} +3 -3
  21. pandas_market_calendars/{exchange_calendar_lse.py → calendars/lse.py} +2 -2
  22. pandas_market_calendars/{exchange_calendars_mirror.py → calendars/mirror.py} +2 -2
  23. pandas_market_calendars/{exchange_calendar_nyse.py → calendars/nyse.py} +2 -2
  24. pandas_market_calendars/{exchange_calendar_ose.py → calendars/ose.py} +1 -1
  25. pandas_market_calendars/{exchange_calendar_sifma.py → calendars/sifma.py} +7 -10
  26. pandas_market_calendars/{exchange_calendar_six.py → calendars/six.py} +1 -1
  27. pandas_market_calendars/{exchange_calendar_sse.py → calendars/sse.py} +2 -2
  28. pandas_market_calendars/{exchange_calendar_tase.py → calendars/tase.py} +1 -1
  29. pandas_market_calendars/{exchange_calendar_tsx.py → calendars/tsx.py} +2 -2
  30. pandas_market_calendars/holidays/__init__.py +0 -0
  31. pandas_market_calendars/{holidays_cme.py → holidays/cme.py} +3 -4
  32. pandas_market_calendars/{holidays_cme_globex.py → holidays/cme_globex.py} +35 -6
  33. pandas_market_calendars/{holidays_jp.py → holidays/jp.py} +1 -1
  34. pandas_market_calendars/{holidays_nyse.py → holidays/nyse.py} +3 -5
  35. pandas_market_calendars/{holidays_us.py → holidays/us.py} +1 -5
  36. pandas_market_calendars/market_calendar.py +28 -9
  37. {pandas_market_calendars-4.2.1.dist-info → pandas_market_calendars-4.3.1.dist-info}/METADATA +4 -7
  38. pandas_market_calendars-4.3.1.dist-info/RECORD +49 -0
  39. pandas_market_calendars-4.2.1.dist-info/RECORD +0 -46
  40. /pandas_market_calendars/{holidays_cn.py → holidays/cn.py} +0 -0
  41. /pandas_market_calendars/{jpx_equinox.py → holidays/jpx_equinox.py} +0 -0
  42. /pandas_market_calendars/{holidays_oz.py → holidays/oz.py} +0 -0
  43. /pandas_market_calendars/{holidays_sifma.py → holidays/sifma.py} +0 -0
  44. /pandas_market_calendars/{holidays_uk.py → holidays/uk.py} +0 -0
  45. {pandas_market_calendars-4.2.1.dist-info → pandas_market_calendars-4.3.1.dist-info}/LICENSE +0 -0
  46. {pandas_market_calendars-4.2.1.dist-info → pandas_market_calendars-4.3.1.dist-info}/NOTICE +0 -0
  47. {pandas_market_calendars-4.2.1.dist-info → pandas_market_calendars-4.3.1.dist-info}/WHEEL +0 -0
  48. {pandas_market_calendars-4.2.1.dist-info → pandas_market_calendars-4.3.1.dist-info}/top_level.txt +0 -0
@@ -1,31 +1,32 @@
1
1
  from .market_calendar import MarketCalendar
2
- from .exchange_calendar_asx import ASXExchangeCalendar
3
- from .exchange_calendar_bmf import BMFExchangeCalendar
4
- from .exchange_calendar_cboe import CFEExchangeCalendar
5
- from .exchange_calendar_cme import \
2
+ from .calendars.asx import ASXExchangeCalendar
3
+ from .calendars.bmf import BMFExchangeCalendar
4
+ from .calendars.bse import BSEExchangeCalendar
5
+ from .calendars.cboe import CFEExchangeCalendar
6
+ from .calendars.cme import \
6
7
  CMEEquityExchangeCalendar, \
7
8
  CMEBondExchangeCalendar
8
- from .exchange_calendar_cme_globex_base import CMEGlobexBaseExchangeCalendar
9
- from .exchange_calendar_cme_globex_agriculture import CMEGlobexAgricultureExchangeCalendar
10
- from .exchange_calendar_cme_globex_fx import CMEGlobexFXExchangeCalendar
11
- from .exchange_calendar_cme_globex_energy_and_metals import CMEGlobexEnergyAndMetalsExchangeCalendar
12
- from .exchange_calendar_cme_globex_equities import CMEGlobexEquitiesExchangeCalendar
13
- from .exchange_calendar_cme_globex_fixed_income import CMEGlobexFixedIncomeCalendar
14
- from .exchange_calendar_eurex import EUREXExchangeCalendar
15
- from .exchange_calendar_hkex import HKEXExchangeCalendar
16
- from .exchange_calendar_ice import ICEExchangeCalendar
17
- from .exchange_calendar_iex import IEXExchangeCalendar
18
- from .exchange_calendar_jpx import JPXExchangeCalendar
19
- from .exchange_calendar_lse import LSEExchangeCalendar
20
- from .exchange_calendar_nyse import NYSEExchangeCalendar
21
- from .exchange_calendar_ose import OSEExchangeCalendar
22
- from .exchange_calendar_sifma import SIFMAUSExchangeCalendar, SIFMAUKExchangeCalendar, SIFMAJPExchangeCalendar
23
- from .exchange_calendar_six import SIXExchangeCalendar
24
- from .exchange_calendar_sse import SSEExchangeCalendar
25
- from .exchange_calendar_tsx import TSXExchangeCalendar
26
- from .exchange_calendar_bse import BSEExchangeCalendar
27
- from .exchange_calendar_tase import TASEExchangeCalendar
28
- from .exchange_calendars_mirror import *
9
+ from .calendars.cme_globex_base import CMEGlobexBaseExchangeCalendar
10
+ from .calendars.cme_globex_agriculture import CMEGlobexAgricultureExchangeCalendar
11
+ from .calendars.cme_globex_crypto import CMEGlobexCryptoExchangeCalendar
12
+ from .calendars.cme_globex_energy_and_metals import CMEGlobexEnergyAndMetalsExchangeCalendar
13
+ from .calendars.cme_globex_equities import CMEGlobexEquitiesExchangeCalendar
14
+ from .calendars.cme_globex_fx import CMEGlobexFXExchangeCalendar
15
+ from .calendars.cme_globex_fixed_income import CMEGlobexFixedIncomeCalendar
16
+ from .calendars.eurex import EUREXExchangeCalendar
17
+ from .calendars.hkex import HKEXExchangeCalendar
18
+ from .calendars.ice import ICEExchangeCalendar
19
+ from .calendars.iex import IEXExchangeCalendar
20
+ from .calendars.jpx import JPXExchangeCalendar
21
+ from .calendars.lse import LSEExchangeCalendar
22
+ from .calendars.nyse import NYSEExchangeCalendar
23
+ from .calendars.ose import OSEExchangeCalendar
24
+ from .calendars.sifma import SIFMAUSExchangeCalendar, SIFMAUKExchangeCalendar, SIFMAJPExchangeCalendar
25
+ from .calendars.six import SIXExchangeCalendar
26
+ from .calendars.sse import SSEExchangeCalendar
27
+ from .calendars.tase import TASEExchangeCalendar
28
+ from .calendars.tsx import TSXExchangeCalendar
29
+ from .calendars.mirror import *
29
30
 
30
31
 
31
32
  def get_calendar(name, open_time=None, close_time=None) -> MarketCalendar:
@@ -14,7 +14,7 @@ def merge_schedules(schedules, how='outer'):
14
14
 
15
15
  CAVEATS:
16
16
  * This does not work for schedules with breaks, the break information will be lost.
17
- * Onlu "market_open" and "market_close" are considered, other market times are not yet supported.
17
+ * Only "market_open" and "market_close" are considered, other market times are not yet supported.
18
18
 
19
19
  :param schedules: list of schedules
20
20
  :param how: outer or inner
File without changes
@@ -3,8 +3,8 @@ from datetime import time
3
3
  from pandas.tseries.holiday import AbstractHolidayCalendar, GoodFriday, EasterMonday
4
4
  from pytz import timezone
5
5
 
6
- from .holidays_oz import *
7
- from .market_calendar import MarketCalendar
6
+ from pandas_market_calendars.holidays.oz import *
7
+ from pandas_market_calendars.market_calendar import MarketCalendar
8
8
 
9
9
  AbstractHolidayCalendar.start_date = '2011-01-01'
10
10
 
@@ -19,7 +19,7 @@ from pandas import Timestamp
19
19
  from pandas.tseries.holiday import AbstractHolidayCalendar, Day, Easter, GoodFriday, Holiday
20
20
  from pytz import timezone
21
21
 
22
- from .market_calendar import (FRIDAY, MarketCalendar)
22
+ from pandas_market_calendars.market_calendar import (FRIDAY, MarketCalendar)
23
23
 
24
24
  # Universal Confraternization (new years day)
25
25
  ConfUniversal = Holiday(
@@ -5,7 +5,7 @@ Bombay Stock Exchnage
5
5
  from pandas import Timestamp
6
6
  from pytz import timezone
7
7
  from datetime import time
8
- from .market_calendar import MarketCalendar
8
+ from pandas_market_calendars.market_calendar import MarketCalendar
9
9
 
10
10
 
11
11
  BSEClosedDay = [
@@ -6,28 +6,29 @@ from pytz import timezone
6
6
  from itertools import chain
7
7
  import pandas as pd
8
8
 
9
- from .holidays_us import (Christmas, USBlackFridayInOrAfter1993, USIndependenceDay, USMartinLutherKingJrAfter1998,
10
- USMemorialDay, USNewYearsDay, HurricaneSandyClosings, USNationalDaysofMourning)
11
- from .market_calendar import MarketCalendar
9
+ from pandas_market_calendars.holidays.us import (Christmas, USBlackFridayInOrAfter1993, USIndependenceDay, USMartinLutherKingJrAfter1998,
10
+ USMemorialDay, USNewYearsDay, HurricaneSandyClosings, USNationalDaysofMourning,
11
+ USJuneteenthAfter2022)
12
+ from pandas_market_calendars.market_calendar import MarketCalendar
12
13
 
13
14
 
14
- # TODO: In pandas 2.0.3 this no longer works as the dt passed in is the entire matrix and not a single date
15
15
  def good_friday_unless_christmas_nye_friday(dt):
16
16
  """
17
17
  Good Friday is a valid trading day if Christmas Day or New Years Day fall
18
18
  on a Friday.
19
19
  """
20
+ if isinstance(dt, pd.DatetimeIndex):
21
+ # Pandas < 2.1.0 will call with an index and fall-back to element by element
22
+ # Pandas == 2.1.0 will only call element by element
23
+ raise NotImplementedError()
24
+
20
25
  year = dt.year
21
- christmas_weekday = Christmas.observance(
22
- pd.Timestamp(year, 12, 25)
23
- ).weekday()
24
- nyd_weekday = USNewYearsDay.observance(
25
- pd.Timestamp(year, 1, 1)
26
- ).weekday()
26
+ christmas_weekday = Christmas.observance(pd.Timestamp(year=year, month=12, day=25)).weekday()
27
+ nyd_weekday = USNewYearsDay.observance(pd.Timestamp(year=year, month=1, day=1)).weekday()
27
28
  if christmas_weekday != 4 and nyd_weekday != 4:
28
- return GoodFriday._apply_rule(dt)
29
+ return GoodFriday.dates(pd.Timestamp(year=year, month=1, day=1), pd.Timestamp(year=year, month=12, day=31))[0]
29
30
  else:
30
- # compatibility for pandas 0.18.1
31
+ # Not a holiday so use NaT to ensure it gets removed
31
32
  return pd.NaT
32
33
 
33
34
 
@@ -70,8 +71,8 @@ class CFEExchangeCalendar(MarketCalendar):
70
71
  USNewYearsDay,
71
72
  USMartinLutherKingJrAfter1998,
72
73
  USPresidentsDay,
73
- # GoodFridayUnlessChristmasNYEFriday, #TODO: When this is fixed can return to using it
74
- GoodFriday,
74
+ GoodFridayUnlessChristmasNYEFriday,
75
+ USJuneteenthAfter2022,
75
76
  USIndependenceDay,
76
77
  USMemorialDay,
77
78
  USLaborDay,
@@ -112,5 +113,3 @@ class CBOEIndexOptionsExchangeCalendar(CFEExchangeCalendar):
112
113
  "market_open": ((None, time(8, 30)),),
113
114
  "market_close": ((None, time(15, 15)),)
114
115
  }
115
-
116
-
@@ -20,10 +20,10 @@ from pandas import Timestamp
20
20
  from pandas.tseries.holiday import AbstractHolidayCalendar, GoodFriday, USLaborDay, USPresidentsDay, USThanksgivingDay
21
21
  from pytz import timezone
22
22
 
23
- from .holidays_us import (Christmas, ChristmasEveBefore1993, ChristmasEveInOrAfter1993, USBlackFridayInOrAfter1993,
24
- USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay, USNationalDaysofMourning,
25
- USNewYearsDay)
26
- from .market_calendar import MarketCalendar
23
+ from pandas_market_calendars.holidays.us import (Christmas, ChristmasEveBefore1993, ChristmasEveInOrAfter1993, USBlackFridayInOrAfter1993,
24
+ USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay, USNationalDaysofMourning,
25
+ USNewYearsDay)
26
+ from pandas_market_calendars.market_calendar import MarketCalendar
27
27
 
28
28
 
29
29
  # Useful resources for making changes to this file: http://www.cmegroup.com/tools-information/holiday-calendar.html
@@ -13,22 +13,16 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- from abc import ABC, abstractmethod
17
- from .exchange_calendar_cme_globex_base import CMEGlobexBaseExchangeCalendar
16
+ from abc import abstractmethod
17
+ from .cme_globex_base import CMEGlobexBaseExchangeCalendar
18
18
 
19
19
  from datetime import time
20
- from itertools import chain
21
20
 
22
- from pandas import Timestamp
23
21
  from pandas.tseries.holiday import AbstractHolidayCalendar, GoodFriday, USLaborDay, USPresidentsDay, USThanksgivingDay
24
- from pytz import timezone
25
-
26
- from .holidays_us import (Christmas, ChristmasEveBefore1993, ChristmasEveInOrAfter1993, USBlackFridayInOrAfter1993,
27
- USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay, USJuneteenthAfter2022,
28
- USNationalDaysofMourning, USNewYearsDay)
29
- from .market_calendar import MarketCalendar
30
-
31
22
 
23
+ from pandas_market_calendars.holidays.us import (Christmas, ChristmasEveBefore1993, ChristmasEveInOrAfter1993, USBlackFridayInOrAfter1993,
24
+ USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay,
25
+ USNewYearsDay)
32
26
 
33
27
 
34
28
  class CMEGlobexAgricultureExchangeCalendar(CMEGlobexBaseExchangeCalendar):
@@ -15,17 +15,13 @@
15
15
 
16
16
  from abc import ABC, abstractmethod
17
17
 
18
- from datetime import time
19
- from itertools import chain
20
-
21
- from pandas import Timestamp
22
18
  from pandas.tseries.holiday import AbstractHolidayCalendar, GoodFriday, USLaborDay, USPresidentsDay, USThanksgivingDay
23
19
  from pytz import timezone
24
20
 
25
- from .holidays_us import (Christmas, ChristmasEveBefore1993, ChristmasEveInOrAfter1993, USBlackFridayInOrAfter1993,
26
- USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay, USJuneteenthAfter2022,
27
- USNationalDaysofMourning, USNewYearsDay)
28
- from .market_calendar import MarketCalendar
21
+ from pandas_market_calendars.holidays.us import (Christmas, ChristmasEveBefore1993, ChristmasEveInOrAfter1993, USBlackFridayInOrAfter1993,
22
+ USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay, USJuneteenthAfter2022,
23
+ USNewYearsDay)
24
+ from pandas_market_calendars.market_calendar import MarketCalendar
29
25
 
30
26
 
31
27
  class CMEGlobexBaseExchangeCalendar(MarketCalendar, ABC):
@@ -34,6 +30,7 @@ class CMEGlobexBaseExchangeCalendar(MarketCalendar, ABC):
34
30
 
35
31
  CME Markets: https://www.cmegroup.com/markets/agriculture.html#overview
36
32
  - Agriculture
33
+ - Crypto
37
34
  - Energy
38
35
  - Equity Index
39
36
  - FX
@@ -0,0 +1,147 @@
1
+ import datetime as dt
2
+
3
+ from pandas.tseries.holiday import AbstractHolidayCalendar
4
+ import pytz
5
+
6
+ from .cme_globex_base import CMEGlobexBaseExchangeCalendar
7
+ from pandas_market_calendars.holidays.cme import (
8
+ GoodFriday2021,
9
+ GoodFridayAfter2021,
10
+ GoodFridayBefore2021,
11
+ USIndependenceDayBefore2022PreviousDay,
12
+ )
13
+ from pandas_market_calendars.holidays.cme_globex import (
14
+ ChristmasCME,
15
+ USMartinLutherKingJrFrom2022,
16
+ USMartinLutherKingJrPre2022,
17
+ USPresidentsDayFrom2022,
18
+ USPresidentsDayPre2022,
19
+ USMemorialDayFrom2022,
20
+ USMemorialDayPre2022,
21
+ USJuneteenthFrom2022,
22
+ USIndependenceDayFrom2022,
23
+ USIndependenceDayPre2022,
24
+ USLaborDayFrom2022,
25
+ USLaborDayPre2022,
26
+ USThanksgivingDayFrom2022,
27
+ USThanksgivingDayPre2022,
28
+ USThanksgivingFridayFrom2021,
29
+ USThanksgivingFridayPre2021,
30
+ )
31
+ from pandas_market_calendars.holidays.us import (
32
+ ChristmasEveInOrAfter1993,
33
+ USNewYearsDay,
34
+ )
35
+
36
+
37
+ # https://github.com/rsheftel/pandas_market_calendars/blob/master/docs/new_market.rst
38
+ class CMEGlobexCryptoExchangeCalendar(CMEGlobexBaseExchangeCalendar):
39
+ # The label you fetch the exchange with in mcal.get_calendar('CME Globex ...')
40
+ aliases = ["CME Globex Cryptocurrencies", "CME Globex Crypto"]
41
+
42
+ # https://www.cmegroup.com/markets/cryptocurrencies/bitcoin/bitcoin.contractSpecs.html
43
+ regular_market_times = {
44
+ # Tuple[Tuple[first date used, time, offset], ...]
45
+ # -1 offset indicates that the open is on the previous day
46
+ # None for first date used marks the start, subsequent market times must have an actual timestamp
47
+ "market_open": (
48
+ (None, dt.time(17, tzinfo=pytz.timezone("America/Chicago")), -1),
49
+ ),
50
+ "market_close": (
51
+ (
52
+ None,
53
+ dt.time(16, tzinfo=pytz.timezone("America/Chicago")),
54
+ ),
55
+ ),
56
+ "break_start": (
57
+ (
58
+ None,
59
+ dt.time(16, tzinfo=pytz.timezone("America/Chicago")),
60
+ ),
61
+ ),
62
+ "break_end": (
63
+ (
64
+ None,
65
+ dt.time(17, tzinfo=pytz.timezone("America/Chicago")),
66
+ ),
67
+ ),
68
+ }
69
+
70
+ @property
71
+ def tz(self):
72
+ # Central Time
73
+ return pytz.timezone("America/Chicago")
74
+
75
+ @property
76
+ def name(self):
77
+ return "CME Globex Crypto"
78
+
79
+ # Check the .zip files at the bottom of this page
80
+ # https://www.cmegroup.com/tools-information/holiday-calendar.html?redirect=/tools-information/holiday-calendar/#cmeGlobex
81
+ # Note: many of the holiday objects (ie. GoodFridayBefore2021) were originally made for equities and other markets
82
+ # and hence have a start_date starting before crypto is actually available
83
+
84
+ @property
85
+ def regular_holidays(self):
86
+ # Days where the market is fully closed
87
+ return AbstractHolidayCalendar(
88
+ rules=[
89
+ GoodFridayBefore2021,
90
+ GoodFridayAfter2021,
91
+ ChristmasCME,
92
+ USNewYearsDay,
93
+ ]
94
+ )
95
+
96
+ @property
97
+ def special_closes(self):
98
+ # Days where the market closes early
99
+ # list[Tuple[time, AbstractHolidayCalendar]]
100
+ return [
101
+ (
102
+ dt.time(8, 15, tzinfo=pytz.timezone("America/Chicago")),
103
+ AbstractHolidayCalendar(rules=[GoodFriday2021]),
104
+ ),
105
+ (
106
+ dt.time(12, tzinfo=pytz.timezone("America/Chicago")),
107
+ AbstractHolidayCalendar(
108
+ rules=[
109
+ USMartinLutherKingJrPre2022,
110
+ USPresidentsDayPre2022,
111
+ USMemorialDayPre2022,
112
+ USIndependenceDayPre2022,
113
+ USLaborDayPre2022,
114
+ USThanksgivingDayPre2022,
115
+ ]
116
+ ),
117
+ ),
118
+ (
119
+ dt.time(12, 15, tzinfo=pytz.timezone("America/Chicago")),
120
+ AbstractHolidayCalendar(
121
+ rules=[
122
+ ChristmasEveInOrAfter1993,
123
+ USIndependenceDayBefore2022PreviousDay,
124
+ USThanksgivingFridayPre2021,
125
+ ]
126
+ ),
127
+ ),
128
+ (
129
+ dt.time(12, 45, tzinfo=pytz.timezone("America/Chicago")),
130
+ AbstractHolidayCalendar(rules=[USThanksgivingFridayFrom2021]),
131
+ ),
132
+ # TODO: this market already closes at 1600 normally, do we need these holidays?
133
+ (
134
+ dt.time(16, tzinfo=pytz.timezone("America/Chicago")),
135
+ AbstractHolidayCalendar(
136
+ rules=[
137
+ USMartinLutherKingJrFrom2022,
138
+ USPresidentsDayFrom2022,
139
+ USMemorialDayFrom2022,
140
+ USJuneteenthFrom2022,
141
+ USIndependenceDayFrom2022,
142
+ USLaborDayFrom2022,
143
+ USThanksgivingDayFrom2022,
144
+ ]
145
+ ),
146
+ ),
147
+ ]
@@ -13,14 +13,10 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- from abc import ABC, abstractmethod
17
- from .exchange_calendar_cme_globex_base import CMEGlobexBaseExchangeCalendar
16
+ from .cme_globex_base import CMEGlobexBaseExchangeCalendar
18
17
 
19
18
  from datetime import time
20
- from itertools import chain
21
19
 
22
- import pandas as pd
23
- from pandas import Timestamp
24
20
  from pandas.tseries.holiday import AbstractHolidayCalendar #, GoodFriday, USLaborDay, USPresidentsDay, USThanksgivingDay
25
21
  from pytz import timezone
26
22
 
@@ -28,19 +24,15 @@ from pytz import timezone
28
24
  # USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay, USJuneteenthAfter2022,
29
25
  # USNationalDaysofMourning, USNewYearsDay)
30
26
 
31
- from .holidays_cme_globex import ( USNewYearsDay,
32
- USMartinLutherKingJrFrom2022, USMartinLutherKingJrPre2022, USNewYearsDay,
33
- USPresidentsDayFrom2022, USPresidentsDayPre2022,
34
- GoodFriday,
35
- USMemorialDayFrom2022, USMemorialDayPre2022,
36
- USJuneteenthFrom2022,
37
- USIndependenceDayFrom2022, USIndependenceDayPre2022,
38
- USLaborDay,
39
- USThanksgivingDayFrom2022, USThanksgivingDayPre2022, FridayAfterThanksgiving,
40
- ChristmasCME)
41
- from .market_calendar import MarketCalendar
42
-
43
-
27
+ from pandas_market_calendars.holidays.cme_globex import (USMartinLutherKingJrFrom2022, USMartinLutherKingJrPre2022, USNewYearsDay,
28
+ USPresidentsDayFrom2022, USPresidentsDayPre2022,
29
+ GoodFriday,
30
+ USMemorialDayFrom2022, USMemorialDayPre2022,
31
+ USJuneteenthFrom2022,
32
+ USIndependenceDayFrom2022, USIndependenceDayPre2022,
33
+ USLaborDay,
34
+ USThanksgivingDayFrom2022, USThanksgivingDayPre2022, FridayAfterThanksgiving,
35
+ ChristmasCME)
44
36
 
45
37
 
46
38
  class CMEGlobexEnergyAndMetalsExchangeCalendar(CMEGlobexBaseExchangeCalendar):
@@ -1,10 +1,10 @@
1
- from .exchange_calendar_cme_globex_base import CMEGlobexBaseExchangeCalendar
1
+ from .cme_globex_base import CMEGlobexBaseExchangeCalendar
2
2
 
3
3
  from datetime import time
4
4
  from pandas.tseries.holiday import AbstractHolidayCalendar
5
5
  from pytz import timezone
6
6
 
7
- from pandas_market_calendars.holidays_cme import (
7
+ from pandas_market_calendars.holidays.cme import (
8
8
  USMartinLutherKingJrAfter1998Before2015,
9
9
  USMartinLutherKingJrAfter2015,
10
10
  USPresidentsDayBefore2015,
@@ -26,7 +26,7 @@ from pandas_market_calendars.holidays_cme import (
26
26
  USThanksgivingAfter2014,
27
27
  USThanksgivingFriday,
28
28
  )
29
- from pandas_market_calendars.holidays_us import (
29
+ from pandas_market_calendars.holidays.us import (
30
30
  USNewYearsDay,
31
31
  ChristmasEveInOrAfter1993,
32
32
  Christmas,
@@ -1,10 +1,9 @@
1
- from .exchange_calendar_cme_globex_base import CMEGlobexBaseExchangeCalendar
1
+ from .cme_globex_base import CMEGlobexBaseExchangeCalendar
2
2
 
3
3
  from datetime import time
4
4
  from pandas.tseries.holiday import AbstractHolidayCalendar
5
- from pytz import timezone
6
5
 
7
- from pandas_market_calendars.holidays_cme import (
6
+ from pandas_market_calendars.holidays.cme import (
8
7
  USMartinLutherKingJrAfter1998Before2015,
9
8
  USMartinLutherKingJrAfter1998Before2016FridayBefore,
10
9
  USMartinLutherKingJrAfter2015,
@@ -30,7 +29,7 @@ from pandas_market_calendars.holidays_cme import (
30
29
  USThanksgivingAfter2014,
31
30
  USThanksgivingFriday,
32
31
  )
33
- from pandas_market_calendars.holidays_us import (
32
+ from pandas_market_calendars.holidays.us import (
34
33
  USNewYearsDay,
35
34
  ChristmasEveInOrAfter1993,
36
35
  Christmas,
@@ -2,8 +2,8 @@ from datetime import time
2
2
 
3
3
  from pandas.tseries.holiday import AbstractHolidayCalendar
4
4
 
5
- from pandas_market_calendars.exchange_calendar_cme_globex_base import CMEGlobexBaseExchangeCalendar
6
- from pandas_market_calendars.holidays_cme import (
5
+ from pandas_market_calendars.calendars.cme_globex_base import CMEGlobexBaseExchangeCalendar
6
+ from pandas_market_calendars.holidays.cme import (
7
7
  USMartinLutherKingJrAfter1998Before2022,
8
8
  USPresidentsDayBefore2022,
9
9
  GoodFridayBefore2021,
@@ -15,7 +15,7 @@ from pandas_market_calendars.holidays_cme import (
15
15
  USThanksgivingBefore2022,
16
16
  USThanksgivingFriday,
17
17
  )
18
- from pandas_market_calendars.holidays_us import (
18
+ from pandas_market_calendars.holidays.us import (
19
19
  USNewYearsDay,
20
20
  ChristmasEveInOrAfter1993,
21
21
  Christmas,
@@ -7,7 +7,7 @@ from datetime import time
7
7
  from pandas.tseries.holiday import AbstractHolidayCalendar, EasterMonday, GoodFriday, Holiday, previous_friday
8
8
  from pytz import timezone
9
9
 
10
- from .market_calendar import (FRIDAY, MONDAY, MarketCalendar, THURSDAY, TUESDAY, WEDNESDAY)
10
+ from pandas_market_calendars.market_calendar import (FRIDAY, MONDAY, MarketCalendar, THURSDAY, TUESDAY, WEDNESDAY)
11
11
 
12
12
  # New Year's Eve
13
13
  EUREXNewYearsEve = Holiday(
@@ -6,9 +6,9 @@ from pandas.tseries.holiday import AbstractHolidayCalendar, EasterMonday, GoodFr
6
6
  from pandas.tseries.offsets import LastWeekOfMonth, WeekOfMonth
7
7
  from pytz import timezone
8
8
 
9
- from pandas_market_calendars.holidays_us import USNewYearsDay
10
- from .holidays_cn import bsd_mapping, dbf_mapping, dnf_mapping, maf_mapping, sf_mapping, tsd_mapping
11
- from .market_calendar import MarketCalendar
9
+ from pandas_market_calendars.holidays.us import USNewYearsDay
10
+ from pandas_market_calendars.holidays.cn import bsd_mapping, dbf_mapping, dnf_mapping, maf_mapping, sf_mapping, tsd_mapping
11
+ from pandas_market_calendars.market_calendar import MarketCalendar
12
12
 
13
13
 
14
14
  def process_date(dt, mapping=None, func=None, delta=None, offset=None):
@@ -5,9 +5,9 @@ from pandas import Timestamp
5
5
  from pandas.tseries.holiday import AbstractHolidayCalendar, GoodFriday, USLaborDay, USPresidentsDay, USThanksgivingDay
6
6
  from pytz import timezone
7
7
 
8
- from .holidays_us import (Christmas, USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay,
9
- USNationalDaysofMourning, USNewYearsDay)
10
- from .market_calendar import MarketCalendar
8
+ from pandas_market_calendars.holidays.us import (Christmas, USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay,
9
+ USNationalDaysofMourning, USNewYearsDay)
10
+ from pandas_market_calendars.market_calendar import MarketCalendar
11
11
 
12
12
 
13
13
  class ICEExchangeCalendar(MarketCalendar):
@@ -1,10 +1,10 @@
1
1
  from datetime import time
2
2
  from itertools import chain
3
- from .exchange_calendar_nyse import NYSEExchangeCalendar
3
+ from .nyse import NYSEExchangeCalendar
4
4
  from pandas.tseries.holiday import AbstractHolidayCalendar
5
5
  from pytz import timezone
6
6
 
7
- from pandas_market_calendars.holidays_nyse import (
7
+ from pandas_market_calendars.holidays.nyse import (
8
8
  USPresidentsDay,
9
9
  GoodFriday,
10
10
  USMemorialDay,
@@ -4,9 +4,9 @@ from itertools import chain
4
4
  from pandas.tseries.holiday import AbstractHolidayCalendar
5
5
  from pytz import timezone
6
6
 
7
- from pandas_market_calendars.holidays_jp import *
8
- from pandas_market_calendars.holidays_us import USNewYearsDay
9
- from .market_calendar import MarketCalendar
7
+ from pandas_market_calendars.holidays.jp import *
8
+ from pandas_market_calendars.holidays.us import USNewYearsDay
9
+ from pandas_market_calendars.market_calendar import MarketCalendar
10
10
 
11
11
 
12
12
  # TODO:
@@ -18,13 +18,13 @@ from datetime import time
18
18
  from pandas.tseries.holiday import AbstractHolidayCalendar, EasterMonday, GoodFriday
19
19
  from pytz import timezone
20
20
 
21
- from .holidays_uk import (
21
+ from pandas_market_calendars.holidays.uk import (
22
22
  BoxingDay, Christmas, ChristmasEve, LSENewYearsDay, LSENewYearsEve,
23
23
  MayBank_pre_1995, MayBank_post_1995_pre_2020, MayBank_post_2020,
24
24
  SpringBank_pre_2002, SpringBank_post_2002_pre_2012, SpringBank_post_2012_pre_2022, SpringBank_post_2022,
25
25
  SummerBank, WeekendBoxingDay, WeekendChristmas, UniqueCloses,
26
26
  )
27
- from .market_calendar import MarketCalendar
27
+ from pandas_market_calendars.market_calendar import MarketCalendar
28
28
 
29
29
 
30
30
  class LSEExchangeCalendar(MarketCalendar):
@@ -4,7 +4,7 @@ Imported calendars from the exchange_calendars project
4
4
  GitHub: https://github.com/gerrymanoim/exchange_calendars
5
5
  """
6
6
 
7
- from .market_calendar import MarketCalendar
7
+ from pandas_market_calendars.market_calendar import MarketCalendar
8
8
  import exchange_calendars
9
9
 
10
10
 
@@ -106,7 +106,7 @@ for exchange in calendars:
106
106
  cal = type(exchange, (TradingCalendar,), {'_ec_class': calendars[exchange],
107
107
  'alias': [exchange],
108
108
  'regular_market_times': regular_market_times})
109
- locals()[exchange + 'ExchangeCalendar'] = cal
109
+ locals()[f'{exchange}ExchangeCalendar'] = cal
110
110
 
111
111
 
112
112
 
@@ -20,7 +20,7 @@ import pandas as pd
20
20
  from pandas.tseries.holiday import AbstractHolidayCalendar
21
21
  from pytz import timezone
22
22
 
23
- from pandas_market_calendars.holidays_nyse import (
23
+ from pandas_market_calendars.holidays.nyse import (
24
24
  # Always Celebrated Holidays
25
25
  USNewYearsDayNYSEpost1952, USNewYearsDayNYSEpre1952, SatBeforeNewYearsAdhoc,
26
26
 
@@ -244,7 +244,7 @@ from pandas_market_calendars.holidays_nyse import (
244
244
  # 2018
245
245
  GeorgeHWBushDeath2018
246
246
  )
247
- from .market_calendar import MarketCalendar
247
+ from pandas_market_calendars.market_calendar import MarketCalendar
248
248
 
249
249
  # Useful resources for making changes to this file:
250
250
  # http://www.nyse.com/pdfs/closings.pdf
@@ -4,7 +4,7 @@ from pandas.tseries.holiday import AbstractHolidayCalendar, EasterMonday, GoodFr
4
4
  from pandas.tseries.offsets import Day, Easter
5
5
  from pytz import timezone
6
6
 
7
- from .market_calendar import MarketCalendar
7
+ from pandas_market_calendars.market_calendar import MarketCalendar
8
8
 
9
9
  OSENewYearsDay = Holiday(
10
10
  "New Year's Day",
@@ -3,8 +3,6 @@ from datetime import time
3
3
  from pandas.tseries.holiday import AbstractHolidayCalendar
4
4
  from pytz import timezone
5
5
  from itertools import chain
6
- import pandas as pd
7
-
8
6
 
9
7
  ########################################################################################################################
10
8
  # SIFMA Financial Markets Calendar for US, UK, JP
@@ -22,9 +20,8 @@ import pandas as pd
22
20
  ########################################################################################################################
23
21
 
24
22
 
25
- from pandas_market_calendars.holidays_sifma import(
23
+ from pandas_market_calendars.holidays.sifma import(
26
24
  # US Holidays
27
- UKWeekendBoxingDay,
28
25
  USNewYearsDay, # Not observed if a Saturday
29
26
  USNewYearsEve2pmEarlyClose,
30
27
 
@@ -71,7 +68,7 @@ from pandas_market_calendars.holidays_sifma import(
71
68
  UKPlatinumJubilee2022,
72
69
  )
73
70
 
74
- from .market_calendar import MarketCalendar
71
+ from pandas_market_calendars.market_calendar import MarketCalendar
75
72
 
76
73
  #AbstractHolidayCalendar.start_date = '1998-01-01'
77
74
 
@@ -214,11 +211,11 @@ class SIFMAUKExchangeCalendar(MarketCalendar):
214
211
  ############################################################
215
212
  # Japan
216
213
  ############################################################
217
- from .holidays_jp import (JapanComingOfAgeDay, JapanNationalFoundationDay,JapanEmperorsBirthday, JapanVernalEquinox,JapanShowaDay,
218
- JapanConstitutionMemorialDay, JapanGreeneryDay, JapanChildrensDay, JapanMarineDay, JapanMountainDay,
219
- JapanRespectForTheAgedDay, JapanAutumnalEquinox,
220
- JapanHealthAndSportsDay2000To2019, JapanSportsDay2020, JapanSportsDay,
221
- JapanCultureDay, JapanLaborThanksgivingDay)
214
+ from pandas_market_calendars.holidays.jp import (JapanComingOfAgeDay, JapanNationalFoundationDay, JapanEmperorsBirthday, JapanVernalEquinox, JapanShowaDay,
215
+ JapanConstitutionMemorialDay, JapanGreeneryDay, JapanChildrensDay, JapanMarineDay, JapanMountainDay,
216
+ JapanRespectForTheAgedDay, JapanAutumnalEquinox,
217
+ JapanHealthAndSportsDay2000To2019, JapanSportsDay2020, JapanSportsDay,
218
+ JapanCultureDay, JapanLaborThanksgivingDay)
222
219
 
223
220
  class SIFMAJPExchangeCalendar(MarketCalendar):
224
221
  """
@@ -4,7 +4,7 @@ from pandas.tseries.holiday import (AbstractHolidayCalendar, Day, Easter, Easter
4
4
  previous_friday)
5
5
  from pytz import timezone
6
6
 
7
- from .market_calendar import (FRIDAY, MONDAY, MarketCalendar, THURSDAY, TUESDAY, WEDNESDAY)
7
+ from pandas_market_calendars.market_calendar import (FRIDAY, MONDAY, MarketCalendar, THURSDAY, TUESDAY, WEDNESDAY)
8
8
 
9
9
  # New Year's Eve
10
10
  NewYearsEve = Holiday(
@@ -4,8 +4,8 @@ from functools import partial
4
4
  from pandas.tseries.holiday import AbstractHolidayCalendar, Holiday, next_monday
5
5
  from pytz import timezone
6
6
 
7
- from .holidays_cn import *
8
- from .market_calendar import MarketCalendar
7
+ from pandas_market_calendars.holidays.cn import *
8
+ from pandas_market_calendars.market_calendar import MarketCalendar
9
9
 
10
10
 
11
11
  class SSEExchangeCalendar(MarketCalendar):
@@ -1,7 +1,7 @@
1
1
  from datetime import time
2
2
  from pandas import Timestamp
3
3
  from pytz import timezone
4
- from .market_calendar import MarketCalendar
4
+ from pandas_market_calendars.market_calendar import MarketCalendar
5
5
 
6
6
  TASEClosedDay = [
7
7
  # 2019
@@ -5,8 +5,8 @@ from pandas.tseries.holiday import AbstractHolidayCalendar, DateOffset, GoodFrid
5
5
  from pytz import timezone
6
6
  from itertools import chain
7
7
 
8
- from .holidays_uk import BoxingDay, WeekendBoxingDay, WeekendChristmas
9
- from .market_calendar import MarketCalendar, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY
8
+ from pandas_market_calendars.holidays.uk import BoxingDay, WeekendBoxingDay, WeekendChristmas
9
+ from pandas_market_calendars.market_calendar import MarketCalendar, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY
10
10
 
11
11
  # New Year's Day
12
12
  TSXNewYearsDay = Holiday(
File without changes
@@ -1,7 +1,6 @@
1
1
  import datetime
2
2
 
3
- from dateutil.relativedelta import (MO, FR)
4
- from dateutil.relativedelta import (TH)
3
+ from dateutil.relativedelta import (MO, TH, FR)
5
4
  from pandas import (DateOffset, Timestamp)
6
5
  from pandas.tseries.holiday import (Holiday, Easter)
7
6
  from pandas.tseries.holiday import (nearest_workday)
@@ -213,11 +212,11 @@ USIndependenceDayAfter2014 = Holiday(
213
212
  start_date=Timestamp('2014-01-01'),
214
213
  observance=nearest_workday,)
215
214
 
216
- # Necessary for equities
215
+ # Necessary for equities and crypto
217
216
  def previous_workday_if_july_4th_is_tue_to_fri(dt):
218
217
  july4th = datetime.datetime(dt.year, 7, 4)
219
218
  if july4th.weekday() in (1, 2, 3, 4):
220
- return july4th - datetime.timedelta(days= 1)
219
+ return july4th - datetime.timedelta(days=1)
221
220
  # else None
222
221
 
223
222
  USIndependenceDayBefore2022PreviousDay = Holiday(
@@ -26,7 +26,7 @@ USNewYearsDay = Holiday(
26
26
  # Martin Luther King Jr.
27
27
  # Starting 1998
28
28
  ##########################################################################
29
- USMartinLutherKingJrFrom2022 = Holiday( # Early Close 1:30pm
29
+ USMartinLutherKingJrFrom2022 = Holiday(
30
30
  'Dr. Martin Luther King Jr. Day',
31
31
  month=1,
32
32
  day=1,
@@ -35,7 +35,7 @@ USMartinLutherKingJrFrom2022 = Holiday( # Early Close 1:30pm
35
35
  offset=DateOffset(weekday=MO(3)),
36
36
  )
37
37
 
38
- USMartinLutherKingJrPre2022 = Holiday( # Early Close 12:00pm
38
+ USMartinLutherKingJrPre2022 = Holiday(
39
39
  'Dr. Martin Luther King Jr. Day',
40
40
  month=1,
41
41
  day=1,
@@ -48,12 +48,12 @@ USMartinLutherKingJrPre2022 = Holiday( # Early Close 12:00pm
48
48
  #########################################################################
49
49
  # US Presidents Day Feb
50
50
  ##########################################################################
51
- USPresidentsDayFrom2022 = Holiday('President''s Day', # 1:30pm Early Close
51
+ USPresidentsDayFrom2022 = Holiday('President''s Day',
52
52
  start_date=Timestamp('2022-01-01'),
53
53
  month=2, day=1,
54
54
  offset=DateOffset(weekday=MO(3)))
55
55
 
56
- USPresidentsDayPre2022 = Holiday('President''s Day', # 12:00pm Early Close
56
+ USPresidentsDayPre2022 = Holiday('President''s Day',
57
57
  end_date=Timestamp('2021-12-31'),
58
58
  month=2, day=1,
59
59
  offset=DateOffset(weekday=MO(3)))
@@ -74,7 +74,7 @@ GoodFriday = Holiday(
74
74
  ##################################################
75
75
  # US Memorial Day (Decoration Day) May 30
76
76
  ##################################################
77
- USMemorialDayFrom2022 = Holiday( # 1:30pm early close
77
+ USMemorialDayFrom2022 = Holiday(
78
78
  'Memorial Day',
79
79
  month=5,
80
80
  day=25,
@@ -82,7 +82,7 @@ USMemorialDayFrom2022 = Holiday( # 1:30pm early close
82
82
  offset=DateOffset(weekday=MO(1)),
83
83
  )
84
84
 
85
- USMemorialDayPre2022 = Holiday( # 12:00pm early close
85
+ USMemorialDayPre2022 = Holiday(
86
86
  'Memorial Day',
87
87
  month=5,
88
88
  day=25,
@@ -122,6 +122,20 @@ USIndependenceDayPre2022 = Holiday(
122
122
  #################################################
123
123
  # US Labor Day Starting 1887
124
124
  #################################################
125
+ USLaborDayFrom2022 = Holiday(
126
+ 'Labor Day',
127
+ month=9,
128
+ day=1,
129
+ start_date=Timestamp('2022-01-01'),
130
+ offset=DateOffset(weekday=MO(1)),
131
+ )
132
+ USLaborDayPre2022 = Holiday(
133
+ 'Labor Day',
134
+ month=9,
135
+ day=1,
136
+ end_date=Timestamp('2021-12-31'),
137
+ offset=DateOffset(weekday=MO(1)),
138
+ )
125
139
  USLaborDay = Holiday(
126
140
  "Labor Day",
127
141
  month=9,
@@ -155,6 +169,21 @@ FridayAfterThanksgiving = Holiday(
155
169
  offset=[DateOffset(weekday=TH(4)), Day(1)],
156
170
  )
157
171
 
172
+ USThanksgivingFridayFrom2021 = Holiday(
173
+ 'Thanksgiving Friday',
174
+ month=11,
175
+ day=1,
176
+ offset=[DateOffset(weekday=TH(4)), Day(1)],
177
+ start_date=Timestamp('2021-01-01'),
178
+ )
179
+
180
+ USThanksgivingFridayPre2021 = Holiday(
181
+ 'Thanksgiving Friday',
182
+ month=11,
183
+ day=1,
184
+ offset=[DateOffset(weekday=TH(4)), Day(1)],
185
+ end_date=Timestamp('2020-12-31'),
186
+ )
158
187
 
159
188
  ################################
160
189
  # Christmas Dec 25
@@ -2,7 +2,7 @@ from dateutil.relativedelta import MO
2
2
  from pandas import DateOffset, Timestamp
3
3
  from pandas.tseries.holiday import Holiday, sunday_to_monday
4
4
 
5
- from pandas_market_calendars.jpx_equinox import autumnal_citizen_dates, autumnal_equinox, vernal_equinox
5
+ from pandas_market_calendars.holidays.jpx_equinox import autumnal_citizen_dates, autumnal_equinox, vernal_equinox
6
6
 
7
7
  AscensionDays = [
8
8
  Timestamp('2019-04-30', tz='UTC'), # National Holiday
@@ -1,3 +1,4 @@
1
+ import pandas as pd
1
2
  from dateutil.relativedelta import (MO, TH, TU)
2
3
  from pandas import (DateOffset, Timestamp, date_range)
3
4
  from datetime import timedelta
@@ -10,7 +11,7 @@ from pandas_market_calendars.market_calendar import ( MONDAY, TUESDAY, WEDNESDAY
10
11
  # main reference:
11
12
  # https://github.com/rsheftel/pandas_market_calendars/files/6827110/Stocks.NYSE-Closings.pdf
12
13
  #
13
- # See exchange_calendar_nyse.py for details
14
+ # See nyse.py for details
14
15
  #################################################################################################
15
16
 
16
17
  def previous_saturday(dt):
@@ -302,9 +303,6 @@ MonTuesThursBeforeIndependenceDay = Holiday(
302
303
  start_date=Timestamp("1995-01-01"),
303
304
  )
304
305
 
305
- def july_5th_holiday_observance(datetime_index):
306
- return datetime_index[datetime_index.year < 2013]
307
-
308
306
  FridayAfterIndependenceDayNYSEpre2013 = Holiday(
309
307
  # When July 4th is a Thursday, the next day is a half day prior to 2013.
310
308
  # Since 2013 the early close is on Wednesday and Friday is a full day
@@ -312,8 +310,8 @@ FridayAfterIndependenceDayNYSEpre2013 = Holiday(
312
310
  month=7,
313
311
  day=5,
314
312
  days_of_week=(FRIDAY,),
315
- observance=july_5th_holiday_observance,
316
313
  start_date=Timestamp("1996-01-01"),
314
+ end_date=Timestamp("2012-12-31"),
317
315
  )
318
316
 
319
317
  WednesdayBeforeIndependenceDayPost2013 = Holiday(
@@ -10,10 +10,6 @@ from pandas_market_calendars.market_calendar import (FRIDAY, MONDAY, THURSDAY, T
10
10
  # NYSE closed at 2:00 PM on Christmas Eve until 1993.
11
11
 
12
12
 
13
- def july_5th_holiday_observance(datetime_index):
14
- return datetime_index[datetime_index.year < 2013]
15
-
16
-
17
13
  def following_tuesday_every_four_years_observance(dt):
18
14
  return dt + DateOffset(years=(4 - (dt.year % 4)) % 4, weekday=TU(1))
19
15
 
@@ -201,8 +197,8 @@ FridayAfterIndependenceDayPre2013 = Holiday(
201
197
  month=7,
202
198
  day=5,
203
199
  days_of_week=(FRIDAY,),
204
- observance=july_5th_holiday_observance,
205
200
  start_date=Timestamp("1995-01-01"),
201
+ end_date=Timestamp("2012-12-31"),
206
202
  )
207
203
  WednesdayBeforeIndependenceDayPost2013 = Holiday(
208
204
  # When July 4th is a Thursday, the next day is a half day prior to 2013.
@@ -421,17 +421,41 @@ class MarketCalendar(metaclass=MarketCalendarMeta):
421
421
  """
422
422
  return []
423
423
 
424
- def _convert(self, col):
424
+ def _convert(self, col: pd.Series):
425
+ """
426
+ col is a series indexed by dates at which interruptions occurred. The values are either the start or end times
427
+ of an interruption, represented by either a timedelta or a tuple with a timedelta and day offset of the form
428
+ (timedelta, offset). _convert produces a new series where the values are replaced by datetimes equal to the
429
+ index of the original series plus the offset if present, at the timedelta.
430
+
431
+ E.g.:
432
+ >>> self._convert(
433
+ pd.Series(
434
+ [datetime.time(11, 2), (datetime.time(11, 1), 1), datetime.time(10, 0), None],
435
+ index=pd.DatetimeIndex(['2002-02-03', '2010-01-11', '2010-01-13', '2011-01-10'])
436
+ )
437
+ )
438
+ 2002-02-03 2002-02-03 11:02:00+00:00
439
+ 2010-01-11 2010-01-12 11:01:00+00:00
440
+ 2010-01-13 2010-01-13 10:00:00+00:00
441
+ 2011-01-10 NaT
442
+ dtype: datetime64[ns, UTC]
443
+ """
444
+ col = col.dropna() # Python 3.8, pandas 2.0.3 cannot create time deltas from NaT
425
445
  try: times = col.str[0]
426
446
  except AttributeError: # no tuples, only offset 0
427
- return (pd.to_timedelta(col.astype("string"), errors="coerce") + col.index
447
+ return (pd.to_timedelta(col.astype("string").fillna(""), errors="coerce") + col.index
428
448
  ).dt.tz_localize(self.tz).dt.tz_convert("UTC")
429
449
 
430
- return (pd.to_timedelta(times.fillna(col).astype("string"), errors="coerce"
450
+ return (pd.to_timedelta(times.fillna(col).astype("string").fillna(""), errors="coerce"
431
451
  ) + pd.to_timedelta(col.str[1].fillna(0), unit="D"
432
452
  ) + col.index
433
453
  ).dt.tz_localize(self.tz).dt.tz_convert("UTC")
434
454
 
455
+ @staticmethod
456
+ def _col_name(n: int):
457
+ return f"interruption_start_{n // 2 + 1}" if n % 2 == 1 else f"interruption_end_{n // 2}"
458
+
435
459
  @property
436
460
  def interruptions_df(self):
437
461
  """
@@ -441,12 +465,7 @@ class MarketCalendar(metaclass=MarketCalendarMeta):
441
465
  intr = pd.DataFrame(self.interruptions)
442
466
  intr.index = pd.to_datetime(intr.pop(0))
443
467
 
444
- columns = []
445
- for i in range(1, intr.shape[1] // 2 + 1):
446
- i = str(i)
447
- columns.append("interruption_start_" + i)
448
- columns.append("interruption_end_" + i)
449
- intr.columns = columns
468
+ intr.columns = map(self._col_name, intr.columns)
450
469
  intr.index.name = None
451
470
 
452
471
  return intr.apply(self._convert).sort_index()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pandas-market-calendars
3
- Version: 4.2.1
3
+ Version: 4.3.1
4
4
  Summary: Market and exchange trading calendars for pandas
5
5
  Author-email: Ryan Sheftel <rsheftel@alumni.upenn.edu>
6
6
  License: MIT
@@ -36,16 +36,13 @@ Market calendars to use with pandas for trading applications.
36
36
  .. image:: https://badge.fury.io/py/pandas-market-calendars.svg
37
37
  :target: https://badge.fury.io/py/pandas-market-calendars
38
38
 
39
- .. image:: https://travis-ci.com/rsheftel/pandas_market_calendars.svg?branch=master
40
- :target: https://travis-ci.com/rsheftel/pandas_market_calendars
41
-
42
- .. image:: https://coveralls.io/repos/github/rsheftel/pandas_market_calendars/badge.svg?branch=master
43
- :target: https://coveralls.io/github/rsheftel/pandas_market_calendars?branch=master
44
-
45
39
  .. image:: https://readthedocs.org/projects/pandas-market-calendars/badge/?version=latest
46
40
  :target: http://pandas-market-calendars.readthedocs.io/en/latest/?badge=latest
47
41
  :alt: Documentation Status
48
42
 
43
+ .. image:: https://coveralls.io/repos/github/rsheftel/pandas_market_calendars/badge.svg?branch=master
44
+ :target: https://coveralls.io/github/rsheftel/pandas_market_calendars?branch=master
45
+
49
46
  Documentation
50
47
  -------------
51
48
  http://pandas-market-calendars.readthedocs.io/en/latest/
@@ -0,0 +1,49 @@
1
+ pandas_market_calendars/__init__.py,sha256=VWaAauLacIGTUKHa1_3i86emgSWyMubJaYm8gThrNWs,1321
2
+ pandas_market_calendars/calendar_registry.py,sha256=NM-nFGUIcc_UEX7MHjGtjVJlocX4GZxQ5WLtdREqFmA,2317
3
+ pandas_market_calendars/calendar_utils.py,sha256=tN21REa6VNXWin7T-oIQu4lMBsz1912pwfwpwHCdtzU,11132
4
+ pandas_market_calendars/class_registry.py,sha256=qwlWwUagxZxco-ER3VeNSCyd7wKnrycucYAbuYvj9hQ,3780
5
+ pandas_market_calendars/market_calendar.py,sha256=1ob9YdXN-iUB07xF6oaCYUOxCcRiKimDDR2751HVBuA,32129
6
+ pandas_market_calendars/calendars/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ pandas_market_calendars/calendars/asx.py,sha256=OQVfEqHppeQe1x7k-9y2Jaqed5Cy7r09L1vLMdfn09c,1533
8
+ pandas_market_calendars/calendars/bmf.py,sha256=9_zHmRUSFnfUkJmlaKBYdwOlCjv42EqQaHPATcw3_h0,5380
9
+ pandas_market_calendars/calendars/bse.py,sha256=IcHN9G2ZV4HJkCooDPhLtOscWv4HAiZu8HJfG9kiw_0,16115
10
+ pandas_market_calendars/calendars/cboe.py,sha256=z2AOHFicermv2DvbC5F5o-nm-S6OYkF1fGOwlRAECEE,3544
11
+ pandas_market_calendars/calendars/cme.py,sha256=7gGr3QyOjZL2N7tDu1DCzzKhvEsLISF_-svjDPIyQBg,9501
12
+ pandas_market_calendars/calendars/cme_globex_agriculture.py,sha256=AZBncalV62HhyRDNejqZg6UphuYz_e7CwxaGPPZOPD4,3065
13
+ pandas_market_calendars/calendars/cme_globex_base.py,sha256=BjAerRmNcH8o21I4huUIjcMeHI68jobmDiVFgZ3wSA4,2903
14
+ pandas_market_calendars/calendars/cme_globex_crypto.py,sha256=UVgdfXKbmnY3h9KZ7YbnbLdb2MgmU8jJWNllJFXgfeA,5105
15
+ pandas_market_calendars/calendars/cme_globex_energy_and_metals.py,sha256=aXBNjC2Lt4bGBfZHeIed622g4hWkcDXeJCKEgPny7rI,6302
16
+ pandas_market_calendars/calendars/cme_globex_equities.py,sha256=wEJtJYllsPOSwefIktZNjgYfgVmT_3tOtaIL0_7U72M,2999
17
+ pandas_market_calendars/calendars/cme_globex_fixed_income.py,sha256=mBTd-i1g10eHfrULzfyMe0i29y8I8EXYvT9QzCI9wcQ,3591
18
+ pandas_market_calendars/calendars/cme_globex_fx.py,sha256=So7GpiqbGbsmdtb196ReMs9SqeTkzXHUzaZvAt-sgGE,2736
19
+ pandas_market_calendars/calendars/eurex.py,sha256=iPoRQUyHpzFISb4kX8iBJADF6WfTd0gZW6K8WmQ9MZI,2705
20
+ pandas_market_calendars/calendars/hkex.py,sha256=nbPfgLYIXfvmM8enT_m9g4jKewTCntBHjcGK_klQO9A,13576
21
+ pandas_market_calendars/calendars/ice.py,sha256=LvCYi4IsNTPEphfmJ0hvuKZO0R4Oq2dC1tvAg4re15E,2014
22
+ pandas_market_calendars/calendars/iex.py,sha256=tO8lBg8XPpogshdg7pJ8wasToxfVtSHKWhGW4y8FBio,2795
23
+ pandas_market_calendars/calendars/jpx.py,sha256=EBXTECZ8xE_vbHtN9nVsZWi1ANe3h0Vaf69HA5PwWQ8,3318
24
+ pandas_market_calendars/calendars/lse.py,sha256=VUeTwmQ_zhSAidfRxeveFqEC6SOlX7zbFMI7iChLg8o,2821
25
+ pandas_market_calendars/calendars/mirror.py,sha256=QZCVh6ioB0cgtfdD8wvt4ADQqZj8eYR-GM5nSAn_b7E,3766
26
+ pandas_market_calendars/calendars/nyse.py,sha256=8_FpG_-GCcoPMuU9Ekq6yKZ7IRxmcJIF35ATU7h7P-w,56829
27
+ pandas_market_calendars/calendars/ose.py,sha256=NGErVNagOWC-FZSHMIs4ltDurr85H1B3yjRU8f2gpIs,2980
28
+ pandas_market_calendars/calendars/sifma.py,sha256=7owyA_I6aZvLJbTA_W1gE6VcloQmrwjWz4PWaPpnfGk,8603
29
+ pandas_market_calendars/calendars/six.py,sha256=fjcquUwCnUABNGJkK95C1RR80PkdZf6CQSDi_mBbYu8,2511
30
+ pandas_market_calendars/calendars/sse.py,sha256=oEJGRz-IK1I_qnGI8uxyQTgUPfUxqkac3nOdhzRc23s,9680
31
+ pandas_market_calendars/calendars/tase.py,sha256=xs4-sUdwvGWSwu3cHvaEWHlF68O2gHdbX0Pd96jucPQ,7827
32
+ pandas_market_calendars/calendars/tsx.py,sha256=JnTKs2hdEb2XStS9Bzq6J84IC-VlYtOyoef9pAnW9uw,3833
33
+ pandas_market_calendars/holidays/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
+ pandas_market_calendars/holidays/cme.py,sha256=d5_hJA7bGbDmYfv70vf2RvSPRpy58EHdYONyh7Y_y5w,8730
35
+ pandas_market_calendars/holidays/cme_globex.py,sha256=DIapJPayIgL7GofmPrp3u9LkKerIgcGo0n1907NvbVQ,5103
36
+ pandas_market_calendars/holidays/cn.py,sha256=DdVO4LNF7TbcRhrcYTcsO3AJj2WZTOaa7s34LSFhCiU,46188
37
+ pandas_market_calendars/holidays/jp.py,sha256=leuXgWX8RrgIVy9aKtqNY7YDDyKjbAh4ZWEMp50dEjs,9195
38
+ pandas_market_calendars/holidays/jpx_equinox.py,sha256=Pn5Y-vDrSNhGaMhK0yrIxDAmn0POAOQgJnlAkBWvego,6611
39
+ pandas_market_calendars/holidays/nyse.py,sha256=dfgGV3XhgHwVdZ00m4P2VKcbUarc0QQEkEEdplSUat8,41034
40
+ pandas_market_calendars/holidays/oz.py,sha256=dlxuHe4h6pffkHvbmhGGQM4HS-xZ0qOWdRJULq7r2Tw,1044
41
+ pandas_market_calendars/holidays/sifma.py,sha256=PbDTZRsWyOXTvgL67ZIeHZeHPx7tExYumxBnCIaa0bk,8437
42
+ pandas_market_calendars/holidays/uk.py,sha256=rrGRPsV8V3Bc4r85tudG2Gtj3JhodNuRXSPlCflFOs4,4712
43
+ pandas_market_calendars/holidays/us.py,sha256=n-hjFcSWo0AnNkkxzIQ5kEwUjeYwFM8Bml2lC9R2KBo,12314
44
+ pandas_market_calendars-4.3.1.dist-info/LICENSE,sha256=qW51_A-I7YutlB-s8VSKeOP-aL83T-Lb8LqqU1x1ilw,1065
45
+ pandas_market_calendars-4.3.1.dist-info/METADATA,sha256=3aO6hTGfzksxxWJoPdyzkFB6WRqdiyJWOykrNKOsYgc,8929
46
+ pandas_market_calendars-4.3.1.dist-info/NOTICE,sha256=mmH7c9aF5FsELh1OHXloXw1TajLD_mWDKO4dsVf43_E,11693
47
+ pandas_market_calendars-4.3.1.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
48
+ pandas_market_calendars-4.3.1.dist-info/top_level.txt,sha256=_4cUEFr07SuEAzZMT-5p0lJGXxO9imVbEK9_5oqcopQ,24
49
+ pandas_market_calendars-4.3.1.dist-info/RECORD,,
@@ -1,46 +0,0 @@
1
- pandas_market_calendars/__init__.py,sha256=VWaAauLacIGTUKHa1_3i86emgSWyMubJaYm8gThrNWs,1321
2
- pandas_market_calendars/calendar_registry.py,sha256=HVHP2OTEJFgMGRz7ummPZWg5E8T7N_LKqsJxMlBQUOA,2445
3
- pandas_market_calendars/calendar_utils.py,sha256=haGu4E9Cj17uO3IXaVTF6uTSnJbTbOe_TAuKeo7qrVw,11132
4
- pandas_market_calendars/class_registry.py,sha256=qwlWwUagxZxco-ER3VeNSCyd7wKnrycucYAbuYvj9hQ,3780
5
- pandas_market_calendars/exchange_calendar_asx.py,sha256=-T9Rl3Snm5xsi4S6fF1bzqCddFbleBBe-DmRiZmiEK4,1487
6
- pandas_market_calendars/exchange_calendar_bmf.py,sha256=GJbyhwjiK2qKQojbJv2ScW1O8KsJc44qmg3CzxVvwZc,5357
7
- pandas_market_calendars/exchange_calendar_bse.py,sha256=8Kb8yhkJK8Gfj4GZG_5VpwPbgp0sIOWQkcpPhQG6ooU,16092
8
- pandas_market_calendars/exchange_calendar_cboe.py,sha256=DRJo7i5FgSZ3R65kk0dxBRHSL7-RAr0sYChhBuvNIUE,3232
9
- pandas_market_calendars/exchange_calendar_cme.py,sha256=KYFgPJLwrt2F-X3sKA9quh0XK7IZ_4F3jLxbM3IEz_o,9409
10
- pandas_market_calendars/exchange_calendar_cme_globex_agriculture.py,sha256=RKE5v0sx1VeKLmdYHbhumTIEW65XJqqI5myzj7CfZio,3197
11
- pandas_market_calendars/exchange_calendar_cme_globex_base.py,sha256=GVhtP3ITSH3uc-qDAUJn1TmOc4XdlITKLsw7A6uhxiE,2908
12
- pandas_market_calendars/exchange_calendar_cme_globex_energy_and_metals.py,sha256=scyYv6zOT8dowA7TX078B-4srZYoXDFbiybjuuSsouI,6372
13
- pandas_market_calendars/exchange_calendar_cme_globex_equities.py,sha256=aZ1erbrD97rKDaeXd3ZttTzY7nql6NhG9FDy8RuUlB0,3017
14
- pandas_market_calendars/exchange_calendar_cme_globex_fixed_income.py,sha256=Giym8z429WX3Otf6ShyA85GgjUrkDl0h7oo47MxP70M,3635
15
- pandas_market_calendars/exchange_calendar_cme_globex_fx.py,sha256=dUEZGH57SyafFhxT9SaWCIIe9ORvd2LpiCb6x1V2pLM,2744
16
- pandas_market_calendars/exchange_calendar_eurex.py,sha256=bN8vXxnbcuIjXFuAEI9MIuW73q3LoYgZ5-h67TeRXdw,2682
17
- pandas_market_calendars/exchange_calendar_hkex.py,sha256=slOUYwWQBMJVyJb9ZSU8GeOHgGPGO5sqdjf42QonYrs,13530
18
- pandas_market_calendars/exchange_calendar_ice.py,sha256=bYmplGujFAWCrNybUkcP5dbzqRsiBa3ie7P_TBNN8Ug,1945
19
- pandas_market_calendars/exchange_calendar_iex.py,sha256=4vN544I99LMjc3H9bKzW2V-TBTYR1opsqZ08YYKu2k8,2814
20
- pandas_market_calendars/exchange_calendar_jpx.py,sha256=6UOQKiuqNw640jPRiL5fu5a7AyNKwNXkaie_nRp5_Ng,3295
21
- pandas_market_calendars/exchange_calendar_lse.py,sha256=C2Ff02y2eAskQc09Z6NcSWKX4jeSA5NF_ETq3K-XzG8,2775
22
- pandas_market_calendars/exchange_calendar_nyse.py,sha256=-c8MJP2w9f74CfHUVd8uAksM9Px4ThlJtFCoDuc5bxQ,56810
23
- pandas_market_calendars/exchange_calendar_ose.py,sha256=pq3qiD6QTKHTusIn_u3G7Jv_iJQWjsr7gT02sNhLiOs,2957
24
- pandas_market_calendars/exchange_calendar_sifma.py,sha256=6R-BYku9T66mOtXf0k0KsuyZMbUVqWTyOXzVmUdMIH8,8509
25
- pandas_market_calendars/exchange_calendar_six.py,sha256=Er1-qoaQkYH4vUEhW79-6-Ii5HdxtzAs1iulAl4l8gM,2488
26
- pandas_market_calendars/exchange_calendar_sse.py,sha256=B4hvayMCuh3d8g_gZY0PWvvs2UsFqPC8yZUNa6sNS7Q,9634
27
- pandas_market_calendars/exchange_calendar_tase.py,sha256=SllnBukjytoGr03ZZT0_hZSurQ43UyMvYIT6mSnrOfw,7804
28
- pandas_market_calendars/exchange_calendar_tsx.py,sha256=WSzCMy_Q1rgqP-jqQGYS_V7XnUpoG9YET545ryGRz5k,3787
29
- pandas_market_calendars/exchange_calendars_mirror.py,sha256=N5ATeXHwuF9PnPWRDH7qIln2ifUaA3xtRSw431ri9aw,3743
30
- pandas_market_calendars/holidays_cme.py,sha256=ycGjFHuNNttCu-mG6TDG73_khKfoA3lFpKfzuR3KVkg,8756
31
- pandas_market_calendars/holidays_cme_globex.py,sha256=gRbItps-Rnyqa0iP63KbysVaPwI8GNR13-bOZea_7b4,4565
32
- pandas_market_calendars/holidays_cn.py,sha256=DdVO4LNF7TbcRhrcYTcsO3AJj2WZTOaa7s34LSFhCiU,46188
33
- pandas_market_calendars/holidays_jp.py,sha256=sSioKZPk5mQHnlK0B-2cVHKxurFuXPiieRuT_PaQxok,9186
34
- pandas_market_calendars/holidays_nyse.py,sha256=QCXC01Hxsk_NmY77Hj-NKgjW6E0RlEqQ4jDLay5mSYE,41142
35
- pandas_market_calendars/holidays_oz.py,sha256=dlxuHe4h6pffkHvbmhGGQM4HS-xZ0qOWdRJULq7r2Tw,1044
36
- pandas_market_calendars/holidays_sifma.py,sha256=PbDTZRsWyOXTvgL67ZIeHZeHPx7tExYumxBnCIaa0bk,8437
37
- pandas_market_calendars/holidays_uk.py,sha256=rrGRPsV8V3Bc4r85tudG2Gtj3JhodNuRXSPlCflFOs4,4712
38
- pandas_market_calendars/holidays_us.py,sha256=uIujIKo8c0_H5NKm7JDMD5FvvlzcCLNt8NRs5YLydds,12425
39
- pandas_market_calendars/jpx_equinox.py,sha256=Pn5Y-vDrSNhGaMhK0yrIxDAmn0POAOQgJnlAkBWvego,6611
40
- pandas_market_calendars/market_calendar.py,sha256=R43Zz1B7a2dYiJLBxOlt96g08ifCzaSjOAm0Fpz1zeA,31054
41
- pandas_market_calendars-4.2.1.dist-info/LICENSE,sha256=qW51_A-I7YutlB-s8VSKeOP-aL83T-Lb8LqqU1x1ilw,1065
42
- pandas_market_calendars-4.2.1.dist-info/METADATA,sha256=4LCLY4J6IS0aKL--92CSY3kXyV6vZUMNN7qX3Jq6fI8,9085
43
- pandas_market_calendars-4.2.1.dist-info/NOTICE,sha256=mmH7c9aF5FsELh1OHXloXw1TajLD_mWDKO4dsVf43_E,11693
44
- pandas_market_calendars-4.2.1.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
45
- pandas_market_calendars-4.2.1.dist-info/top_level.txt,sha256=_4cUEFr07SuEAzZMT-5p0lJGXxO9imVbEK9_5oqcopQ,24
46
- pandas_market_calendars-4.2.1.dist-info/RECORD,,