pandas-market-calendars 4.1.3__py3-none-any.whl → 4.2.0__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.
- {pandas_market_calendars-4.1.3.dist-info → pandas_market_calendars-4.2.0.dist-info}/METADATA +200 -187
- pandas_market_calendars-4.2.0.dist-info/NOTICE +206 -0
- pandas_market_calendars-4.2.0.dist-info/RECORD +6 -0
- {pandas_market_calendars-4.1.3.dist-info → pandas_market_calendars-4.2.0.dist-info}/WHEEL +1 -1
- pandas_market_calendars/__init__.py +0 -37
- pandas_market_calendars/calendar_registry.py +0 -47
- pandas_market_calendars/calendar_utils.py +0 -225
- pandas_market_calendars/class_registry.py +0 -111
- pandas_market_calendars/exchange_calendar_asx.py +0 -63
- pandas_market_calendars/exchange_calendar_bmf.py +0 -227
- pandas_market_calendars/exchange_calendar_bse.py +0 -409
- pandas_market_calendars/exchange_calendar_cboe.py +0 -115
- pandas_market_calendars/exchange_calendar_cme.py +0 -240
- pandas_market_calendars/exchange_calendar_cme_globex_agriculture.py +0 -109
- pandas_market_calendars/exchange_calendar_cme_globex_base.py +0 -106
- pandas_market_calendars/exchange_calendar_cme_globex_energy_and_metals.py +0 -146
- pandas_market_calendars/exchange_calendar_cme_globex_equities.py +0 -104
- pandas_market_calendars/exchange_calendar_cme_globex_fixed_income.py +0 -114
- pandas_market_calendars/exchange_calendar_cme_globex_fx.py +0 -78
- pandas_market_calendars/exchange_calendar_eurex.py +0 -119
- pandas_market_calendars/exchange_calendar_hkex.py +0 -408
- pandas_market_calendars/exchange_calendar_ice.py +0 -65
- pandas_market_calendars/exchange_calendar_iex.py +0 -98
- pandas_market_calendars/exchange_calendar_jpx.py +0 -98
- pandas_market_calendars/exchange_calendar_lse.py +0 -91
- pandas_market_calendars/exchange_calendar_nyse.py +0 -1127
- pandas_market_calendars/exchange_calendar_ose.py +0 -150
- pandas_market_calendars/exchange_calendar_sifma.py +0 -300
- pandas_market_calendars/exchange_calendar_six.py +0 -114
- pandas_market_calendars/exchange_calendar_sse.py +0 -290
- pandas_market_calendars/exchange_calendar_tase.py +0 -119
- pandas_market_calendars/exchange_calendar_tsx.py +0 -159
- pandas_market_calendars/exchange_calendars_mirror.py +0 -114
- pandas_market_calendars/holidays_cme.py +0 -341
- pandas_market_calendars/holidays_cme_globex.py +0 -169
- pandas_market_calendars/holidays_cn.py +0 -1436
- pandas_market_calendars/holidays_jp.py +0 -362
- pandas_market_calendars/holidays_nyse.py +0 -1474
- pandas_market_calendars/holidays_oz.py +0 -65
- pandas_market_calendars/holidays_sifma.py +0 -321
- pandas_market_calendars/holidays_uk.py +0 -177
- pandas_market_calendars/holidays_us.py +0 -364
- pandas_market_calendars/jpx_equinox.py +0 -147
- pandas_market_calendars/market_calendar.py +0 -770
- pandas_market_calendars-4.1.3.dist-info/RECORD +0 -45
- {pandas_market_calendars-4.1.3.dist-info → pandas_market_calendars-4.2.0.dist-info}/LICENSE +0 -0
- {pandas_market_calendars-4.1.3.dist-info → pandas_market_calendars-4.2.0.dist-info}/top_level.txt +0 -0
@@ -1,290 +0,0 @@
|
|
1
|
-
from datetime import time, timedelta
|
2
|
-
from functools import partial
|
3
|
-
|
4
|
-
from pandas.tseries.holiday import AbstractHolidayCalendar, Holiday, next_monday
|
5
|
-
from pytz import timezone
|
6
|
-
|
7
|
-
from .holidays_cn import *
|
8
|
-
from .market_calendar import MarketCalendar
|
9
|
-
|
10
|
-
|
11
|
-
class SSEExchangeCalendar(MarketCalendar):
|
12
|
-
"""
|
13
|
-
Exchange calendar for Shanghai Stock Exchange
|
14
|
-
|
15
|
-
Open Time: 9:30 AM, Asia/Shanghai
|
16
|
-
LUNCH BREAK :facepalm: : 11:30 AM - 1:00 PM Asia/Shanghai
|
17
|
-
Close Time: 3:00 PM, Asia/Shanghai
|
18
|
-
"""
|
19
|
-
aliases = ['SSE']
|
20
|
-
regular_market_times = {
|
21
|
-
"market_open": ((None, time(9, 30)),),
|
22
|
-
"market_close": ((None, time(15)),),
|
23
|
-
"break_start": ((None, time(11,30)),),
|
24
|
-
"break_end": ((None, time(13)),)
|
25
|
-
}
|
26
|
-
|
27
|
-
@property
|
28
|
-
def name(self):
|
29
|
-
return "SSE"
|
30
|
-
|
31
|
-
@property
|
32
|
-
def tz(self):
|
33
|
-
return timezone('Asia/Shanghai')
|
34
|
-
|
35
|
-
@property
|
36
|
-
def regular_holidays(self):
|
37
|
-
"""
|
38
|
-
Rules are guesses based on observations of recent year.
|
39
|
-
Rectify accordingly once the next year's holidays arrangement is published by the government.
|
40
|
-
"""
|
41
|
-
# Since all past holidays are adhoc, start_year should always be a year in the future.
|
42
|
-
# For example: Holiday arrangements for 2022 are now included,
|
43
|
-
# then our guesswork starts from the next year so start_year = 2023
|
44
|
-
start_year = 2024
|
45
|
-
|
46
|
-
return AbstractHolidayCalendar(rules=[
|
47
|
-
Holiday(
|
48
|
-
name="New Year's Day",
|
49
|
-
month=1,
|
50
|
-
day=1,
|
51
|
-
observance=next_monday,
|
52
|
-
start_date=Timestamp(start_year, 1, 1),
|
53
|
-
),
|
54
|
-
Holiday(
|
55
|
-
name="New Year's Day",
|
56
|
-
month=1,
|
57
|
-
day=2,
|
58
|
-
observance=partial(second_day_in_lieu),
|
59
|
-
start_date=Timestamp(start_year, 1, 2),
|
60
|
-
),
|
61
|
-
Holiday(
|
62
|
-
name="New Year's Day",
|
63
|
-
month=1,
|
64
|
-
day=3,
|
65
|
-
observance=partial(third_day_in_lieu),
|
66
|
-
start_date=Timestamp(start_year, 1, 3),
|
67
|
-
),
|
68
|
-
Holiday(
|
69
|
-
name="Spring Festival",
|
70
|
-
month=1,
|
71
|
-
day=20,
|
72
|
-
observance=partial(lunisolar, mapping=sf_mapping, delta=-1),
|
73
|
-
start_date=Timestamp(start_year, 1, 20),
|
74
|
-
),
|
75
|
-
Holiday(
|
76
|
-
name="Spring Festival",
|
77
|
-
month=1,
|
78
|
-
day=21,
|
79
|
-
observance=partial(lunisolar, mapping=sf_mapping, delta=0),
|
80
|
-
start_date=Timestamp(start_year, 1, 21),
|
81
|
-
),
|
82
|
-
Holiday(
|
83
|
-
name="Spring Festival",
|
84
|
-
month=1,
|
85
|
-
day=21,
|
86
|
-
observance=partial(lunisolar, mapping=sf_mapping, delta=1),
|
87
|
-
start_date=Timestamp(start_year, 1, 22),
|
88
|
-
),
|
89
|
-
Holiday(
|
90
|
-
name="Spring Festival",
|
91
|
-
month=1,
|
92
|
-
day=21,
|
93
|
-
observance=partial(lunisolar, mapping=sf_mapping, delta=2),
|
94
|
-
start_date=Timestamp(start_year, 1, 23),
|
95
|
-
),
|
96
|
-
Holiday(
|
97
|
-
name="Spring Festival",
|
98
|
-
month=1,
|
99
|
-
day=21,
|
100
|
-
observance=partial(lunisolar, mapping=sf_mapping, delta=3),
|
101
|
-
start_date=Timestamp(start_year, 1, 24),
|
102
|
-
),
|
103
|
-
Holiday(
|
104
|
-
name="Spring Festival",
|
105
|
-
month=1,
|
106
|
-
day=21,
|
107
|
-
observance=partial(lunisolar, mapping=sf_mapping, delta=4),
|
108
|
-
start_date=Timestamp(start_year, 1, 25),
|
109
|
-
),
|
110
|
-
Holiday(
|
111
|
-
name="Spring Festival",
|
112
|
-
month=1,
|
113
|
-
day=21,
|
114
|
-
observance=partial(lunisolar, mapping=sf_mapping, delta=5),
|
115
|
-
start_date=Timestamp(start_year, 1, 26),
|
116
|
-
),
|
117
|
-
Holiday(
|
118
|
-
name="Labour Day",
|
119
|
-
month=5,
|
120
|
-
day=1,
|
121
|
-
observance=next_monday,
|
122
|
-
start_date=Timestamp(start_year, 5, 1),
|
123
|
-
),
|
124
|
-
Holiday(
|
125
|
-
name="Labour Day",
|
126
|
-
month=5,
|
127
|
-
day=2,
|
128
|
-
observance=second_day_in_lieu,
|
129
|
-
start_date=Timestamp(start_year, 5, 2),
|
130
|
-
),
|
131
|
-
Holiday(
|
132
|
-
name="Labour Day",
|
133
|
-
month=5,
|
134
|
-
day=3,
|
135
|
-
observance=third_day_in_lieu,
|
136
|
-
start_date=Timestamp(start_year, 5, 3),
|
137
|
-
),
|
138
|
-
Holiday(
|
139
|
-
name="Tomb-sweeping Day",
|
140
|
-
month=4,
|
141
|
-
day=4,
|
142
|
-
observance=partial(lunisolar, mapping=tsd_mapping, func=next_monday),
|
143
|
-
start_date=Timestamp(start_year, 4, 4),
|
144
|
-
),
|
145
|
-
Holiday(
|
146
|
-
name="Tomb-sweeping Day",
|
147
|
-
month=4,
|
148
|
-
day=5,
|
149
|
-
observance=partial(lunisolar, mapping=tsd_mapping, func=second_day_in_lieu, delta=1),
|
150
|
-
start_date=Timestamp(start_year, 4, 4),
|
151
|
-
),
|
152
|
-
Holiday(
|
153
|
-
name="Tomb-sweeping Day",
|
154
|
-
month=4,
|
155
|
-
day=6,
|
156
|
-
observance=partial(lunisolar, mapping=tsd_mapping, func=third_day_in_lieu, delta=2),
|
157
|
-
start_date=Timestamp(start_year, 4, 4),
|
158
|
-
),
|
159
|
-
Holiday(
|
160
|
-
name="Dragon Boat Festival",
|
161
|
-
month=5,
|
162
|
-
day=27,
|
163
|
-
observance=partial(lunisolar, mapping=dbf_mapping, func=next_monday),
|
164
|
-
start_date=Timestamp(start_year, 5, 27),
|
165
|
-
),
|
166
|
-
Holiday(
|
167
|
-
name="Dragon Boat Festival",
|
168
|
-
month=5,
|
169
|
-
day=28,
|
170
|
-
observance=partial(lunisolar, mapping=dbf_mapping, func=second_day_in_lieu, delta=1),
|
171
|
-
start_date=Timestamp(start_year, 5, 27),
|
172
|
-
),
|
173
|
-
Holiday(
|
174
|
-
name="Dragon Boat Festival",
|
175
|
-
month=5,
|
176
|
-
day=29,
|
177
|
-
observance=partial(lunisolar, mapping=dbf_mapping, func=third_day_in_lieu, delta=2),
|
178
|
-
start_date=Timestamp(start_year, 5, 27),
|
179
|
-
),
|
180
|
-
Holiday(
|
181
|
-
name="Mid-autumn Festival",
|
182
|
-
month=9,
|
183
|
-
day=7,
|
184
|
-
observance=partial(lunisolar, mapping=maf_mapping, func=next_monday),
|
185
|
-
start_date=Timestamp(start_year, 9, 7),
|
186
|
-
),
|
187
|
-
Holiday(
|
188
|
-
name="Mid-autumn Festival",
|
189
|
-
month=9,
|
190
|
-
day=8,
|
191
|
-
observance=partial(lunisolar, mapping=maf_mapping, func=second_day_in_lieu, delta=1),
|
192
|
-
start_date=Timestamp(start_year, 9, 7),
|
193
|
-
),
|
194
|
-
Holiday(
|
195
|
-
name="Mid-autumn Festival",
|
196
|
-
month=9,
|
197
|
-
day=9,
|
198
|
-
observance=partial(lunisolar, mapping=maf_mapping, func=third_day_in_lieu, delta=2),
|
199
|
-
start_date=Timestamp(start_year, 9, 7),
|
200
|
-
),
|
201
|
-
Holiday(
|
202
|
-
name="National Day",
|
203
|
-
month=10,
|
204
|
-
day=1,
|
205
|
-
start_date=Timestamp(start_year, 10, 1),
|
206
|
-
),
|
207
|
-
Holiday(
|
208
|
-
name="National Day",
|
209
|
-
month=10,
|
210
|
-
day=2,
|
211
|
-
start_date=Timestamp(start_year, 10, 2),
|
212
|
-
),
|
213
|
-
Holiday(
|
214
|
-
name="National Day",
|
215
|
-
month=10,
|
216
|
-
day=3,
|
217
|
-
start_date=Timestamp(start_year, 10, 3),
|
218
|
-
),
|
219
|
-
Holiday(
|
220
|
-
name="National Day",
|
221
|
-
month=10,
|
222
|
-
day=4,
|
223
|
-
start_date=Timestamp(start_year, 10, 4),
|
224
|
-
),
|
225
|
-
Holiday(
|
226
|
-
name="National Day",
|
227
|
-
month=10,
|
228
|
-
day=5,
|
229
|
-
start_date=Timestamp(start_year, 10, 5),
|
230
|
-
),
|
231
|
-
Holiday(
|
232
|
-
name="National Day",
|
233
|
-
month=10,
|
234
|
-
day=6,
|
235
|
-
start_date=Timestamp(start_year, 10, 6),
|
236
|
-
),
|
237
|
-
Holiday(
|
238
|
-
name="National Day",
|
239
|
-
month=10,
|
240
|
-
day=7,
|
241
|
-
start_date=Timestamp(start_year, 10, 7),
|
242
|
-
),
|
243
|
-
])
|
244
|
-
|
245
|
-
@property
|
246
|
-
def adhoc_holidays(self):
|
247
|
-
return all_holidays
|
248
|
-
|
249
|
-
|
250
|
-
def second_day_in_lieu(dt):
|
251
|
-
dow = dt.weekday()
|
252
|
-
if dow == 0: # Holiday is Sunday, use Saturday
|
253
|
-
return dt - timedelta(2)
|
254
|
-
elif dow == 1: # Holiday is Monday, use Saturday
|
255
|
-
return dt - timedelta(3)
|
256
|
-
elif dow == 2: # Holiday is Tuesday, use Sunday
|
257
|
-
return dt - timedelta(3)
|
258
|
-
elif dow == 3: # Holiday is Wednesday, use Saturday
|
259
|
-
return dt - timedelta(5)
|
260
|
-
|
261
|
-
return dt
|
262
|
-
|
263
|
-
|
264
|
-
def third_day_in_lieu(dt):
|
265
|
-
dow = dt.weekday()
|
266
|
-
if dow == 0: # Holiday is Saturday, use Sunday
|
267
|
-
return dt - timedelta(1)
|
268
|
-
elif dow == 1: # Holiday is Sunday, use Sunday
|
269
|
-
return dt - timedelta(2)
|
270
|
-
elif dow == 2: # Holiday is Monday, use Sunday
|
271
|
-
return dt - timedelta(3)
|
272
|
-
elif dow == 3: # Holiday is Tuesday, use Monday
|
273
|
-
return dt - timedelta(3)
|
274
|
-
elif dow == 4: # Holiday is Wednesday, use Sunday
|
275
|
-
return dt - timedelta(5)
|
276
|
-
|
277
|
-
return dt
|
278
|
-
|
279
|
-
|
280
|
-
def lunisolar(dt, mapping, func=None, delta=None):
|
281
|
-
if mapping and (dt.year in mapping):
|
282
|
-
new_dt = mapping[dt.year]
|
283
|
-
else:
|
284
|
-
new_dt = dt
|
285
|
-
if delta:
|
286
|
-
new_dt = new_dt + timedelta(delta)
|
287
|
-
if func:
|
288
|
-
return func(new_dt)
|
289
|
-
else:
|
290
|
-
return new_dt
|
@@ -1,119 +0,0 @@
|
|
1
|
-
from datetime import time
|
2
|
-
from pandas import Timestamp
|
3
|
-
from pytz import timezone
|
4
|
-
from .market_calendar import MarketCalendar
|
5
|
-
|
6
|
-
TASEClosedDay = [
|
7
|
-
# 2019
|
8
|
-
Timestamp('2019-03-21', tz='Asia/Jerusalem'),
|
9
|
-
Timestamp('2019-04-09', tz='Asia/Jerusalem'),
|
10
|
-
Timestamp('2019-04-25', tz='Asia/Jerusalem'),
|
11
|
-
Timestamp('2019-04-26', tz='Asia/Jerusalem'),
|
12
|
-
Timestamp('2019-05-08', tz='Asia/Jerusalem'),
|
13
|
-
Timestamp('2019-05-09', tz='Asia/Jerusalem'),
|
14
|
-
Timestamp('2019-06-09', tz='Asia/Jerusalem'),
|
15
|
-
Timestamp('2019-08-11', tz='Asia/Jerusalem'),
|
16
|
-
Timestamp('2019-09-17', tz='Asia/Jerusalem'),
|
17
|
-
Timestamp('2019-09-29', tz='Asia/Jerusalem'),
|
18
|
-
Timestamp('2019-09-30', tz='Asia/Jerusalem'),
|
19
|
-
Timestamp('2019-10-01', tz='Asia/Jerusalem'),
|
20
|
-
Timestamp('2019-10-08', tz='Asia/Jerusalem'),
|
21
|
-
Timestamp('2019-10-09', tz='Asia/Jerusalem'),
|
22
|
-
Timestamp('2019-10-13', tz='Asia/Jerusalem'),
|
23
|
-
Timestamp('2019-10-14', tz='Asia/Jerusalem'),
|
24
|
-
Timestamp('2019-10-20', tz='Asia/Jerusalem'),
|
25
|
-
Timestamp('2019-10-21', tz='Asia/Jerusalem'),
|
26
|
-
# 2020
|
27
|
-
Timestamp('2020-03-02', tz='Asia/Jerusalem'),
|
28
|
-
Timestamp('2020-03-10', tz='Asia/Jerusalem'),
|
29
|
-
Timestamp('2020-04-08', tz='Asia/Jerusalem'),
|
30
|
-
Timestamp('2020-04-09', tz='Asia/Jerusalem'),
|
31
|
-
Timestamp('2020-04-14', tz='Asia/Jerusalem'),
|
32
|
-
Timestamp('2020-04-15', tz='Asia/Jerusalem'),
|
33
|
-
Timestamp('2020-04-28', tz='Asia/Jerusalem'),
|
34
|
-
Timestamp('2020-04-29', tz='Asia/Jerusalem'),
|
35
|
-
Timestamp('2020-05-28', tz='Asia/Jerusalem'),
|
36
|
-
Timestamp('2020-05-29', tz='Asia/Jerusalem'),
|
37
|
-
Timestamp('2020-07-30', tz='Asia/Jerusalem'),
|
38
|
-
Timestamp('2020-09-20', tz='Asia/Jerusalem'),
|
39
|
-
Timestamp('2020-09-27', tz='Asia/Jerusalem'),
|
40
|
-
Timestamp('2020-09-28', tz='Asia/Jerusalem'),
|
41
|
-
# 2021
|
42
|
-
Timestamp('2021-02-26', tz='Asia/Jerusalem'),
|
43
|
-
Timestamp('2021-03-28', tz='Asia/Jerusalem'),
|
44
|
-
Timestamp('2021-04-02', tz='Asia/Jerusalem'),
|
45
|
-
Timestamp('2021-04-14', tz='Asia/Jerusalem'),
|
46
|
-
Timestamp('2021-04-15', tz='Asia/Jerusalem'),
|
47
|
-
Timestamp('2021-05-16', tz='Asia/Jerusalem'),
|
48
|
-
Timestamp('2021-05-17', tz='Asia/Jerusalem'),
|
49
|
-
Timestamp('2021-07-18', tz='Asia/Jerusalem'),
|
50
|
-
Timestamp('2021-09-06', tz='Asia/Jerusalem'),
|
51
|
-
Timestamp('2021-09-07', tz='Asia/Jerusalem'),
|
52
|
-
Timestamp('2021-09-08', tz='Asia/Jerusalem'),
|
53
|
-
Timestamp('2021-09-15', tz='Asia/Jerusalem'),
|
54
|
-
Timestamp('2021-09-16', tz='Asia/Jerusalem'),
|
55
|
-
Timestamp('2021-09-20', tz='Asia/Jerusalem'),
|
56
|
-
Timestamp('2021-09-21', tz='Asia/Jerusalem'),
|
57
|
-
Timestamp('2021-09-27', tz='Asia/Jerusalem'),
|
58
|
-
Timestamp('2021-09-28', tz='Asia/Jerusalem'),
|
59
|
-
]
|
60
|
-
|
61
|
-
|
62
|
-
class TASEExchangeCalendar(MarketCalendar):
|
63
|
-
"""
|
64
|
-
Exchange calendar for TASE Stock Exchange
|
65
|
-
|
66
|
-
Note these dates are only checked against 2020 and 2021
|
67
|
-
https://info.tase.co.il/Eng/about_tase/corporate/Pages/vacation_schedule.aspx
|
68
|
-
|
69
|
-
Opening times for the regular trading of equities (not including closing auction call)
|
70
|
-
Open Time: 10:00 AM Asia/Jerusalem
|
71
|
-
Close Time: 3:59 PM Asia/Jerusalem
|
72
|
-
|
73
|
-
Daylight Saving Time in Israel comes into effect on the Friday before the last Sunday in March, and lasts until the
|
74
|
-
last Sunday in October.
|
75
|
-
During the Daylight Saving time period the clock will be UTC+3, and for the rest of the year UTC+2.
|
76
|
-
|
77
|
-
Regularly-Observed Holidays (not necessarily in order):
|
78
|
-
- Purim
|
79
|
-
- Passover_I_Eve
|
80
|
-
- Passover_I
|
81
|
-
- Passover_II_Eve
|
82
|
-
- Passover_II
|
83
|
-
- Independence_Day
|
84
|
-
- Yom_HaZikaron
|
85
|
-
- Shavuot_Eve
|
86
|
-
- Shavuot
|
87
|
-
- Tisha_beAv
|
88
|
-
- Jewish_New_Year_Eve
|
89
|
-
- Jewish_New_Year_I
|
90
|
-
- Jewish_New_Year_II
|
91
|
-
- Yom_Kippur_Eve
|
92
|
-
- Yom_Kippur
|
93
|
-
- Sukkoth_Eve
|
94
|
-
- Sukkoth
|
95
|
-
- Simchat_Tora_Eve
|
96
|
-
- Simchat_Tora
|
97
|
-
"""
|
98
|
-
|
99
|
-
aliases = ['TASE']
|
100
|
-
regular_market_times = {
|
101
|
-
"market_open": ((None, time(10)),),
|
102
|
-
"market_close": ((None, time(15,59)),)
|
103
|
-
}
|
104
|
-
|
105
|
-
@property
|
106
|
-
def name(self):
|
107
|
-
return "TASE"
|
108
|
-
|
109
|
-
@property
|
110
|
-
def tz(self):
|
111
|
-
return timezone("Asia/Jerusalem")
|
112
|
-
|
113
|
-
@property
|
114
|
-
def adhoc_holidays(self):
|
115
|
-
return TASEClosedDay
|
116
|
-
|
117
|
-
@property
|
118
|
-
def weekmask(self):
|
119
|
-
return "Sun Mon Tue Wed Thu"
|
@@ -1,159 +0,0 @@
|
|
1
|
-
from datetime import time
|
2
|
-
|
3
|
-
import pandas as pd
|
4
|
-
from pandas.tseries.holiday import AbstractHolidayCalendar, DateOffset, GoodFriday, Holiday, MO, weekend_to_monday
|
5
|
-
from pytz import timezone
|
6
|
-
from itertools import chain
|
7
|
-
|
8
|
-
from .holidays_uk import BoxingDay, WeekendBoxingDay, WeekendChristmas
|
9
|
-
from .market_calendar import MarketCalendar, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY
|
10
|
-
|
11
|
-
# New Year's Day
|
12
|
-
TSXNewYearsDay = Holiday(
|
13
|
-
"New Year's Day",
|
14
|
-
month=1,
|
15
|
-
day=1,
|
16
|
-
observance=weekend_to_monday,
|
17
|
-
)
|
18
|
-
# Ontario Family Day
|
19
|
-
FamilyDay = Holiday(
|
20
|
-
"Family Day",
|
21
|
-
month=2,
|
22
|
-
day=1,
|
23
|
-
offset=DateOffset(weekday=MO(3)),
|
24
|
-
start_date='2008-01-01',
|
25
|
-
)
|
26
|
-
# Victoria Day
|
27
|
-
# https://www.timeanddate.com/holidays/canada/victoria-day
|
28
|
-
VictoriaDay = Holiday(
|
29
|
-
'Victoria Day',
|
30
|
-
month=5,
|
31
|
-
day=24,
|
32
|
-
offset=DateOffset(weekday=MO(-1)),
|
33
|
-
)
|
34
|
-
# Canada Day
|
35
|
-
CanadaDay = Holiday(
|
36
|
-
'Canada Day',
|
37
|
-
month=7,
|
38
|
-
day=1,
|
39
|
-
observance=weekend_to_monday,
|
40
|
-
)
|
41
|
-
# Civic Holiday
|
42
|
-
CivicHoliday = Holiday(
|
43
|
-
'Civic Holiday',
|
44
|
-
month=8,
|
45
|
-
day=1,
|
46
|
-
offset=DateOffset(weekday=MO(1)),
|
47
|
-
)
|
48
|
-
# Labor Day
|
49
|
-
LaborDay = Holiday(
|
50
|
-
'Labor Day',
|
51
|
-
month=9,
|
52
|
-
day=1,
|
53
|
-
offset=DateOffset(weekday=MO(1)),
|
54
|
-
)
|
55
|
-
# Thanksgiving
|
56
|
-
Thanksgiving = Holiday(
|
57
|
-
'Thanksgiving',
|
58
|
-
month=10,
|
59
|
-
day=1,
|
60
|
-
offset=DateOffset(weekday=MO(2)),
|
61
|
-
)
|
62
|
-
|
63
|
-
Christmas = Holiday(
|
64
|
-
'Christmas',
|
65
|
-
month=12,
|
66
|
-
day=25,
|
67
|
-
)
|
68
|
-
|
69
|
-
ChristmasEveEarlyClose2010Onwards = Holiday(
|
70
|
-
"Christmas Eve Early Close",
|
71
|
-
month=12,
|
72
|
-
day=24,
|
73
|
-
days_of_week=(MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY),
|
74
|
-
start_date=pd.Timestamp("2010-01-01"),
|
75
|
-
)
|
76
|
-
|
77
|
-
September11Closings2001 = [
|
78
|
-
pd.Timestamp("2001-09-11", tz='UTC'),
|
79
|
-
pd.Timestamp("2001-09-12", tz='UTC'),
|
80
|
-
]
|
81
|
-
|
82
|
-
|
83
|
-
class TSXExchangeCalendar(MarketCalendar):
|
84
|
-
"""
|
85
|
-
Exchange calendar for the Toronto Stock Exchange
|
86
|
-
|
87
|
-
Open Time: 9:30 AM, EST
|
88
|
-
Close Time: 4:00 PM, EST
|
89
|
-
|
90
|
-
Regularly-Observed Holidays:
|
91
|
-
- New Years Day (observed on first business day on/after)
|
92
|
-
- Family Day (Third Monday in February, starting in 2008)
|
93
|
-
- Good Friday
|
94
|
-
- Victoria Day (Monday before May 25th)
|
95
|
-
- Canada Day (July 1st, observed first business day after)
|
96
|
-
- Civic Holiday (First Monday in August)
|
97
|
-
- Labor Day (First Monday in September)
|
98
|
-
- Thanksgiving (Second Monday in October)
|
99
|
-
- Christmas Day
|
100
|
-
- Dec. 26th if Christmas is on a Sunday
|
101
|
-
- Dec. 27th if Christmas is on a weekend
|
102
|
-
- Boxing Day
|
103
|
-
- Dec. 27th if Christmas is on a Sunday
|
104
|
-
- Dec. 28th if Boxing Day is on a weekend
|
105
|
-
|
106
|
-
Early closes:
|
107
|
-
- Starting in 2010, if Christmas Eve falls on a weekday, the market
|
108
|
-
closes at 1:00 pm that day. If it falls on a weekend, there is no
|
109
|
-
early close.
|
110
|
-
"""
|
111
|
-
aliases = ['TSX', 'TSXV']
|
112
|
-
|
113
|
-
regular_market_times = {
|
114
|
-
"market_open": ((None, time(9, 30)),),
|
115
|
-
"market_close": ((None, time(16)),)
|
116
|
-
}
|
117
|
-
|
118
|
-
|
119
|
-
@property
|
120
|
-
def name(self):
|
121
|
-
return "TSX"
|
122
|
-
|
123
|
-
@property
|
124
|
-
def tz(self):
|
125
|
-
return timezone('Canada/Eastern')
|
126
|
-
|
127
|
-
regular_early_close = time(13)
|
128
|
-
|
129
|
-
@property
|
130
|
-
def regular_holidays(self):
|
131
|
-
return AbstractHolidayCalendar(rules=[
|
132
|
-
TSXNewYearsDay,
|
133
|
-
FamilyDay,
|
134
|
-
GoodFriday,
|
135
|
-
VictoriaDay,
|
136
|
-
CanadaDay,
|
137
|
-
CivicHoliday,
|
138
|
-
LaborDay,
|
139
|
-
Thanksgiving,
|
140
|
-
Christmas,
|
141
|
-
WeekendChristmas,
|
142
|
-
BoxingDay,
|
143
|
-
WeekendBoxingDay
|
144
|
-
])
|
145
|
-
|
146
|
-
@property
|
147
|
-
def adhoc_holidays(self):
|
148
|
-
return list(chain(
|
149
|
-
September11Closings2001,
|
150
|
-
))
|
151
|
-
|
152
|
-
@property
|
153
|
-
def special_closes(self):
|
154
|
-
return [
|
155
|
-
(
|
156
|
-
self.regular_early_close,
|
157
|
-
AbstractHolidayCalendar([ChristmasEveEarlyClose2010Onwards]),
|
158
|
-
)
|
159
|
-
]
|
@@ -1,114 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Imported calendars from the exchange_calendars project
|
3
|
-
|
4
|
-
GitHub: https://github.com/gerrymanoim/exchange_calendars
|
5
|
-
"""
|
6
|
-
|
7
|
-
from .market_calendar import MarketCalendar
|
8
|
-
import exchange_calendars
|
9
|
-
|
10
|
-
|
11
|
-
class TradingCalendar(MarketCalendar):
|
12
|
-
"""
|
13
|
-
This class provides access to all the information on opens, breaks and closes that are available
|
14
|
-
in the exchange_calendars package, it will receive the correctly formatted regular_market_times
|
15
|
-
dictionary in the for-loop below.
|
16
|
-
|
17
|
-
The initialization of calendars from exchange_calendars, is bypassed until the `.ec` property is used,
|
18
|
-
which returns the initialized exchange_calendar calendar, which is only initialized the first time.
|
19
|
-
"""
|
20
|
-
# flag indicating that offset still needs to be checked.
|
21
|
-
# A class attribute so we only do this once per class and not per instance
|
22
|
-
_FINALIZE_TRADING_CALENDAR = True
|
23
|
-
|
24
|
-
def __new__(cls, *args, **kwargs):
|
25
|
-
self = super().__new__(cls)
|
26
|
-
self._ec = super().__new__(cls._ec_class)
|
27
|
-
# flag indicating that mirrored class is not initialized yet, which we only want to do
|
28
|
-
# once per instance, if and only if the public `.ec` property is used.
|
29
|
-
self._EC_NOT_INITIALIZED = True
|
30
|
-
|
31
|
-
# offsets of exchange_calendar_mirrors are only available through the instance
|
32
|
-
if cls._FINALIZE_TRADING_CALENDAR:
|
33
|
-
if self._ec.open_offset:
|
34
|
-
cls.regular_market_times._set("market_open", tuple(
|
35
|
-
(t[0], t[1], self._ec.open_offset) for t in cls.regular_market_times["market_open"]))
|
36
|
-
|
37
|
-
if self._ec.close_offset:
|
38
|
-
cls.regular_market_times._set("market_close", tuple(
|
39
|
-
(t[0], t[1], self._ec.close_offset) for t in cls.regular_market_times["market_close"]))
|
40
|
-
cls._FINALIZE_TRADING_CALENDAR = False
|
41
|
-
|
42
|
-
self.__init__(*args, **kwargs)
|
43
|
-
return self
|
44
|
-
|
45
|
-
def __init__(self, open_time=None, close_time=None):
|
46
|
-
super().__init__(open_time, close_time)
|
47
|
-
|
48
|
-
@property
|
49
|
-
def ec(self):
|
50
|
-
if self._EC_NOT_INITIALIZED:
|
51
|
-
self._ec.__init__()
|
52
|
-
self._EC_NOT_INITIALIZED = False
|
53
|
-
|
54
|
-
return self._ec
|
55
|
-
|
56
|
-
@property
|
57
|
-
def name(self):
|
58
|
-
return self._ec.name
|
59
|
-
|
60
|
-
@property
|
61
|
-
def tz(self):
|
62
|
-
return self._ec.tz
|
63
|
-
|
64
|
-
@property
|
65
|
-
def regular_holidays(self):
|
66
|
-
return self._ec.regular_holidays
|
67
|
-
|
68
|
-
@property
|
69
|
-
def adhoc_holidays(self):
|
70
|
-
return self._ec.adhoc_holidays
|
71
|
-
|
72
|
-
@property
|
73
|
-
def special_opens(self):
|
74
|
-
return self._ec.special_opens
|
75
|
-
|
76
|
-
@property
|
77
|
-
def special_opens_adhoc(self):
|
78
|
-
return self._ec.special_opens_adhoc
|
79
|
-
|
80
|
-
@property
|
81
|
-
def special_closes(self):
|
82
|
-
return self._ec.special_closes
|
83
|
-
|
84
|
-
@property
|
85
|
-
def special_closes_adhoc(self):
|
86
|
-
return self._ec.special_closes_adhoc
|
87
|
-
|
88
|
-
|
89
|
-
calendars = exchange_calendars.calendar_utils._default_calendar_factories # noqa
|
90
|
-
|
91
|
-
time_props = dict(open_times= "market_open",
|
92
|
-
close_times= "market_close",
|
93
|
-
break_start_times= "break_start",
|
94
|
-
break_end_times= "break_end")
|
95
|
-
|
96
|
-
for exchange in calendars:
|
97
|
-
cal = calendars[exchange]
|
98
|
-
|
99
|
-
# this loop will set up the newly required regular_market_times dictionary
|
100
|
-
regular_market_times = {}
|
101
|
-
for prop, new in time_props.items():
|
102
|
-
times = getattr(cal, prop)
|
103
|
-
if times is None or isinstance(times, property): continue
|
104
|
-
regular_market_times[new] = times
|
105
|
-
|
106
|
-
cal = type(exchange, (TradingCalendar,), {'_ec_class': calendars[exchange],
|
107
|
-
'alias': [exchange],
|
108
|
-
'regular_market_times': regular_market_times})
|
109
|
-
locals()[exchange + 'ExchangeCalendar'] = cal
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|