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