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.
Files changed (47) hide show
  1. pandas_market_calendars/__init__.py +39 -38
  2. pandas_market_calendars/calendar_registry.py +57 -53
  3. pandas_market_calendars/calendar_utils.py +1200 -261
  4. pandas_market_calendars/calendars/asx.py +66 -66
  5. pandas_market_calendars/calendars/bmf.py +223 -206
  6. pandas_market_calendars/calendars/bse.py +421 -407
  7. pandas_market_calendars/calendars/cboe.py +145 -145
  8. pandas_market_calendars/calendars/cme.py +405 -402
  9. pandas_market_calendars/calendars/cme_globex_agriculture.py +172 -126
  10. pandas_market_calendars/calendars/cme_globex_base.py +119 -119
  11. pandas_market_calendars/calendars/cme_globex_crypto.py +160 -160
  12. pandas_market_calendars/calendars/cme_globex_energy_and_metals.py +216 -216
  13. pandas_market_calendars/calendars/cme_globex_equities.py +123 -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 +131 -139
  17. pandas_market_calendars/calendars/eurex_fixed_income.py +98 -98
  18. pandas_market_calendars/calendars/hkex.py +429 -426
  19. pandas_market_calendars/calendars/ice.py +81 -81
  20. pandas_market_calendars/calendars/iex.py +151 -112
  21. pandas_market_calendars/calendars/jpx.py +113 -109
  22. pandas_market_calendars/calendars/lse.py +114 -114
  23. pandas_market_calendars/calendars/mirror.py +149 -130
  24. pandas_market_calendars/calendars/nyse.py +1466 -1324
  25. pandas_market_calendars/calendars/ose.py +116 -116
  26. pandas_market_calendars/calendars/sifma.py +354 -350
  27. pandas_market_calendars/calendars/six.py +132 -132
  28. pandas_market_calendars/calendars/sse.py +311 -311
  29. pandas_market_calendars/calendars/tase.py +220 -197
  30. pandas_market_calendars/calendars/tsx.py +181 -181
  31. pandas_market_calendars/holidays/cme.py +385 -385
  32. pandas_market_calendars/holidays/cme_globex.py +214 -214
  33. pandas_market_calendars/holidays/cn.py +1476 -1455
  34. pandas_market_calendars/holidays/jp.py +401 -398
  35. pandas_market_calendars/holidays/jpx_equinox.py +1 -0
  36. pandas_market_calendars/holidays/nyse.py +1536 -1531
  37. pandas_market_calendars/holidays/oz.py +63 -63
  38. pandas_market_calendars/holidays/sifma.py +350 -338
  39. pandas_market_calendars/holidays/us.py +376 -376
  40. pandas_market_calendars/market_calendar.py +1057 -895
  41. {pandas_market_calendars-4.3.3.dist-info → pandas_market_calendars-4.6.0.dist-info}/METADATA +13 -9
  42. pandas_market_calendars-4.6.0.dist-info/RECORD +50 -0
  43. {pandas_market_calendars-4.3.3.dist-info → pandas_market_calendars-4.6.0.dist-info}/WHEEL +1 -1
  44. pandas_market_calendars-4.3.3.dist-info/RECORD +0 -50
  45. {pandas_market_calendars-4.3.3.dist-info → pandas_market_calendars-4.6.0.dist-info}/LICENSE +0 -0
  46. {pandas_market_calendars-4.3.3.dist-info → pandas_market_calendars-4.6.0.dist-info}/NOTICE +0 -0
  47. {pandas_market_calendars-4.3.3.dist-info → pandas_market_calendars-4.6.0.dist-info}/top_level.txt +0 -0
