pandas-market-calendars 4.3.1__py3-none-any.whl → 4.3.3__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- pandas_market_calendars/__init__.py +38 -37
- pandas_market_calendars/calendar_registry.py +53 -48
- pandas_market_calendars/calendar_utils.py +261 -225
- pandas_market_calendars/calendars/asx.py +66 -63
- pandas_market_calendars/calendars/bmf.py +206 -227
- pandas_market_calendars/calendars/bse.py +407 -409
- pandas_market_calendars/calendars/cboe.py +145 -115
- pandas_market_calendars/calendars/cme.py +402 -240
- pandas_market_calendars/calendars/cme_globex_agriculture.py +126 -103
- pandas_market_calendars/calendars/cme_globex_base.py +119 -103
- pandas_market_calendars/calendars/cme_globex_crypto.py +160 -147
- pandas_market_calendars/calendars/cme_globex_energy_and_metals.py +216 -138
- pandas_market_calendars/calendars/cme_globex_equities.py +123 -104
- pandas_market_calendars/calendars/cme_globex_fixed_income.py +136 -113
- pandas_market_calendars/calendars/cme_globex_fx.py +101 -78
- pandas_market_calendars/calendars/eurex.py +139 -119
- pandas_market_calendars/calendars/eurex_fixed_income.py +98 -0
- pandas_market_calendars/calendars/hkex.py +426 -408
- pandas_market_calendars/calendars/ice.py +81 -65
- pandas_market_calendars/calendars/iex.py +112 -98
- pandas_market_calendars/calendars/jpx.py +109 -103
- pandas_market_calendars/calendars/lse.py +114 -91
- pandas_market_calendars/calendars/mirror.py +130 -114
- pandas_market_calendars/calendars/nyse.py +1324 -1127
- pandas_market_calendars/calendars/ose.py +116 -150
- pandas_market_calendars/calendars/sifma.py +350 -297
- pandas_market_calendars/calendars/six.py +132 -114
- pandas_market_calendars/calendars/sse.py +311 -290
- pandas_market_calendars/calendars/tase.py +197 -195
- pandas_market_calendars/calendars/tsx.py +181 -159
- pandas_market_calendars/class_registry.py +22 -16
- pandas_market_calendars/holidays/cme.py +385 -340
- pandas_market_calendars/holidays/cme_globex.py +214 -198
- pandas_market_calendars/holidays/cn.py +1455 -1436
- pandas_market_calendars/holidays/jp.py +398 -396
- pandas_market_calendars/holidays/jpx_equinox.py +453 -95
- pandas_market_calendars/holidays/nyse.py +1531 -1472
- pandas_market_calendars/holidays/oz.py +63 -65
- pandas_market_calendars/holidays/sifma.py +338 -321
- pandas_market_calendars/holidays/uk.py +32 -26
- pandas_market_calendars/holidays/us.py +376 -360
- pandas_market_calendars/market_calendar.py +895 -789
- {pandas_market_calendars-4.3.1.dist-info → pandas_market_calendars-4.3.3.dist-info}/METADATA +7 -5
- pandas_market_calendars-4.3.3.dist-info/RECORD +50 -0
- {pandas_market_calendars-4.3.1.dist-info → pandas_market_calendars-4.3.3.dist-info}/WHEEL +1 -1
- pandas_market_calendars-4.3.1.dist-info/RECORD +0 -49
- {pandas_market_calendars-4.3.1.dist-info → pandas_market_calendars-4.3.3.dist-info}/LICENSE +0 -0
- {pandas_market_calendars-4.3.1.dist-info → pandas_market_calendars-4.3.3.dist-info}/NOTICE +0 -0
- {pandas_market_calendars-4.3.1.dist-info → pandas_market_calendars-4.3.3.dist-info}/top_level.txt +0 -0
@@ -1,159 +1,181 @@
|
|
1
|
-
from datetime import time
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
from
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
-
|
97
|
-
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
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 pytz import timezone
|
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 tz(self):
|
143
|
+
return timezone("Canada/Eastern")
|
144
|
+
|
145
|
+
regular_early_close = time(13)
|
146
|
+
|
147
|
+
@property
|
148
|
+
def regular_holidays(self):
|
149
|
+
return AbstractHolidayCalendar(
|
150
|
+
rules=[
|
151
|
+
TSXNewYearsDay,
|
152
|
+
FamilyDay,
|
153
|
+
GoodFriday,
|
154
|
+
VictoriaDay,
|
155
|
+
CanadaDay,
|
156
|
+
CivicHoliday,
|
157
|
+
LaborDay,
|
158
|
+
Thanksgiving,
|
159
|
+
Christmas,
|
160
|
+
WeekendChristmas,
|
161
|
+
BoxingDay,
|
162
|
+
WeekendBoxingDay,
|
163
|
+
]
|
164
|
+
)
|
165
|
+
|
166
|
+
@property
|
167
|
+
def adhoc_holidays(self):
|
168
|
+
return list(
|
169
|
+
chain(
|
170
|
+
September11Closings2001,
|
171
|
+
)
|
172
|
+
)
|
173
|
+
|
174
|
+
@property
|
175
|
+
def special_closes(self):
|
176
|
+
return [
|
177
|
+
(
|
178
|
+
self.regular_early_close,
|
179
|
+
AbstractHolidayCalendar([ChristmasEveEarlyClose2010Onwards]),
|
180
|
+
)
|
181
|
+
]
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import inspect
|
2
2
|
from pprint import pformat
|
3
3
|
|
4
|
+
|
4
5
|
def _regmeta_instance_factory(cls, name, *args, **kwargs):
|
5
6
|
"""
|
6
7
|
:param cls(RegisteryMeta): registration meta class
|
@@ -13,16 +14,20 @@ def _regmeta_instance_factory(cls, name, *args, **kwargs):
|
|
13
14
|
class_ = cls._regmeta_class_registry[name]
|
14
15
|
except KeyError:
|
15
16
|
raise RuntimeError(
|
16
|
-
|
17
|
+
"Class {} is not one of the registered classes: {}".format(
|
18
|
+
name, cls._regmeta_class_registry.keys()
|
19
|
+
)
|
20
|
+
)
|
17
21
|
return class_(*args, **kwargs)
|
18
22
|
|
23
|
+
|
19
24
|
def _regmeta_register_class(cls, regcls, name):
|
20
25
|
"""
|
21
26
|
:param cls(RegisteryMeta): registration base class
|
22
27
|
:param regcls(class): class to be registered
|
23
28
|
:param name(str): name of the class to be registered
|
24
29
|
"""
|
25
|
-
if hasattr(regcls,
|
30
|
+
if hasattr(regcls, "aliases"):
|
26
31
|
if regcls.aliases:
|
27
32
|
for alias in regcls.aliases:
|
28
33
|
cls._regmeta_class_registry[alias] = regcls
|
@@ -39,7 +44,7 @@ class RegisteryMeta(type):
|
|
39
44
|
|
40
45
|
def __new__(mcs, name, bases, attr):
|
41
46
|
cls = super(RegisteryMeta, mcs).__new__(mcs, name, bases, attr)
|
42
|
-
if not hasattr(cls,
|
47
|
+
if not hasattr(cls, "_regmeta_class_registry"):
|
43
48
|
cls._regmeta_class_registry = {}
|
44
49
|
cls.factory = classmethod(_regmeta_instance_factory)
|
45
50
|
|
@@ -49,7 +54,7 @@ class RegisteryMeta(type):
|
|
49
54
|
if not inspect.isabstract(cls):
|
50
55
|
_regmeta_register_class(cls, cls, name)
|
51
56
|
for b in bases:
|
52
|
-
if hasattr(b,
|
57
|
+
if hasattr(b, "_regmeta_class_registry"):
|
53
58
|
_regmeta_register_class(b, cls, name)
|
54
59
|
|
55
60
|
super(RegisteryMeta, cls).__init__(name, bases, attr)
|
@@ -65,7 +70,6 @@ class RegisteryMeta(type):
|
|
65
70
|
|
66
71
|
|
67
72
|
class ProtectedDict(dict):
|
68
|
-
|
69
73
|
def __init__(self, *args, **kwargs):
|
70
74
|
super().__init__(*args, **kwargs)
|
71
75
|
# __init__ is bypassed when unpickling, which causes __setitem__ to fail
|
@@ -82,30 +86,32 @@ class ProtectedDict(dict):
|
|
82
86
|
if not hasattr(self, "_INIT_RAN_NORMALLY"):
|
83
87
|
return self._set(key, value)
|
84
88
|
|
85
|
-
raise TypeError(
|
86
|
-
|
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
|
+
)
|
87
93
|
|
88
94
|
def __delitem__(self, key):
|
89
95
|
if not hasattr(self, "_INIT_RAN_NORMALLY"):
|
90
96
|
return self._del(key)
|
91
97
|
|
92
|
-
raise TypeError(
|
93
|
-
|
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
|
+
)
|
94
102
|
|
95
103
|
def __repr__(self):
|
96
|
-
return self.__class__.__name__+ "(" + super().__repr__() + ")"
|
104
|
+
return self.__class__.__name__ + "(" + super().__repr__() + ")"
|
97
105
|
|
98
106
|
def __str__(self):
|
99
107
|
try:
|
100
|
-
formatted = pformat(
|
108
|
+
formatted = pformat(
|
109
|
+
dict(self), sort_dicts=False
|
110
|
+
) # sort_dicts apparently not available < python3.8
|
101
111
|
except TypeError:
|
102
112
|
formatted = pformat(dict(self))
|
103
113
|
|
104
|
-
return self.__class__.__name__+ "(\n" + formatted + "\n)"
|
114
|
+
return self.__class__.__name__ + "(\n" + formatted + "\n)"
|
105
115
|
|
106
116
|
def copy(self):
|
107
117
|
return self.__class__(super().copy())
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|