pandas-market-calendars 4.3.3__py3-none-any.whl → 4.6.0__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 +39 -38
- pandas_market_calendars/calendar_registry.py +57 -53
- pandas_market_calendars/calendar_utils.py +1200 -261
- pandas_market_calendars/calendars/asx.py +66 -66
- pandas_market_calendars/calendars/bmf.py +223 -206
- pandas_market_calendars/calendars/bse.py +421 -407
- pandas_market_calendars/calendars/cboe.py +145 -145
- pandas_market_calendars/calendars/cme.py +405 -402
- pandas_market_calendars/calendars/cme_globex_agriculture.py +172 -126
- pandas_market_calendars/calendars/cme_globex_base.py +119 -119
- pandas_market_calendars/calendars/cme_globex_crypto.py +160 -160
- pandas_market_calendars/calendars/cme_globex_energy_and_metals.py +216 -216
- pandas_market_calendars/calendars/cme_globex_equities.py +123 -123
- pandas_market_calendars/calendars/cme_globex_fixed_income.py +136 -136
- pandas_market_calendars/calendars/cme_globex_fx.py +101 -101
- pandas_market_calendars/calendars/eurex.py +131 -139
- pandas_market_calendars/calendars/eurex_fixed_income.py +98 -98
- pandas_market_calendars/calendars/hkex.py +429 -426
- pandas_market_calendars/calendars/ice.py +81 -81
- pandas_market_calendars/calendars/iex.py +151 -112
- pandas_market_calendars/calendars/jpx.py +113 -109
- pandas_market_calendars/calendars/lse.py +114 -114
- pandas_market_calendars/calendars/mirror.py +149 -130
- pandas_market_calendars/calendars/nyse.py +1466 -1324
- pandas_market_calendars/calendars/ose.py +116 -116
- pandas_market_calendars/calendars/sifma.py +354 -350
- pandas_market_calendars/calendars/six.py +132 -132
- pandas_market_calendars/calendars/sse.py +311 -311
- pandas_market_calendars/calendars/tase.py +220 -197
- pandas_market_calendars/calendars/tsx.py +181 -181
- pandas_market_calendars/holidays/cme.py +385 -385
- pandas_market_calendars/holidays/cme_globex.py +214 -214
- pandas_market_calendars/holidays/cn.py +1476 -1455
- pandas_market_calendars/holidays/jp.py +401 -398
- pandas_market_calendars/holidays/jpx_equinox.py +1 -0
- pandas_market_calendars/holidays/nyse.py +1536 -1531
- pandas_market_calendars/holidays/oz.py +63 -63
- pandas_market_calendars/holidays/sifma.py +350 -338
- pandas_market_calendars/holidays/us.py +376 -376
- pandas_market_calendars/market_calendar.py +1057 -895
- {pandas_market_calendars-4.3.3.dist-info → pandas_market_calendars-4.6.0.dist-info}/METADATA +13 -9
- pandas_market_calendars-4.6.0.dist-info/RECORD +50 -0
- {pandas_market_calendars-4.3.3.dist-info → pandas_market_calendars-4.6.0.dist-info}/WHEEL +1 -1
- pandas_market_calendars-4.3.3.dist-info/RECORD +0 -50
- {pandas_market_calendars-4.3.3.dist-info → pandas_market_calendars-4.6.0.dist-info}/LICENSE +0 -0
- {pandas_market_calendars-4.3.3.dist-info → pandas_market_calendars-4.6.0.dist-info}/NOTICE +0 -0
- {pandas_market_calendars-4.3.3.dist-info → pandas_market_calendars-4.6.0.dist-info}/top_level.txt +0 -0
@@ -1,114 +1,114 @@
|
|
1
|
-
#
|
2
|
-
# Copyright 2016 Quantopian, Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
|
16
|
-
from datetime import time
|
17
|
-
|
18
|
-
from pandas.tseries.holiday import AbstractHolidayCalendar, EasterMonday, GoodFriday
|
19
|
-
from pytz import timezone
|
20
|
-
|
21
|
-
from pandas_market_calendars.holidays.uk import (
|
22
|
-
BoxingDay,
|
23
|
-
Christmas,
|
24
|
-
ChristmasEve,
|
25
|
-
LSENewYearsDay,
|
26
|
-
LSENewYearsEve,
|
27
|
-
MayBank_pre_1995,
|
28
|
-
MayBank_post_1995_pre_2020,
|
29
|
-
MayBank_post_2020,
|
30
|
-
SpringBank_pre_2002,
|
31
|
-
SpringBank_post_2002_pre_2012,
|
32
|
-
SpringBank_post_2012_pre_2022,
|
33
|
-
SpringBank_post_2022,
|
34
|
-
SummerBank,
|
35
|
-
WeekendBoxingDay,
|
36
|
-
WeekendChristmas,
|
37
|
-
UniqueCloses,
|
38
|
-
)
|
39
|
-
from pandas_market_calendars.market_calendar import MarketCalendar
|
40
|
-
|
41
|
-
|
42
|
-
class LSEExchangeCalendar(MarketCalendar):
|
43
|
-
"""
|
44
|
-
Exchange calendar for the London Stock Exchange
|
45
|
-
|
46
|
-
Open Time: 8:00 AM, GMT
|
47
|
-
Close Time: 4:30 PM, GMT
|
48
|
-
|
49
|
-
Regularly-Observed Holidays:
|
50
|
-
- New Years Day (observed on first business day on/after)
|
51
|
-
- Good Friday
|
52
|
-
- Easter Monday
|
53
|
-
- Early May Bank Holiday (first Monday in May)
|
54
|
-
- Spring Bank Holiday (last Monday in May)
|
55
|
-
- Summer Bank Holiday (last Monday in August)
|
56
|
-
- Christmas Day
|
57
|
-
- Dec. 27th (if Christmas is on a weekend)
|
58
|
-
- Boxing Day
|
59
|
-
- Dec. 28th (if Boxing Day is on a weekend)
|
60
|
-
"""
|
61
|
-
|
62
|
-
aliases = ["LSE"]
|
63
|
-
regular_market_times = {
|
64
|
-
"market_open": ((None, time(8)),),
|
65
|
-
"market_close": ((None, time(16, 30)),),
|
66
|
-
}
|
67
|
-
|
68
|
-
@property
|
69
|
-
def name(self):
|
70
|
-
return "LSE"
|
71
|
-
|
72
|
-
@property
|
73
|
-
def tz(self):
|
74
|
-
return timezone("Europe/London")
|
75
|
-
|
76
|
-
@property
|
77
|
-
def regular_holidays(self):
|
78
|
-
return AbstractHolidayCalendar(
|
79
|
-
rules=[
|
80
|
-
LSENewYearsDay,
|
81
|
-
GoodFriday,
|
82
|
-
EasterMonday,
|
83
|
-
MayBank_pre_1995,
|
84
|
-
MayBank_post_1995_pre_2020,
|
85
|
-
MayBank_post_2020,
|
86
|
-
SpringBank_pre_2002,
|
87
|
-
SpringBank_post_2002_pre_2012,
|
88
|
-
SpringBank_post_2012_pre_2022,
|
89
|
-
SpringBank_post_2022,
|
90
|
-
SummerBank,
|
91
|
-
Christmas,
|
92
|
-
WeekendChristmas,
|
93
|
-
BoxingDay,
|
94
|
-
WeekendBoxingDay,
|
95
|
-
]
|
96
|
-
)
|
97
|
-
|
98
|
-
@property
|
99
|
-
def adhoc_holidays(self):
|
100
|
-
return UniqueCloses
|
101
|
-
|
102
|
-
@property
|
103
|
-
def special_closes(self):
|
104
|
-
return [
|
105
|
-
(
|
106
|
-
time(12, 30),
|
107
|
-
AbstractHolidayCalendar(
|
108
|
-
rules=[
|
109
|
-
ChristmasEve,
|
110
|
-
LSENewYearsEve,
|
111
|
-
]
|
112
|
-
),
|
113
|
-
)
|
114
|
-
]
|
1
|
+
#
|
2
|
+
# Copyright 2016 Quantopian, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
from datetime import time
|
17
|
+
|
18
|
+
from pandas.tseries.holiday import AbstractHolidayCalendar, EasterMonday, GoodFriday
|
19
|
+
from pytz import timezone
|
20
|
+
|
21
|
+
from pandas_market_calendars.holidays.uk import (
|
22
|
+
BoxingDay,
|
23
|
+
Christmas,
|
24
|
+
ChristmasEve,
|
25
|
+
LSENewYearsDay,
|
26
|
+
LSENewYearsEve,
|
27
|
+
MayBank_pre_1995,
|
28
|
+
MayBank_post_1995_pre_2020,
|
29
|
+
MayBank_post_2020,
|
30
|
+
SpringBank_pre_2002,
|
31
|
+
SpringBank_post_2002_pre_2012,
|
32
|
+
SpringBank_post_2012_pre_2022,
|
33
|
+
SpringBank_post_2022,
|
34
|
+
SummerBank,
|
35
|
+
WeekendBoxingDay,
|
36
|
+
WeekendChristmas,
|
37
|
+
UniqueCloses,
|
38
|
+
)
|
39
|
+
from pandas_market_calendars.market_calendar import MarketCalendar
|
40
|
+
|
41
|
+
|
42
|
+
class LSEExchangeCalendar(MarketCalendar):
|
43
|
+
"""
|
44
|
+
Exchange calendar for the London Stock Exchange
|
45
|
+
|
46
|
+
Open Time: 8:00 AM, GMT
|
47
|
+
Close Time: 4:30 PM, GMT
|
48
|
+
|
49
|
+
Regularly-Observed Holidays:
|
50
|
+
- New Years Day (observed on first business day on/after)
|
51
|
+
- Good Friday
|
52
|
+
- Easter Monday
|
53
|
+
- Early May Bank Holiday (first Monday in May)
|
54
|
+
- Spring Bank Holiday (last Monday in May)
|
55
|
+
- Summer Bank Holiday (last Monday in August)
|
56
|
+
- Christmas Day
|
57
|
+
- Dec. 27th (if Christmas is on a weekend)
|
58
|
+
- Boxing Day
|
59
|
+
- Dec. 28th (if Boxing Day is on a weekend)
|
60
|
+
"""
|
61
|
+
|
62
|
+
aliases = ["LSE"]
|
63
|
+
regular_market_times = {
|
64
|
+
"market_open": ((None, time(8)),),
|
65
|
+
"market_close": ((None, time(16, 30)),),
|
66
|
+
}
|
67
|
+
|
68
|
+
@property
|
69
|
+
def name(self):
|
70
|
+
return "LSE"
|
71
|
+
|
72
|
+
@property
|
73
|
+
def tz(self):
|
74
|
+
return timezone("Europe/London")
|
75
|
+
|
76
|
+
@property
|
77
|
+
def regular_holidays(self):
|
78
|
+
return AbstractHolidayCalendar(
|
79
|
+
rules=[
|
80
|
+
LSENewYearsDay,
|
81
|
+
GoodFriday,
|
82
|
+
EasterMonday,
|
83
|
+
MayBank_pre_1995,
|
84
|
+
MayBank_post_1995_pre_2020,
|
85
|
+
MayBank_post_2020,
|
86
|
+
SpringBank_pre_2002,
|
87
|
+
SpringBank_post_2002_pre_2012,
|
88
|
+
SpringBank_post_2012_pre_2022,
|
89
|
+
SpringBank_post_2022,
|
90
|
+
SummerBank,
|
91
|
+
Christmas,
|
92
|
+
WeekendChristmas,
|
93
|
+
BoxingDay,
|
94
|
+
WeekendBoxingDay,
|
95
|
+
]
|
96
|
+
)
|
97
|
+
|
98
|
+
@property
|
99
|
+
def adhoc_holidays(self):
|
100
|
+
return UniqueCloses
|
101
|
+
|
102
|
+
@property
|
103
|
+
def special_closes(self):
|
104
|
+
return [
|
105
|
+
(
|
106
|
+
time(12, 30),
|
107
|
+
AbstractHolidayCalendar(
|
108
|
+
rules=[
|
109
|
+
ChristmasEve,
|
110
|
+
LSENewYearsEve,
|
111
|
+
]
|
112
|
+
),
|
113
|
+
)
|
114
|
+
]
|
@@ -1,130 +1,149 @@
|
|
1
|
-
"""
|
2
|
-
Imported calendars from the exchange_calendars project
|
3
|
-
|
4
|
-
GitHub: https://github.com/gerrymanoim/exchange_calendars
|
5
|
-
"""
|
6
|
-
|
7
|
-
import exchange_calendars
|
8
|
-
|
9
|
-
from pandas_market_calendars.market_calendar import MarketCalendar
|
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
|
-
for
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
1
|
+
"""
|
2
|
+
Imported calendars from the exchange_calendars project
|
3
|
+
|
4
|
+
GitHub: https://github.com/gerrymanoim/exchange_calendars
|
5
|
+
"""
|
6
|
+
|
7
|
+
import exchange_calendars
|
8
|
+
|
9
|
+
from pandas_market_calendars.market_calendar import MarketCalendar
|
10
|
+
|
11
|
+
DAYMASKS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
|
12
|
+
|
13
|
+
|
14
|
+
class TradingCalendar(MarketCalendar):
|
15
|
+
"""
|
16
|
+
This class provides access to all the information on opens, breaks and closes that are available
|
17
|
+
in the exchange_calendars package, it will receive the correctly formatted regular_market_times
|
18
|
+
dictionary in the for-loop below.
|
19
|
+
|
20
|
+
The initialization of calendars from exchange_calendars, is bypassed until the `.ec` property is used,
|
21
|
+
which returns the initialized exchange_calendar calendar, which is only initialized the first time.
|
22
|
+
"""
|
23
|
+
|
24
|
+
# flag indicating that offset still needs to be checked.
|
25
|
+
# A class attribute so we only do this once per class and not per instance
|
26
|
+
_FINALIZE_TRADING_CALENDAR = True
|
27
|
+
|
28
|
+
def __new__(cls, *args, **kwargs):
|
29
|
+
self = super().__new__(cls)
|
30
|
+
self._ec = super().__new__(cls._ec_class)
|
31
|
+
# flag indicating that mirrored class is not initialized yet, which we only want to do
|
32
|
+
# once per instance, if and only if the public `.ec` property is used.
|
33
|
+
self._EC_NOT_INITIALIZED = True
|
34
|
+
|
35
|
+
# offsets of exchange_calendar_mirrors are only available through the instance
|
36
|
+
if cls._FINALIZE_TRADING_CALENDAR:
|
37
|
+
if self._ec.open_offset:
|
38
|
+
cls.regular_market_times._set(
|
39
|
+
"market_open",
|
40
|
+
tuple(
|
41
|
+
(t[0], t[1], self._ec.open_offset)
|
42
|
+
for t in cls.regular_market_times["market_open"]
|
43
|
+
),
|
44
|
+
)
|
45
|
+
|
46
|
+
if self._ec.close_offset:
|
47
|
+
cls.regular_market_times._set(
|
48
|
+
"market_close",
|
49
|
+
tuple(
|
50
|
+
(t[0], t[1], self._ec.close_offset)
|
51
|
+
for t in cls.regular_market_times["market_close"]
|
52
|
+
),
|
53
|
+
)
|
54
|
+
cls._FINALIZE_TRADING_CALENDAR = False
|
55
|
+
|
56
|
+
self.__init__(*args, **kwargs)
|
57
|
+
return self
|
58
|
+
|
59
|
+
def __init__(self, open_time=None, close_time=None):
|
60
|
+
super().__init__(open_time, close_time)
|
61
|
+
|
62
|
+
@property
|
63
|
+
def ec(self):
|
64
|
+
if self._EC_NOT_INITIALIZED:
|
65
|
+
self._ec.__init__()
|
66
|
+
self._EC_NOT_INITIALIZED = False
|
67
|
+
|
68
|
+
return self._ec
|
69
|
+
|
70
|
+
@property
|
71
|
+
def name(self):
|
72
|
+
return self._ec.name
|
73
|
+
|
74
|
+
@property
|
75
|
+
def tz(self):
|
76
|
+
return self._ec.tz
|
77
|
+
|
78
|
+
@property
|
79
|
+
def regular_holidays(self):
|
80
|
+
return self._ec.regular_holidays
|
81
|
+
|
82
|
+
@property
|
83
|
+
def adhoc_holidays(self):
|
84
|
+
return self._ec.adhoc_holidays
|
85
|
+
|
86
|
+
@property
|
87
|
+
def special_opens(self):
|
88
|
+
return self._ec.special_opens
|
89
|
+
|
90
|
+
@property
|
91
|
+
def special_opens_adhoc(self):
|
92
|
+
return self._ec.special_opens_adhoc
|
93
|
+
|
94
|
+
@property
|
95
|
+
def special_closes(self):
|
96
|
+
return self._ec.special_closes
|
97
|
+
|
98
|
+
@property
|
99
|
+
def special_closes_adhoc(self):
|
100
|
+
return self._ec.special_closes_adhoc
|
101
|
+
|
102
|
+
@property
|
103
|
+
def weekmask(self):
|
104
|
+
if hasattr(self._ec, "weekmask"):
|
105
|
+
if "1" in self._ec.weekmask or "0" in self._ec.weekmask:
|
106
|
+
# Convert 1s & 0s to Day Abbreviations
|
107
|
+
return " ".join(
|
108
|
+
[
|
109
|
+
DAYMASKS[i]
|
110
|
+
for i, val in enumerate(self._ec.weekmask)
|
111
|
+
if val == "1"
|
112
|
+
]
|
113
|
+
)
|
114
|
+
else:
|
115
|
+
return self._ec.weekmask
|
116
|
+
else:
|
117
|
+
return "Mon Tue Wed Thu Fri"
|
118
|
+
|
119
|
+
|
120
|
+
calendars = exchange_calendars.calendar_utils._default_calendar_factories # noqa
|
121
|
+
|
122
|
+
time_props = dict(
|
123
|
+
open_times="market_open",
|
124
|
+
close_times="market_close",
|
125
|
+
break_start_times="break_start",
|
126
|
+
break_end_times="break_end",
|
127
|
+
)
|
128
|
+
|
129
|
+
for exchange in calendars:
|
130
|
+
cal = calendars[exchange]
|
131
|
+
|
132
|
+
# this loop will set up the newly required regular_market_times dictionary
|
133
|
+
regular_market_times = {}
|
134
|
+
for prop, new in time_props.items():
|
135
|
+
times = getattr(cal, prop)
|
136
|
+
if times is None or isinstance(times, property):
|
137
|
+
continue
|
138
|
+
regular_market_times[new] = times
|
139
|
+
|
140
|
+
cal = type(
|
141
|
+
exchange,
|
142
|
+
(TradingCalendar,),
|
143
|
+
{
|
144
|
+
"_ec_class": calendars[exchange],
|
145
|
+
"alias": [exchange],
|
146
|
+
"regular_market_times": regular_market_times,
|
147
|
+
},
|
148
|
+
)
|
149
|
+
locals()[f"{exchange}ExchangeCalendar"] = cal
|