pandas-market-calendars 5.1.0__py3-none-any.whl → 5.1.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/__init__.py +39 -39
  2. pandas_market_calendars/calendar_registry.py +57 -57
  3. pandas_market_calendars/calendar_utils.py +1151 -1151
  4. pandas_market_calendars/calendars/asx.py +77 -70
  5. pandas_market_calendars/calendars/bmf.py +226 -219
  6. pandas_market_calendars/calendars/bse.py +432 -425
  7. pandas_market_calendars/calendars/cboe.py +156 -149
  8. pandas_market_calendars/calendars/cme.py +412 -405
  9. pandas_market_calendars/calendars/cme_globex_agriculture.py +172 -172
  10. pandas_market_calendars/calendars/cme_globex_base.py +126 -119
  11. pandas_market_calendars/calendars/cme_globex_crypto.py +165 -158
  12. pandas_market_calendars/calendars/cme_globex_energy_and_metals.py +223 -216
  13. pandas_market_calendars/calendars/cme_globex_equities.py +130 -123
  14. pandas_market_calendars/calendars/cme_globex_fixed_income.py +136 -136
  15. pandas_market_calendars/calendars/cme_globex_fx.py +101 -101
  16. pandas_market_calendars/calendars/eurex.py +138 -131
  17. pandas_market_calendars/calendars/eurex_fixed_income.py +105 -98
  18. pandas_market_calendars/calendars/hkex.py +438 -431
  19. pandas_market_calendars/calendars/ice.py +88 -81
  20. pandas_market_calendars/calendars/iex.py +162 -155
  21. pandas_market_calendars/calendars/jpx.py +124 -117
  22. pandas_market_calendars/calendars/lse.py +125 -118
  23. pandas_market_calendars/calendars/mirror.py +144 -144
  24. pandas_market_calendars/calendars/nyse.py +1472 -1466
  25. pandas_market_calendars/calendars/ose.py +125 -118
  26. pandas_market_calendars/calendars/sifma.py +390 -383
  27. pandas_market_calendars/calendars/six.py +143 -136
  28. pandas_market_calendars/calendars/sse.py +322 -315
  29. pandas_market_calendars/calendars/tase.py +231 -224
  30. pandas_market_calendars/calendars/tsx.py +192 -185
  31. pandas_market_calendars/class_registry.py +115 -115
  32. pandas_market_calendars/holidays/cme.py +385 -385
  33. pandas_market_calendars/holidays/cme_globex.py +214 -214
  34. pandas_market_calendars/holidays/cn.py +1476 -1476
  35. pandas_market_calendars/holidays/jp.py +401 -401
  36. pandas_market_calendars/holidays/jpx_equinox.py +506 -506
  37. pandas_market_calendars/holidays/nyse.py +1536 -1536
  38. pandas_market_calendars/holidays/oz.py +63 -63
  39. pandas_market_calendars/holidays/sifma.py +350 -350
  40. pandas_market_calendars/holidays/us.py +376 -376
  41. pandas_market_calendars/market_calendar.py +1008 -1008
  42. {pandas_market_calendars-5.1.0.dist-info → pandas_market_calendars-5.1.1.dist-info}/METADATA +3 -1
  43. pandas_market_calendars-5.1.1.dist-info/RECORD +50 -0
  44. {pandas_market_calendars-5.1.0.dist-info → pandas_market_calendars-5.1.1.dist-info}/WHEEL +1 -1
  45. pandas_market_calendars-5.1.0.dist-info/RECORD +0 -50
  46. {pandas_market_calendars-5.1.0.dist-info → pandas_market_calendars-5.1.1.dist-info}/licenses/LICENSE +0 -0
  47. {pandas_market_calendars-5.1.0.dist-info → pandas_market_calendars-5.1.1.dist-info}/licenses/NOTICE +0 -0
  48. {pandas_market_calendars-5.1.0.dist-info → pandas_market_calendars-5.1.1.dist-info}/top_level.txt +0 -0