@@ -1,426 +1,429 @@
1
- from datetime import time, timedelta
2
- from functools import partial
3
-
4
- from pandas import DateOffset, Timestamp
5
- from pandas.tseries.holiday import (
6
- AbstractHolidayCalendar,
7
- EasterMonday,
8
- GoodFriday,
9
- Holiday,
10
- sunday_to_monday,
11
- )
12
- from pandas.tseries.offsets import LastWeekOfMonth, WeekOfMonth
13
- from pytz import timezone
14
-
15
- from pandas_market_calendars.holidays.cn import (
16
- bsd_mapping,
17
- dbf_mapping,
18
- dnf_mapping,
19
- maf_mapping,
20
- sf_mapping,
21
- tsd_mapping,
22
- )
23
- from pandas_market_calendars.holidays.us import USNewYearsDay
24
- from pandas_market_calendars.market_calendar import MarketCalendar
25
-
26
-
27
- def process_date(dt, mapping=None, func=None, delta=None, offset=None):
28
- if mapping and (dt.year in mapping):
29
- new_dt = mapping[dt.year]
30
- else:
31
- new_dt = dt
32
- if delta:
33
- new_dt = new_dt + timedelta(delta)
34
- dow = new_dt.weekday()
35
- if dow == 6 and offset: # sunday
36
- new_dt = new_dt + timedelta(offset)
37
- if func:
38
- return func(new_dt)
39
- return new_dt
40
-
41
-
42
- def process_queen_birthday(dt):
43
- # before 1983
44
- if dt.year in [1974, 1981]:
45
- return dt + DateOffset(weekday=6)
46
- elif dt.year < 1983:
47
- return sunday_to_monday(dt)
48
- # after 1983
49
- wom = WeekOfMonth(week=2, weekday=0)
50
- if dt.year in [1983, 1988, 1993, 1994]:
51
- wom = WeekOfMonth(week=1, weekday=0)
52
- if dt.year in [1985]:
53
- wom = WeekOfMonth(week=3, weekday=0)
54
- return dt + wom
55
-
56
-
57
- HKNewYearsDay = USNewYearsDay
58
-
59
- SpringFestivalDayBefore1983 = Holiday(
60
- name="Spring Festival",
61
- month=1,
62
- day=21,
63
- observance=partial(process_date, mapping=sf_mapping, delta=0, offset=3),
64
- start_date=Timestamp("1961-01-01"),
65
- end_date=Timestamp("1983-01-01"),
66
- )
67
-
68
- SpringFestivalDay2Before1983 = Holiday(
69
- name="Spring Festival",
70
- month=1,
71
- day=21,
72
- observance=partial(process_date, mapping=sf_mapping, delta=1, offset=2),
73
- start_date=Timestamp("1961-01-01"),
74
- end_date=Timestamp("1983-01-01"),
75
- )
76
-
77
- SpringFestivalDay3Before1983 = Holiday(
78
- name="Spring Festival",
79
- month=1,
80
- day=21,
81
- observance=partial(process_date, mapping=sf_mapping, delta=2, offset=1),
82
- start_date=Timestamp("1961-01-01"),
83
- end_date=Timestamp("1983-01-01"),
84
- )
85
-
86
- SpringFestivalDayBefore2010 = Holiday(
87
- name="Spring Festival",
88
- month=1,
89
- day=21,
90
- observance=partial(process_date, mapping=sf_mapping, delta=0, offset=-1),
91
- start_date=Timestamp("1983-01-01"),
92
- end_date=Timestamp("2010-07-01"),
93
- )
94
-
95
- SpringFestivalDay2Before2010 = Holiday(
96
- name="Spring Festival",
97
- month=1,
98
- day=21,
99
- observance=partial(process_date, mapping=sf_mapping, delta=1, offset=-2),
100
- start_date=Timestamp("1983-01-01"),
101
- end_date=Timestamp("2010-07-01"),
102
- )
103
-
104
- SpringFestivalDay3Before2010 = Holiday(
105
- name="Spring Festival",
106
- month=1,
107
- day=21,
108
- observance=partial(process_date, mapping=sf_mapping, delta=2, offset=-3),
109
- start_date=Timestamp("1983-01-01"),
110
- end_date=Timestamp("2010-07-01"),
111
- )
112
-
113
- SpringFestivalDay = Holiday(
114
- name="Spring Festival",
115
- month=1,
116
- day=21,
117
- observance=partial(process_date, mapping=sf_mapping, delta=0, offset=3),
118
- start_date=Timestamp("2010-07-01"),
119
- )
120
-
121
- SpringFestivalDay2 = Holiday(
122
- name="Spring Festival",
123
- month=1,
124
- day=21,
125
- observance=partial(process_date, mapping=sf_mapping, delta=1, offset=2),
126
- start_date=Timestamp("2010-07-01"),
127
- )
128
-
129
- SpringFestivalDay3 = Holiday(
130
- name="Spring Festival",
131
- month=1,
132
- day=21,
133
- observance=partial(process_date, mapping=sf_mapping, delta=2, offset=1),
134
- start_date=Timestamp("2010-07-01"),
135
- )
136
-
137
- TombSweepingDay = Holiday(
138
- name="Tomb-sweeping Day", # 清明节4月5日
139
- month=4,
140
- day=4,
141
- observance=partial(process_date, mapping=tsd_mapping, func=sunday_to_monday),
142
- start_date=Timestamp("1961-01-01"),
143
- )
144
-
145
- LabourDay = Holiday(
146
- name="Labour Day", # 劳动节
147
- month=5,
148
- day=1,
149
- observance=sunday_to_monday,
150
- start_date=Timestamp("1999-05-01"),
151
- )
152
-
153
- BuddhaShakyamuniDay = Holiday(
154
- name="Buddha Shakyamuni Day", # 浴佛节 98年农历4月8日定为法定假日
155
- month=4,
156
- day=28,
157
- observance=partial(process_date, mapping=bsd_mapping, func=sunday_to_monday),
158
- start_date=Timestamp("1999-04-28"),
159
- )
160
-
161
- DragonBoatFestivalDay = Holiday(
162
- name="Dragon Boat Festival", # 端午节
163
- month=5,
164
- day=27,
165
- observance=partial(process_date, mapping=dbf_mapping, func=sunday_to_monday),
166
- start_date=Timestamp("1961-01-01"),
167
- )
168
-
169
- HKRegionEstablishmentDay = Holiday(
170
- name="Hong Kong Special Region Establishment Day",
171
- month=7,
172
- day=1,
173
- observance=sunday_to_monday,
174
- start_date=Timestamp("1997-07-01"),
175
- )
176
-
177
- MidAutumnFestivalDayBefore1983 = Holiday(
178
- name="Mid-autumn Festival", # 中秋节翌日
179
- month=9,
180
- day=7,
181
- observance=partial(
182
- process_date, mapping=maf_mapping, delta=1, func=sunday_to_monday
183
- ),
184
- start_date=Timestamp("1961-01-01"),
185
- end_date=Timestamp("1983-01-01"),
186
- )
187
-
188
- MidAutumnFestivalDayBefore2010 = Holiday(
189
- name="Mid-autumn Festival", # 中秋节翌日
190
- month=9,
191
- day=7,
192
- observance=partial(process_date, mapping=maf_mapping, delta=1, offset=-1),
193
- start_date=Timestamp("1983-01-01"),
194
- end_date=Timestamp("2010-12-31"),
195
- )
196
-
197
- MidAutumnFestivalDay = Holiday(
198
- name="Mid-autumn Festival", # 中秋节翌日
199
- month=9,
200
- day=7,
201
- observance=partial(
202
- process_date, mapping=maf_mapping, delta=1, func=sunday_to_monday
203
- ),
204
- start_date=Timestamp("2011-01-01"),
205
- )
206
-
207
- DoubleNinthFestivalDay = Holiday(
208
- name="Double Ninth Festival", # 重阳节
209
- month=10,
210
- day=2,
211
- observance=partial(process_date, mapping=dnf_mapping, func=sunday_to_monday),
212
- start_date=Timestamp("1961-01-01"),
213
- )
214
-
215
- NationalDay = Holiday(
216
- name="National Day",
217
- month=10,
218
- day=1,
219
- observance=sunday_to_monday,
220
- start_date=Timestamp("1997-07-01"),
221
- )
222
-
223
- Christmas = Holiday(
224
- name="Christmas",
225
- month=12,
226
- day=25,
227
- observance=partial(process_date, offset=2),
228
- start_date=Timestamp("1954-01-01"),
229
- )
230
-
231
- BoxingDay = Holiday(
232
- name="Boxing day", # 圣诞节后第一个平日
233
- month=12,
234
- day=26,
235
- observance=sunday_to_monday,
236
- start_date=Timestamp("1954-01-01"),
237
- )
238
-
239
- QueenBirthday = Holiday(
240
- name="Queen's Birthday", # 英女王生日 6月
241
- month=6,
242
- day=10,
243
- observance=process_queen_birthday,
244
- start_date=Timestamp("1983-01-01"),
245
- end_date=Timestamp("1997-06-01"),
246
- )
247
-
248
- QueenBirthday2 = Holiday(
249
- name="Queen's Birthday", # 英女王生日 4月
250
- month=4,
251
- day=21,
252
- observance=process_queen_birthday,
253
- start_date=Timestamp("1926-04-21"),
254
- end_date=Timestamp("1983-01-01"),
255
- )
256
-
257
- CommemoratingAlliedVictory = Holiday(
258
- name="Commemorating the allied victory", # 重光纪念日 8月最后一个星期一
259
- month=8,
260
- day=20,
261
- offset=LastWeekOfMonth(weekday=0),
262
- start_date=Timestamp("1945-08-30"),
263
- end_date=Timestamp("1997-07-01"),
264
- )
265
-
266
- IDontKnow = Holiday(
267
- name="I dont know these days, please tell me", # 8月第一个星期一
268
- month=7,
269
- day=31,
270
- offset=WeekOfMonth(week=0, weekday=0),
271
- start_date=Timestamp("1960-08-01"),
272
- end_date=Timestamp("1983-01-01"),
273
- )
274
-
275
- HKClosedDay = [
276
- # I dont know these days
277
- Timestamp("1970-07-01", tz="UTC"),
278
- Timestamp("1971-07-01", tz="UTC"),
279
- Timestamp("1973-07-02", tz="UTC"),
280
- Timestamp("1974-07-01", tz="UTC"),
281
- Timestamp("1975-07-01", tz="UTC"),
282
- Timestamp("1976-07-01", tz="UTC"),
283
- Timestamp("1977-07-01", tz="UTC"),
284
- Timestamp("1979-07-02", tz="UTC"),
285
- Timestamp("1980-07-01", tz="UTC"),
286
- Timestamp("1981-07-01", tz="UTC"),
287
- Timestamp("1982-07-01", tz="UTC"),
288
- Timestamp("1971-03-22", tz="UTC"),
289
- Timestamp("1971-12-06", tz="UTC"),
290
- Timestamp("1971-12-20", tz="UTC"),
291
- Timestamp("1975-07-28", tz="UTC"),
292
- Timestamp("1985-07-29", tz="UTC"),
293
- Timestamp("1970-07-16", tz="UTC"), # 台风Ruby7003
294
- Timestamp("1970-09-14", tz="UTC"), # 台风Georgia7011
295
- Timestamp("1971-07-22", tz="UTC"), # 台风Lucy7114
296
- Timestamp("1971-08-31", tz="UTC"), # 重光纪念日?
297
- Timestamp("1973-04-16", tz="UTC"), # 股灾休市?
298
- Timestamp("1973-07-17", tz="UTC"), # 台风Dot7304
299
- Timestamp("1974-04-25", tz="UTC"), # 英国女王生日
300
- Timestamp("1975-10-14", tz="UTC"), # 台风Elsie7514
301
- Timestamp("1978-07-26", tz="UTC"), # 台风Agnes7807
302
- Timestamp("1978-07-27", tz="UTC"),
303
- Timestamp("1979-01-26", tz="UTC"), # 春节补假
304
- Timestamp("1979-08-02", tz="UTC"), # 台风Hope7908
305
- Timestamp("1980-05-21", tz="UTC"), # 台风Georgia8004
306
- Timestamp("1980-07-22", tz="UTC"), # 台风Joy8007
307
- Timestamp("1981-04-27", tz="UTC"), # 英国女王生日
308
- Timestamp("1981-07-06", tz="UTC"), # 台风Lynn8106
309
- Timestamp("1981-07-07", tz="UTC"),
310
- Timestamp("1981-07-29", tz="UTC"), # 查理斯王子与戴安娜婚礼
311
- Timestamp("1983-09-09", tz="UTC"), # 台风Ellen8309
312
- Timestamp("1985-06-24", tz="UTC"), # 台风Hal8504
313
- Timestamp("1986-04-01", tz="UTC"), # 复活节星期一翌日
314
- Timestamp("1986-10-22", tz="UTC"), # 英女王伊丽莎白二世访港
315
- Timestamp("1987-10-20", tz="UTC"), # 黑色星期一后,休市4天
316
- Timestamp("1987-10-21", tz="UTC"),
317
- Timestamp("1987-10-22", tz="UTC"),
318
- Timestamp("1987-10-23", tz="UTC"),
319
- Timestamp("1988-04-05", tz="UTC"), # 清明节翌日
320
- # Timestamp('1988-06-13', tz='UTC'), # 英国女王生日
321
- Timestamp("1991-06-18", tz="UTC"), # 英国女王生日翌日
322
- Timestamp("1992-07-22", tz="UTC"), # 台风Cary9207
323
- # Timestamp('1993-06-14', tz='UTC'), # 英国女王生日
324
- Timestamp("1993-09-17", tz="UTC"), # 台风Becky9316
325
- Timestamp("1994-06-14", tz="UTC"), # 英国女王生日翌日,端午节翌日
326
- Timestamp("1997-06-30", tz="UTC"), # 英国女王生日
327
- Timestamp("1997-07-02", tz="UTC"), # 香港回归纪念日翌日
328
- Timestamp("1997-08-18", tz="UTC"), # 抗战胜利纪念日
329
- Timestamp("1997-10-02", tz="UTC"), # 国庆节翌日
330
- Timestamp("1998-08-17", tz="UTC"), # 抗战胜利纪念日
331
- Timestamp("1998-10-02", tz="UTC"), # 国庆节翌日
332
- Timestamp("1999-04-06", tz="UTC"), # 清明节翌日
333
- Timestamp("1999-09-16", tz="UTC"), # 台风约克
334
- Timestamp("1999-12-31", tz="UTC"), # 千年虫
335
- Timestamp("2001-07-06", tz="UTC"), # 台风尤特0104
336
- Timestamp("2001-07-25", tz="UTC"), # 台风玉兔0107
337
- # Timestamp(2008-06-25', tz='UTC'), # 台风风神0806,上午休市
338
- Timestamp("2008-08-06", tz="UTC"), # 台风北冕0809
339
- Timestamp("2008-08-22", tz="UTC"), # 台风鹦鹉0810
340
- # Timestamp(2009-09-15', tz='UTC'), # 台风巨爵0915,上午休市
341
- Timestamp("2010-04-06", tz="UTC"), # 清明节翌日
342
- Timestamp("2011-09-29", tz="UTC"), # 台风纳沙1117
343
- # Timestamp(2012-07-24', tz='UTC'), # 台风韦森特1208,上午休市
344
- Timestamp("2012-10-02", tz="UTC"), # 中秋节补假
345
- # Timestamp(2013-05-22', tz='UTC'), # 暴雨,上午休市
346
- Timestamp("2013-08-14", tz="UTC"), # 台风尤特1311
347
- # Timestamp(2013-09-23', tz='UTC'), # 台风天兔1319,上午休市
348
- # Timestamp(2014-09-16', tz='UTC'), # 台风海鸥1415,上午休市
349
- Timestamp("2015-04-07", tz="UTC"), # 复活节+清明节补假
350
- # Timestamp(2015-07-09', tz='UTC'), # 台风莲花1520,期货夜盘休市
351
- Timestamp("2015-09-03", tz="UTC"), # 抗战70周年纪念
352
- # Timestamp(2016-08-01', tz='UTC'), # 台风妮妲1604,期货夜盘20:55收市
353
- Timestamp("2016-08-02", tz="UTC"), # 台风妮妲1604
354
- Timestamp("2016-10-21", tz="UTC"), # 台风海马1622
355
- # Timestamp(2017-06-12', tz='UTC'), # 台风苗柏1702,期货夜盘17:35休市
356
- Timestamp("2017-08-23", tz="UTC"), # 台风天鸽1713
357
- ]
358
-
359
-
360
- class HKEXExchangeCalendar(MarketCalendar):
361
- """
362
- Exchange calendar for Hong Kong Stock Exchange
363
-
364
- Open Time: 9:30 AM, Asia/Shanghai
365
- LUNCH BREAK :facepalm: : 12:00 AM - 1:00 PM Asia/Shanghai
366
- Close Time: 4:00 PM, Asia/Shanghai
367
- """
368
-
369
- aliases = ["HKEX"]
370
- regular_market_times = {
371
- "market_open": ((None, time(9, 30)),),
372
- "market_close": ((None, time(16)),),
373
- "break_start": ((None, time(12)),),
374
- "break_end": ((None, time(13)),),
375
- }
376
-
377
- @property
378
- def name(self):
379
- return "HKEX"
380
-
381
- @property
382
- def tz(self):
383
- return timezone("Asia/Shanghai")
384
-
385
- @property
386
- def regular_holidays(self):
387
- """
388
- Rules are guesses based on observations of recent year.
389
- Rectify accordingly once the next year's holidays arrangement is published by the government.
390
- """
391
- return AbstractHolidayCalendar(
392
- rules=[
393
- HKNewYearsDay,
394
- SpringFestivalDayBefore1983,
395
- SpringFestivalDay2Before1983,
396
- SpringFestivalDay3Before1983,
397
- SpringFestivalDayBefore2010,
398
- SpringFestivalDay2Before2010,
399
- SpringFestivalDay3Before2010,
400
- SpringFestivalDay,
401
- SpringFestivalDay2,
402
- SpringFestivalDay3,
403
- GoodFriday,
404
- EasterMonday,
405
- TombSweepingDay,
406
- LabourDay,
407
- BuddhaShakyamuniDay,
408
- DragonBoatFestivalDay,
409
- HKRegionEstablishmentDay,
410
- MidAutumnFestivalDayBefore1983,
411
- MidAutumnFestivalDayBefore2010,
412
- MidAutumnFestivalDay,
413
- NationalDay,
414
- DoubleNinthFestivalDay,
415
- Christmas,
416
- BoxingDay,
417
- CommemoratingAlliedVictory,
418
- QueenBirthday,
419
- QueenBirthday2,
420
- IDontKnow,
421
- ]
422
- )
423
-
424
- @property
425
- def adhoc_holidays(self):
426
- return HKClosedDay
1
+ from datetime import time, timedelta
2
+ from functools import partial
3
+
4
+ from pandas import DateOffset, Timestamp
5
+ from pandas.tseries.holiday import (
6
+ AbstractHolidayCalendar,
7
+ EasterMonday,
8
+ GoodFriday,
9
+ Holiday,
10
+ sunday_to_monday,
11
+ )
12
+ from pandas.tseries.offsets import LastWeekOfMonth, WeekOfMonth
13
+ from pytz import timezone
14
+
15
+ from pandas_market_calendars.holidays.cn import (
16
+ bsd_mapping,
17
+ dbf_mapping,
18
+ dnf_mapping,
19
+ maf_mapping,
20
+ sf_mapping,
21
+ tsd_mapping,
22
+ )
23
+ from pandas_market_calendars.holidays.us import USNewYearsDay
24
+ from pandas_market_calendars.market_calendar import MarketCalendar
25
+
26
+
27
+ def process_date(dt, mapping=None, func=None, delta=None, offset=None):
28
+ if mapping and (dt.year in mapping):
29
+ new_dt = mapping[dt.year]
30
+ else:
31
+ new_dt = dt
32
+ if delta:
33
+ new_dt = new_dt + timedelta(delta)
34
+ dow = new_dt.weekday()
35
+ if dow == 6 and offset: # sunday
36
+ new_dt = new_dt + timedelta(offset)
37
+ if func:
38
+ return func(new_dt)
39
+ return new_dt
40
+
41
+
42
+ def process_queen_birthday(dt):
43
+ # before 1983
44
+ if dt.year in [1974, 1981]:
45
+ return dt + DateOffset(weekday=6)
46
+ elif dt.year < 1983:
47
+ return sunday_to_monday(dt)
48
+ # after 1983
49
+ wom = WeekOfMonth(week=2, weekday=0)
50
+ if dt.year in [1983, 1988, 1993, 1994]:
51
+ wom = WeekOfMonth(week=1, weekday=0)
52
+ if dt.year in [1985]:
53
+ wom = WeekOfMonth(week=3, weekday=0)
54
+ return dt + wom
55
+
56
+
57
+ HKNewYearsDay = USNewYearsDay
58
+
59
+ SpringFestivalDayBefore1983 = Holiday(
60
+ name="Spring Festival",
61
+ month=1,
62
+ day=21,
63
+ observance=partial(process_date, mapping=sf_mapping, delta=0, offset=3),
64
+ start_date=Timestamp("1961-01-01"),
65
+ end_date=Timestamp("1983-01-01"),
66
+ )
67
+
68
+ SpringFestivalDay2Before1983 = Holiday(
69
+ name="Spring Festival",
70
+ month=1,
71
+ day=21,
72
+ observance=partial(process_date, mapping=sf_mapping, delta=1, offset=2),
73
+ start_date=Timestamp("1961-01-01"),
74
+ end_date=Timestamp("1983-01-01"),
75
+ )
76
+
77
+ SpringFestivalDay3Before1983 = Holiday(
78
+ name="Spring Festival",
79
+ month=1,
80
+ day=21,
81
+ observance=partial(process_date, mapping=sf_mapping, delta=2, offset=1),
82
+ start_date=Timestamp("1961-01-01"),
83
+ end_date=Timestamp("1983-01-01"),
84
+ )
85
+
86
+ SpringFestivalDayBefore2010 = Holiday(
87
+ name="Spring Festival",
88
+ month=1,
89
+ day=21,
90
+ observance=partial(process_date, mapping=sf_mapping, delta=0, offset=-1),
91
+ start_date=Timestamp("1983-01-01"),
92
+ end_date=Timestamp("2010-07-01"),
93
+ )
94
+
95
+ SpringFestivalDay2Before2010 = Holiday(
96
+ name="Spring Festival",
97
+ month=1,
98
+ day=21,
99
+ observance=partial(process_date, mapping=sf_mapping, delta=1, offset=-2),
100
+ start_date=Timestamp("1983-01-01"),
101
+ end_date=Timestamp("2010-07-01"),
102
+ )
103
+
104
+ SpringFestivalDay3Before2010 = Holiday(
105
+ name="Spring Festival",
106
+ month=1,
107
+ day=21,
108
+ observance=partial(process_date, mapping=sf_mapping, delta=2, offset=-3),
109
+ start_date=Timestamp("1983-01-01"),
110
+ end_date=Timestamp("2010-07-01"),
111
+ )
112
+
113
+ SpringFestivalDay = Holiday(
114
+ name="Spring Festival",
115
+ month=1,
116
+ day=21,
117
+ observance=partial(process_date, mapping=sf_mapping, delta=0, offset=3),
118
+ start_date=Timestamp("2010-07-01"),
119
+ )
120
+
121
+ SpringFestivalDay2 = Holiday(
122
+ name="Spring Festival",
123
+ month=1,
124
+ day=21,
125
+ observance=partial(process_date, mapping=sf_mapping, delta=1, offset=2),
126
+ start_date=Timestamp("2010-07-01"),
127
+ )
128
+
129
+ SpringFestivalDay3 = Holiday(
130
+ name="Spring Festival",
131
+ month=1,
132
+ day=21,
133
+ observance=partial(process_date, mapping=sf_mapping, delta=2, offset=1),
134
+ start_date=Timestamp("2010-07-01"),
135
+ )
136
+
137
+ TombSweepingDay = Holiday(
138
+ name="Tomb-sweeping Day", # 清明节4月5日
139
+ month=4,
140
+ day=4,
141
+ observance=partial(process_date, mapping=tsd_mapping, func=sunday_to_monday),
142
+ start_date=Timestamp("1961-01-01"),
143
+ )
144
+
145
+ LabourDay = Holiday(
146
+ name="Labour Day", # 劳动节
147
+ month=5,
148
+ day=1,
149
+ observance=sunday_to_monday,
150
+ start_date=Timestamp("1999-05-01"),
151
+ )
152
+
153
+ BuddhaShakyamuniDay = Holiday(
154
+ name="Buddha Shakyamuni Day", # 浴佛节 98年农历4月8日定为法定假日
155
+ month=4,
156
+ day=28,
157
+ observance=partial(process_date, mapping=bsd_mapping, func=sunday_to_monday),
158
+ start_date=Timestamp("1999-04-28"),
159
+ )
160
+
161
+ DragonBoatFestivalDay = Holiday(
162
+ name="Dragon Boat Festival", # 端午节
163
+ month=5,
164
+ day=27,
165
+ observance=partial(process_date, mapping=dbf_mapping, func=sunday_to_monday),
166
+ start_date=Timestamp("1961-01-01"),
167
+ )
168
+
169
+ HKRegionEstablishmentDay = Holiday(
170
+ name="Hong Kong Special Region Establishment Day",
171
+ month=7,
172
+ day=1,
173
+ observance=sunday_to_monday,
174
+ start_date=Timestamp("1997-07-01"),
175
+ )
176
+
177
+ MidAutumnFestivalDayBefore1983 = Holiday(
178
+ name="Mid-autumn Festival", # 中秋节翌日
179
+ month=9,
180
+ day=7,
181
+ observance=partial(
182
+ process_date, mapping=maf_mapping, delta=1, func=sunday_to_monday
183
+ ),
184
+ start_date=Timestamp("1961-01-01"),
185
+ end_date=Timestamp("1983-01-01"),
186
+ )
187
+
188
+ MidAutumnFestivalDayBefore2010 = Holiday(
189
+ name="Mid-autumn Festival", # 中秋节翌日
190
+ month=9,
191
+ day=7,
192
+ observance=partial(process_date, mapping=maf_mapping, delta=1, offset=-1),
193
+ start_date=Timestamp("1983-01-01"),
194
+ end_date=Timestamp("2010-12-31"),
195
+ )
196
+
197
+ MidAutumnFestivalDay = Holiday(
198
+ name="Mid-autumn Festival", # 中秋节翌日
199
+ month=9,
200
+ day=7,
201
+ observance=partial(
202
+ process_date, mapping=maf_mapping, delta=1, func=sunday_to_monday
203
+ ),
204
+ start_date=Timestamp("2011-01-01"),
205
+ )
206
+
207
+ DoubleNinthFestivalDay = Holiday(
208
+ name="Double Ninth Festival", # 重阳节
209
+ month=10,
210
+ day=2,
211
+ observance=partial(process_date, mapping=dnf_mapping, func=sunday_to_monday),
212
+ start_date=Timestamp("1961-01-01"),
213
+ )
214
+
215
+ NationalDay = Holiday(
216
+ name="National Day",
217
+ month=10,
218
+ day=1,
219
+ observance=sunday_to_monday,
220
+ start_date=Timestamp("1997-07-01"),
221
+ )
222
+
223
+ Christmas = Holiday(
224
+ name="Christmas",
225
+ month=12,
226
+ day=25,
227
+ observance=partial(process_date, offset=2),
228
+ start_date=Timestamp("1954-01-01"),
229
+ )
230
+
231
+ BoxingDay = Holiday(
232
+ name="Boxing day", # 圣诞节后第一个平日
233
+ month=12,
234
+ day=26,
235
+ observance=sunday_to_monday,
236
+ start_date=Timestamp("1954-01-01"),
237
+ )
238
+
239
+ QueenBirthday = Holiday(
240
+ name="Queen's Birthday", # 英女王生日 6月
241
+ month=6,
242
+ day=10,
243
+ observance=process_queen_birthday,
244
+ start_date=Timestamp("1983-01-01"),
245
+ end_date=Timestamp("1997-06-01"),
246
+ )
247
+
248
+ QueenBirthday2 = Holiday(
249
+ name="Queen's Birthday", # 英女王生日 4月
250
+ month=4,
251
+ day=21,
252
+ observance=process_queen_birthday,
253
+ start_date=Timestamp("1926-04-21"),
254
+ end_date=Timestamp("1983-01-01"),
255
+ )
256
+
257
+ CommemoratingAlliedVictory = Holiday(
258
+ name="Commemorating the allied victory", # 重光纪念日 8月最后一个星期一
259
+ month=8,
260
+ day=20,
261
+ offset=LastWeekOfMonth(weekday=0),
262
+ start_date=Timestamp("1945-08-30"),
263
+ end_date=Timestamp("1997-07-01"),
264
+ )
265
+
266
+ IDontKnow = Holiday(
267
+ name="I dont know these days, please tell me", # 8月第一个星期一
268
+ month=7,
269
+ day=31,
270
+ offset=WeekOfMonth(week=0, weekday=0),
271
+ start_date=Timestamp("1960-08-01"),
272
+ end_date=Timestamp("1983-01-01"),
273
+ )
274
+
275
+ HKClosedDay = [
276
+ # I dont know these days
277
+ Timestamp("1970-07-01", tz="UTC"),
278
+ Timestamp("1971-07-01", tz="UTC"),
279
+ Timestamp("1973-07-02", tz="UTC"),
280
+ Timestamp("1974-07-01", tz="UTC"),
281
+ Timestamp("1975-07-01", tz="UTC"),
282
+ Timestamp("1976-07-01", tz="UTC"),
283
+ Timestamp("1977-07-01", tz="UTC"),
284
+ Timestamp("1979-07-02", tz="UTC"),
285
+ Timestamp("1980-07-01", tz="UTC"),
286
+ Timestamp("1981-07-01", tz="UTC"),
287
+ Timestamp("1982-07-01", tz="UTC"),
288
+ Timestamp("1971-03-22", tz="UTC"),
289
+ Timestamp("1971-12-06", tz="UTC"),
290
+ Timestamp("1971-12-20", tz="UTC"),
291
+ Timestamp("1975-07-28", tz="UTC"),
292
+ Timestamp("1985-07-29", tz="UTC"),
293
+ Timestamp("1970-07-16", tz="UTC"), # 台风Ruby7003
294
+ Timestamp("1970-09-14", tz="UTC"), # 台风Georgia7011
295
+ Timestamp("1971-07-22", tz="UTC"), # 台风Lucy7114
296
+ Timestamp("1971-08-31", tz="UTC"), # 重光纪念日?
297
+ Timestamp("1973-04-16", tz="UTC"), # 股灾休市?
298
+ Timestamp("1973-07-17", tz="UTC"), # 台风Dot7304
299
+ Timestamp("1974-04-25", tz="UTC"), # 英国女王生日
300
+ Timestamp("1975-10-14", tz="UTC"), # 台风Elsie7514
301
+ Timestamp("1978-07-26", tz="UTC"), # 台风Agnes7807
302
+ Timestamp("1978-07-27", tz="UTC"),
303
+ Timestamp("1979-01-26", tz="UTC"), # 春节补假
304
+ Timestamp("1979-08-02", tz="UTC"), # 台风Hope7908
305
+ Timestamp("1980-05-21", tz="UTC"), # 台风Georgia8004
306
+ Timestamp("1980-07-22", tz="UTC"), # 台风Joy8007
307
+ Timestamp("1981-04-27", tz="UTC"), # 英国女王生日
308
+ Timestamp("1981-07-06", tz="UTC"), # 台风Lynn8106
309
+ Timestamp("1981-07-07", tz="UTC"),
310
+ Timestamp("1981-07-29", tz="UTC"), # 查理斯王子与戴安娜婚礼
311
+ Timestamp("1983-09-09", tz="UTC"), # 台风Ellen8309
312
+ Timestamp("1985-06-24", tz="UTC"), # 台风Hal8504
313
+ Timestamp("1986-04-01", tz="UTC"), # 复活节星期一翌日
314
+ Timestamp("1986-10-22", tz="UTC"), # 英女王伊丽莎白二世访港
315
+ Timestamp("1987-10-20", tz="UTC"), # 黑色星期一后,休市4天
316
+ Timestamp("1987-10-21", tz="UTC"),
317
+ Timestamp("1987-10-22", tz="UTC"),
318
+ Timestamp("1987-10-23", tz="UTC"),
319
+ Timestamp("1988-04-05", tz="UTC"), # 清明节翌日
320
+ # Timestamp('1988-06-13', tz='UTC'), # 英国女王生日
321
+ Timestamp("1991-06-18", tz="UTC"), # 英国女王生日翌日
322
+ Timestamp("1992-07-22", tz="UTC"), # 台风Cary9207
323
+ # Timestamp('1993-06-14', tz='UTC'), # 英国女王生日
324
+ Timestamp("1993-09-17", tz="UTC"), # 台风Becky9316
325
+ Timestamp("1994-06-14", tz="UTC"), # 英国女王生日翌日,端午节翌日
326
+ Timestamp("1997-06-30", tz="UTC"), # 英国女王生日
327
+ Timestamp("1997-07-02", tz="UTC"), # 香港回归纪念日翌日
328
+ Timestamp("1997-08-18", tz="UTC"), # 抗战胜利纪念日
329
+ Timestamp("1997-10-02", tz="UTC"), # 国庆节翌日
330
+ Timestamp("1998-08-17", tz="UTC"), # 抗战胜利纪念日
331
+ Timestamp("1998-10-02", tz="UTC"), # 国庆节翌日
332
+ Timestamp("1999-04-06", tz="UTC"), # 清明节翌日
333
+ Timestamp("1999-09-16", tz="UTC"), # 台风约克
334
+ Timestamp("1999-12-31", tz="UTC"), # 千年虫
335
+ Timestamp("2001-07-06", tz="UTC"), # 台风尤特0104
336
+ Timestamp("2001-07-25", tz="UTC"), # 台风玉兔0107
337
+ # Timestamp(2008-06-25', tz='UTC'), # 台风风神0806,上午休市
338
+ Timestamp("2008-08-06", tz="UTC"), # 台风北冕0809
339
+ Timestamp("2008-08-22", tz="UTC"), # 台风鹦鹉0810
340
+ # Timestamp(2009-09-15', tz='UTC'), # 台风巨爵0915,上午休市
341
+ Timestamp("2010-04-06", tz="UTC"), # 清明节翌日
342
+ Timestamp("2011-09-29", tz="UTC"), # 台风纳沙1117
343
+ # Timestamp(2012-07-24', tz='UTC'), # 台风韦森特1208,上午休市
344
+ Timestamp("2012-10-02", tz="UTC"), # 中秋节补假
345
+ # Timestamp(2013-05-22', tz='UTC'), # 暴雨,上午休市
346
+ Timestamp("2013-08-14", tz="UTC"), # 台风尤特1311
347
+ # Timestamp(2013-09-23', tz='UTC'), # 台风天兔1319,上午休市
348
+ # Timestamp(2014-09-16', tz='UTC'), # 台风海鸥1415,上午休市
349
+ Timestamp("2015-04-07", tz="UTC"), # 复活节+清明节补假
350
+ # Timestamp(2015-07-09', tz='UTC'), # 台风莲花1520,期货夜盘休市
351
+ Timestamp("2015-09-03", tz="UTC"), # 抗战70周年纪念
352
+ # Timestamp(2016-08-01', tz='UTC'), # 台风妮妲1604,期货夜盘20:55收市
353
+ Timestamp("2016-08-02", tz="UTC"), # 台风妮妲1604
354
+ Timestamp("2016-10-21", tz="UTC"), # 台风海马1622
355
+ # Timestamp(2017-06-12', tz='UTC'), # 台风苗柏1702,期货夜盘17:35休市
356
+ Timestamp("2017-08-23", tz="UTC"), # 台风天鸽1713
357
+ Timestamp("2023-07-17", tz="UTC"), # Typhoon closure
358
+ Timestamp("2023-09-01", tz="UTC"), # Typhoon closure
359
+ Timestamp("2023-09-08", tz="UTC"), # Typhoon closure
360
+ ]
361
+
362
+
363
+ class HKEXExchangeCalendar(MarketCalendar):
364
+ """
365
+ Exchange calendar for Hong Kong Stock Exchange
366
+
367
+ Open Time: 9:30 AM, Asia/Shanghai
368
+ LUNCH BREAK :facepalm: : 12:00 AM - 1:00 PM Asia/Shanghai
369
+ Close Time: 4:00 PM, Asia/Shanghai
370
+ """
371
+
372
+ aliases = ["HKEX"]
373
+ regular_market_times = {
374
+ "market_open": ((None, time(9, 30)),),
375
+ "market_close": ((None, time(16)),),
376
+ "break_start": ((None, time(12)),),
377
+ "break_end": ((None, time(13)),),
378
+ }
379
+
380
+ @property
381
+ def name(self):
382
+ return "HKEX"
383
+
384
+ @property
385
+ def tz(self):
386
+ return timezone("Asia/Shanghai")
387
+
388
+ @property
389
+ def regular_holidays(self):
390
+ """
391
+ Rules are guesses based on observations of recent year.
392
+ Rectify accordingly once the next year's holidays arrangement is published by the government.
393
+ """
394
+ return AbstractHolidayCalendar(
395
+ rules=[
396
+ HKNewYearsDay,
397
+ SpringFestivalDayBefore1983,
398
+ SpringFestivalDay2Before1983,
399
+ SpringFestivalDay3Before1983,
400
+ SpringFestivalDayBefore2010,
401
+ SpringFestivalDay2Before2010,
402
+ SpringFestivalDay3Before2010,
403
+ SpringFestivalDay,
404
+ SpringFestivalDay2,
405
+ SpringFestivalDay3,
406
+ GoodFriday,
407
+ EasterMonday,
408
+ TombSweepingDay,
409
+ LabourDay,
410
+ BuddhaShakyamuniDay,
411
+ DragonBoatFestivalDay,
412
+ HKRegionEstablishmentDay,
413
+ MidAutumnFestivalDayBefore1983,
414
+ MidAutumnFestivalDayBefore2010,
415
+ MidAutumnFestivalDay,
416
+ NationalDay,
417
+ DoubleNinthFestivalDay,
418
+ Christmas,
419
+ BoxingDay,
420
+ CommemoratingAlliedVictory,
421
+ QueenBirthday,
422
+ QueenBirthday2,
423
+ IDontKnow,
424
+ ]
425
+ )
426
+
427
+ @property
428
+ def adhoc_holidays(self):
429
+ return HKClosedDay