@@ -1,185 +1,192 @@
1
- from datetime import time
2
- from itertools import chain
3
-
4
- import pandas as pd
5
- from pandas.tseries.holiday import (
6
- AbstractHolidayCalendar,
7
- DateOffset,
8
- GoodFriday,
9
- Holiday,
10
- MO,
11
- weekend_to_monday,
12
- )
13
- from zoneinfo import ZoneInfo
14
-
15
- from pandas_market_calendars.holidays.uk import (
16
- BoxingDay,
17
- WeekendBoxingDay,
18
- WeekendChristmas,
19
- )
20
- from pandas_market_calendars.market_calendar import (
21
- MarketCalendar,
22
- MONDAY,
23
- TUESDAY,
24
- WEDNESDAY,
25
- THURSDAY,
26
- FRIDAY,
27
- )
28
-
29
- # New Year's Day
30
- TSXNewYearsDay = Holiday(
31
- "New Year's Day",
32
- month=1,
33
- day=1,
34
- observance=weekend_to_monday,
35
- )
36
- # Ontario Family Day
37
- FamilyDay = Holiday(
38
- "Family Day",
39
- month=2,
40
- day=1,
41
- offset=DateOffset(weekday=MO(3)),
42
- start_date="2008-01-01",
43
- )
44
- # Victoria Day
45
- # https://www.timeanddate.com/holidays/canada/victoria-day
46
- VictoriaDay = Holiday(
47
- "Victoria Day",
48
- month=5,
49
- day=24,
50
- offset=DateOffset(weekday=MO(-1)),
51
- )
52
- # Canada Day
53
- CanadaDay = Holiday(
54
- "Canada Day",
55
- month=7,
56
- day=1,
57
- observance=weekend_to_monday,
58
- )
59
- # Civic Holiday
60
- CivicHoliday = Holiday(
61
- "Civic Holiday",
62
- month=8,
63
- day=1,
64
- offset=DateOffset(weekday=MO(1)),
65
- )
66
- # Labor Day
67
- LaborDay = Holiday(
68
- "Labor Day",
69
- month=9,
70
- day=1,
71
- offset=DateOffset(weekday=MO(1)),
72
- )
73
- # Thanksgiving
74
- Thanksgiving = Holiday(
75
- "Thanksgiving",
76
- month=10,
77
- day=1,
78
- offset=DateOffset(weekday=MO(2)),
79
- )
80
-
81
- Christmas = Holiday(
82
- "Christmas",
83
- month=12,
84
- day=25,
85
- )
86
-
87
- ChristmasEveEarlyClose2010Onwards = Holiday(
88
- "Christmas Eve Early Close",
89
- month=12,
90
- day=24,
91
- days_of_week=(MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY),
92
- start_date=pd.Timestamp("2010-01-01"),
93
- )
94
-
95
- September11Closings2001 = [
96
- pd.Timestamp("2001-09-11", tz="UTC"),
97
- pd.Timestamp("2001-09-12", tz="UTC"),
98
- ]
99
-
100
-
101
- class TSXExchangeCalendar(MarketCalendar):
102
- """
103
- Exchange calendar for the Toronto Stock Exchange
104
-
105
- Open Time: 9:30 AM, EST
106
- Close Time: 4:00 PM, EST
107
-
108
- Regularly-Observed Holidays:
109
- - New Years Day (observed on first business day on/after)
110
- - Family Day (Third Monday in February, starting in 2008)
111
- - Good Friday
112
- - Victoria Day (Monday before May 25th)
113
- - Canada Day (July 1st, observed first business day after)
114
- - Civic Holiday (First Monday in August)
115
- - Labor Day (First Monday in September)
116
- - Thanksgiving (Second Monday in October)
117
- - Christmas Day
118
- - Dec. 26th if Christmas is on a Sunday
119
- - Dec. 27th if Christmas is on a weekend
120
- - Boxing Day
121
- - Dec. 27th if Christmas is on a Sunday
122
- - Dec. 28th if Boxing Day is on a weekend
123
-
124
- Early closes:
125
- - Starting in 2010, if Christmas Eve falls on a weekday, the market
126
- closes at 1:00 pm that day. If it falls on a weekend, there is no
127
- early close.
128
- """
129
-
130
- aliases = ["TSX", "TSXV"]
131
-
132
- regular_market_times = {
133
- "market_open": ((None, time(9, 30)),),
134
- "market_close": ((None, time(16)),),
135
- }
136
-
137
- @property
138
- def name(self):
139
- return "TSX"
140
-
141
- @property
142
- def full_name(self):
143
- return "Toronto Stock Exchange"
144
-
145
- @property
146
- def tz(self):
147
- return ZoneInfo("Canada/Eastern")
148
-
149
- regular_early_close = time(13)
150
-
151
- @property
152
- def regular_holidays(self):
153
- return AbstractHolidayCalendar(
154
- rules=[
155
- TSXNewYearsDay,
156
- FamilyDay,
157
- GoodFriday,
158
- VictoriaDay,
159
- CanadaDay,
160
- CivicHoliday,
161
- LaborDay,
162
- Thanksgiving,
163
- Christmas,
164
- WeekendChristmas,
165
- BoxingDay,
166
- WeekendBoxingDay,
167
- ]
168
- )
169
-
170
- @property
171
- def adhoc_holidays(self):
172
- return list(
173
- chain(
174
- September11Closings2001,
175
- )
176
- )
177
-
178
- @property
179
- def special_closes(self):
180
- return [
181
- (
182
- self.regular_early_close,
183
- AbstractHolidayCalendar([ChristmasEveEarlyClose2010Onwards]),
184
- )
185
- ]
1
+ from datetime import time
2
+ from itertools import chain
3
+
4
+ import pandas as pd
5
+ from pandas.tseries.holiday import (
6
+ AbstractHolidayCalendar,
7
+ DateOffset,
8
+ GoodFriday,
9
+ Holiday,
10
+ MO,
11
+ weekend_to_monday,
12
+ )
13
+ import sys
14
+ # check python versiOn aNd import accordingly
15
+ if sys.version_info >= (3, 9):
16
+ # For Python 3.9 and later, import directly
17
+ from zoneinfo import ZoneInfo
18
+ else:
19
+ # For Python 3.8 and earlier, import from backports
20
+ from backports.zoneinfo import ZoneInfo
21
+
22
+ from pandas_market_calendars.holidays.uk import (
23
+ BoxingDay,
24
+ WeekendBoxingDay,
25
+ WeekendChristmas,
26
+ )
27
+ from pandas_market_calendars.market_calendar import (
28
+ MarketCalendar,
29
+ MONDAY,
30
+ TUESDAY,
31
+ WEDNESDAY,
32
+ THURSDAY,
33
+ FRIDAY,
34
+ )
35
+
36
+ # New Year's Day
37
+ TSXNewYearsDay = Holiday(
38
+ "New Year's Day",
39
+ month=1,
40
+ day=1,
41
+ observance=weekend_to_monday,
42
+ )
43
+ # Ontario Family Day
44
+ FamilyDay = Holiday(
45
+ "Family Day",
46
+ month=2,
47
+ day=1,
48
+ offset=DateOffset(weekday=MO(3)),
49
+ start_date="2008-01-01",
50
+ )
51
+ # Victoria Day
52
+ # https://www.timeanddate.com/holidays/canada/victoria-day
53
+ VictoriaDay = Holiday(
54
+ "Victoria Day",
55
+ month=5,
56
+ day=24,
57
+ offset=DateOffset(weekday=MO(-1)),
58
+ )
59
+ # Canada Day
60
+ CanadaDay = Holiday(
61
+ "Canada Day",
62
+ month=7,
63
+ day=1,
64
+ observance=weekend_to_monday,
65
+ )
66
+ # Civic Holiday
67
+ CivicHoliday = Holiday(
68
+ "Civic Holiday",
69
+ month=8,
70
+ day=1,
71
+ offset=DateOffset(weekday=MO(1)),
72
+ )
73
+ # Labor Day
74
+ LaborDay = Holiday(
75
+ "Labor Day",
76
+ month=9,
77
+ day=1,
78
+ offset=DateOffset(weekday=MO(1)),
79
+ )
80
+ # Thanksgiving
81
+ Thanksgiving = Holiday(
82
+ "Thanksgiving",
83
+ month=10,
84
+ day=1,
85
+ offset=DateOffset(weekday=MO(2)),
86
+ )
87
+
88
+ Christmas = Holiday(
89
+ "Christmas",
90
+ month=12,
91
+ day=25,
92
+ )
93
+
94
+ ChristmasEveEarlyClose2010Onwards = Holiday(
95
+ "Christmas Eve Early Close",
96
+ month=12,
97
+ day=24,
98
+ days_of_week=(MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY),
99
+ start_date=pd.Timestamp("2010-01-01"),
100
+ )
101
+
102
+ September11Closings2001 = [
103
+ pd.Timestamp("2001-09-11", tz="UTC"),
104
+ pd.Timestamp("2001-09-12", tz="UTC"),
105
+ ]
106
+
107
+
108
+ class TSXExchangeCalendar(MarketCalendar):
109
+ """
110
+ Exchange calendar for the Toronto Stock Exchange
111
+
112
+ Open Time: 9:30 AM, EST
113
+ Close Time: 4:00 PM, EST
114
+
115
+ Regularly-Observed Holidays:
116
+ - New Years Day (observed on first business day on/after)
117
+ - Family Day (Third Monday in February, starting in 2008)
118
+ - Good Friday
119
+ - Victoria Day (Monday before May 25th)
120
+ - Canada Day (July 1st, observed first business day after)
121
+ - Civic Holiday (First Monday in August)
122
+ - Labor Day (First Monday in September)
123
+ - Thanksgiving (Second Monday in October)
124
+ - Christmas Day
125
+ - Dec. 26th if Christmas is on a Sunday
126
+ - Dec. 27th if Christmas is on a weekend
127
+ - Boxing Day
128
+ - Dec. 27th if Christmas is on a Sunday
129
+ - Dec. 28th if Boxing Day is on a weekend
130
+
131
+ Early closes:
132
+ - Starting in 2010, if Christmas Eve falls on a weekday, the market
133
+ closes at 1:00 pm that day. If it falls on a weekend, there is no
134
+ early close.
135
+ """
136
+
137
+ aliases = ["TSX", "TSXV"]
138
+
139
+ regular_market_times = {
140
+ "market_open": ((None, time(9, 30)),),
141
+ "market_close": ((None, time(16)),),
142
+ }
143
+
144
+ @property
145
+ def name(self):
146
+ return "TSX"
147
+
148
+ @property
149
+ def full_name(self):
150
+ return "Toronto Stock Exchange"
151
+
152
+ @property
153
+ def tz(self):
154
+ return ZoneInfo("Canada/Eastern")
155
+
156
+ regular_early_close = time(13)
157
+
158
+ @property
159
+ def regular_holidays(self):
160
+ return AbstractHolidayCalendar(
161
+ rules=[
162
+ TSXNewYearsDay,
163
+ FamilyDay,
164
+ GoodFriday,
165
+ VictoriaDay,
166
+ CanadaDay,
167
+ CivicHoliday,
168
+ LaborDay,
169
+ Thanksgiving,
170
+ Christmas,
171
+ WeekendChristmas,
172
+ BoxingDay,
173
+ WeekendBoxingDay,
174
+ ]
175
+ )
176
+
177
+ @property
178
+ def adhoc_holidays(self):
179
+ return list(
180
+ chain(
181
+ September11Closings2001,
182
+ )
183
+ )
184
+
185
+ @property
186
+ def special_closes(self):
187
+ return [
188
+ (
189
+ self.regular_early_close,
190
+ AbstractHolidayCalendar([ChristmasEveEarlyClose2010Onwards]),
191
+ )
192
+ ]
@@ -1,115 +1,115 @@
1
- import inspect
2
- from pprint import pformat
3
-
4
-
5
- def _regmeta_instance_factory(cls, name, *args, **kwargs):
6
- """
7
- :param cls(RegisteryMeta): registration meta class
8
- :param name(str): name of class that needs to be instantiated
9
- :param args(Optional(tuple)): instance positional arguments
10
- :param kwargs(Optional(dict)): instance named arguments
11
- :return: class instance
12
- """
13
- try:
14
- class_ = cls._regmeta_class_registry[name]
15
- except KeyError:
16
- raise RuntimeError(
17
- "Class {} is not one of the registered classes: {}".format(
18
- name, cls._regmeta_class_registry.keys()
19
- )
20
- )
21
- return class_(*args, **kwargs)
22
-
23
-
24
- def _regmeta_register_class(cls, regcls, name):
25
- """
26
- :param cls(RegisteryMeta): registration base class
27
- :param regcls(class): class to be registered
28
- :param name(str): name of the class to be registered
29
- """
30
- if hasattr(regcls, "aliases"):
31
- if regcls.aliases:
32
- for alias in regcls.aliases:
33
- cls._regmeta_class_registry[alias] = regcls
34
- else:
35
- cls._regmeta_class_registry[name] = regcls
36
- else:
37
- cls._regmeta_class_registry[name] = regcls
38
-
39
-
40
- class RegisteryMeta(type):
41
- """
42
- Metaclass used to register all classes inheriting from RegisteryMeta
43
- """
44
-
45
- def __new__(mcs, name, bases, attr):
46
- cls = super(RegisteryMeta, mcs).__new__(mcs, name, bases, attr)
47
- if not hasattr(cls, "_regmeta_class_registry"):
48
- cls._regmeta_class_registry = {}
49
- cls.factory = classmethod(_regmeta_instance_factory)
50
-
51
- return cls
52
-
53
- def __init__(cls, name, bases, attr):
54
- if not inspect.isabstract(cls):
55
- _regmeta_register_class(cls, cls, name)
56
- for b in bases:
57
- if hasattr(b, "_regmeta_class_registry"):
58
- _regmeta_register_class(b, cls, name)
59
-
60
- super(RegisteryMeta, cls).__init__(name, bases, attr)
61
-
62
- cls.regular_market_times = ProtectedDict(cls.regular_market_times)
63
- cls.open_close_map = ProtectedDict(cls.open_close_map)
64
-
65
- cls.special_market_open = cls.special_opens
66
- cls.special_market_open_adhoc = cls.special_opens_adhoc
67
-
68
- cls.special_market_close = cls.special_closes
69
- cls.special_market_close_adhoc = cls.special_closes_adhoc
70
-
71
-
72
- class ProtectedDict(dict):
73
- def __init__(self, *args, **kwargs):
74
- super().__init__(*args, **kwargs)
75
- # __init__ is bypassed when unpickling, which causes __setitem__ to fail
76
- # without the _INIT_RAN_NORMALLY flag
77
- self._INIT_RAN_NORMALLY = True
78
-
79
- def _set(self, key, value):
80
- return super().__setitem__(key, value)
81
-
82
- def _del(self, key):
83
- return super().__delitem__(key)
84
-
85
- def __setitem__(self, key, value):
86
- if not hasattr(self, "_INIT_RAN_NORMALLY"):
87
- return self._set(key, value)
88
-
89
- raise TypeError(
90
- "You cannot set a value directly, you can change regular_market_times "
91
- "using .change_time, .add_time or .remove_time."
92
- )
93
-
94
- def __delitem__(self, key):
95
- if not hasattr(self, "_INIT_RAN_NORMALLY"):
96
- return self._del(key)
97
-
98
- raise TypeError(
99
- "You cannot delete an item directly. You can change regular_market_times "
100
- "using .change_time, .add_time or .remove_time"
101
- )
102
-
103
- def __repr__(self):
104
- return self.__class__.__name__ + "(" + super().__repr__() + ")"
105
-
106
- def __str__(self):
107
- try:
108
- formatted = pformat(dict(self), sort_dicts=False) # sort_dicts apparently not available < python3.8
109
- except TypeError:
110
- formatted = pformat(dict(self))
111
-
112
- return self.__class__.__name__ + "(\n" + formatted + "\n)"
113
-
114
- def copy(self):
115
- return self.__class__(super().copy())
1
+ import inspect
2
+ from pprint import pformat
3
+
4
+
5
+ def _regmeta_instance_factory(cls, name, *args, **kwargs):
6
+ """
7
+ :param cls(RegisteryMeta): registration meta class
8
+ :param name(str): name of class that needs to be instantiated
9
+ :param args(Optional(tuple)): instance positional arguments
10
+ :param kwargs(Optional(dict)): instance named arguments
11
+ :return: class instance
12
+ """
13
+ try:
14
+ class_ = cls._regmeta_class_registry[name]
15
+ except KeyError:
16
+ raise RuntimeError(
17
+ "Class {} is not one of the registered classes: {}".format(
18
+ name, cls._regmeta_class_registry.keys()
19
+ )
20
+ )
21
+ return class_(*args, **kwargs)
22
+
23
+
24
+ def _regmeta_register_class(cls, regcls, name):
25
+ """
26
+ :param cls(RegisteryMeta): registration base class
27
+ :param regcls(class): class to be registered
28
+ :param name(str): name of the class to be registered
29
+ """
30
+ if hasattr(regcls, "aliases"):
31
+ if regcls.aliases:
32
+ for alias in regcls.aliases:
33
+ cls._regmeta_class_registry[alias] = regcls
34
+ else:
35
+ cls._regmeta_class_registry[name] = regcls
36
+ else:
37
+ cls._regmeta_class_registry[name] = regcls
38
+
39
+
40
+ class RegisteryMeta(type):
41
+ """
42
+ Metaclass used to register all classes inheriting from RegisteryMeta
43
+ """
44
+
45
+ def __new__(mcs, name, bases, attr):
46
+ cls = super(RegisteryMeta, mcs).__new__(mcs, name, bases, attr)
47
+ if not hasattr(cls, "_regmeta_class_registry"):
48
+ cls._regmeta_class_registry = {}
49
+ cls.factory = classmethod(_regmeta_instance_factory)
50
+
51
+ return cls
52
+
53
+ def __init__(cls, name, bases, attr):
54
+ if not inspect.isabstract(cls):
55
+ _regmeta_register_class(cls, cls, name)
56
+ for b in bases:
57
+ if hasattr(b, "_regmeta_class_registry"):
58
+ _regmeta_register_class(b, cls, name)
59
+
60
+ super(RegisteryMeta, cls).__init__(name, bases, attr)
61
+
62
+ cls.regular_market_times = ProtectedDict(cls.regular_market_times)
63
+ cls.open_close_map = ProtectedDict(cls.open_close_map)
64
+
65
+ cls.special_market_open = cls.special_opens
66
+ cls.special_market_open_adhoc = cls.special_opens_adhoc
67
+
68
+ cls.special_market_close = cls.special_closes
69
+ cls.special_market_close_adhoc = cls.special_closes_adhoc
70
+
71
+
72
+ class ProtectedDict(dict):
73
+ def __init__(self, *args, **kwargs):
74
+ super().__init__(*args, **kwargs)
75
+ # __init__ is bypassed when unpickling, which causes __setitem__ to fail
76
+ # without the _INIT_RAN_NORMALLY flag
77
+ self._INIT_RAN_NORMALLY = True
78
+
79
+ def _set(self, key, value):
80
+ return super().__setitem__(key, value)
81
+
82
+ def _del(self, key):
83
+ return super().__delitem__(key)
84
+
85
+ def __setitem__(self, key, value):
86
+ if not hasattr(self, "_INIT_RAN_NORMALLY"):
87
+ return self._set(key, value)
88
+
89
+ raise TypeError(
90
+ "You cannot set a value directly, you can change regular_market_times "
91
+ "using .change_time, .add_time or .remove_time."
92
+ )
93
+
94
+ def __delitem__(self, key):
95
+ if not hasattr(self, "_INIT_RAN_NORMALLY"):
96
+ return self._del(key)
97
+
98
+ raise TypeError(
99
+ "You cannot delete an item directly. You can change regular_market_times "
100
+ "using .change_time, .add_time or .remove_time"
101
+ )
102
+
103
+ def __repr__(self):
104
+ return self.__class__.__name__ + "(" + super().__repr__() + ")"
105
+
106
+ def __str__(self):
107
+ try:
108
+ formatted = pformat(dict(self), sort_dicts=False) # sort_dicts apparently not available < python3.8
109
+ except TypeError:
110
+ formatted = pformat(dict(self))
111
+
112
+ return self.__class__.__name__ + "(\n" + formatted + "\n)"
113
+
114
+ def copy(self):
115
+ return self.__class__(super().copy())