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,290 +1,311 @@
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 pandas_market_calendars.holidays.cn import *
8
- from pandas_market_calendars.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
+ 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 pandas_market_calendars.holidays.cn import *
8
+ from pandas_market_calendars.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
+
20
+ aliases = ["SSE"]
21
+ regular_market_times = {
22
+ "market_open": ((None, time(9, 30)),),
23
+ "market_close": ((None, time(15)),),
24
+ "break_start": ((None, time(11, 30)),),
25
+ "break_end": ((None, time(13)),),
26
+ }
27
+
28
+ @property
29
+ def name(self):
30
+ return "SSE"
31
+
32
+ @property
33
+ def tz(self):
34
+ return timezone("Asia/Shanghai")
35
+
36
+ @property
37
+ def regular_holidays(self):
38
+ """
39
+ Rules are guesses based on observations of recent year.
40
+ Rectify accordingly once the next year's holidays arrangement is published by the government.
41
+ """
42
+ # Since all past holidays are adhoc, start_year should always be a year in the future.
43
+ # For example: Holiday arrangements for 2022 are now included,
44
+ # then our guesswork starts from the next year so start_year = 2023
45
+ start_year = 2024
46
+
47
+ return AbstractHolidayCalendar(
48
+ rules=[
49
+ Holiday(
50
+ name="New Year's Day",
51
+ month=1,
52
+ day=1,
53
+ observance=next_monday,
54
+ start_date=Timestamp(start_year, 1, 1),
55
+ ),
56
+ Holiday(
57
+ name="New Year's Day",
58
+ month=1,
59
+ day=2,
60
+ observance=partial(second_day_in_lieu),
61
+ start_date=Timestamp(start_year, 1, 2),
62
+ ),
63
+ Holiday(
64
+ name="New Year's Day",
65
+ month=1,
66
+ day=3,
67
+ observance=partial(third_day_in_lieu),
68
+ start_date=Timestamp(start_year, 1, 3),
69
+ ),
70
+ Holiday(
71
+ name="Spring Festival",
72
+ month=1,
73
+ day=20,
74
+ observance=partial(lunisolar, mapping=sf_mapping, delta=-1),
75
+ start_date=Timestamp(start_year, 1, 20),
76
+ ),
77
+ Holiday(
78
+ name="Spring Festival",
79
+ month=1,
80
+ day=21,
81
+ observance=partial(lunisolar, mapping=sf_mapping, delta=0),
82
+ start_date=Timestamp(start_year, 1, 21),
83
+ ),
84
+ Holiday(
85
+ name="Spring Festival",
86
+ month=1,
87
+ day=21,
88
+ observance=partial(lunisolar, mapping=sf_mapping, delta=1),
89
+ start_date=Timestamp(start_year, 1, 22),
90
+ ),
91
+ Holiday(
92
+ name="Spring Festival",
93
+ month=1,
94
+ day=21,
95
+ observance=partial(lunisolar, mapping=sf_mapping, delta=2),
96
+ start_date=Timestamp(start_year, 1, 23),
97
+ ),
98
+ Holiday(
99
+ name="Spring Festival",
100
+ month=1,
101
+ day=21,
102
+ observance=partial(lunisolar, mapping=sf_mapping, delta=3),
103
+ start_date=Timestamp(start_year, 1, 24),
104
+ ),
105
+ Holiday(
106
+ name="Spring Festival",
107
+ month=1,
108
+ day=21,
109
+ observance=partial(lunisolar, mapping=sf_mapping, delta=4),
110
+ start_date=Timestamp(start_year, 1, 25),
111
+ ),
112
+ Holiday(
113
+ name="Spring Festival",
114
+ month=1,
115
+ day=21,
116
+ observance=partial(lunisolar, mapping=sf_mapping, delta=5),
117
+ start_date=Timestamp(start_year, 1, 26),
118
+ ),
119
+ Holiday(
120
+ name="Labour Day",
121
+ month=5,
122
+ day=1,
123
+ observance=next_monday,
124
+ start_date=Timestamp(start_year, 5, 1),
125
+ ),
126
+ Holiday(
127
+ name="Labour Day",
128
+ month=5,
129
+ day=2,
130
+ observance=second_day_in_lieu,
131
+ start_date=Timestamp(start_year, 5, 2),
132
+ ),
133
+ Holiday(
134
+ name="Labour Day",
135
+ month=5,
136
+ day=3,
137
+ observance=third_day_in_lieu,
138
+ start_date=Timestamp(start_year, 5, 3),
139
+ ),
140
+ Holiday(
141
+ name="Tomb-sweeping Day",
142
+ month=4,
143
+ day=4,
144
+ observance=partial(
145
+ lunisolar, mapping=tsd_mapping, func=next_monday
146
+ ),
147
+ start_date=Timestamp(start_year, 4, 4),
148
+ ),
149
+ Holiday(
150
+ name="Tomb-sweeping Day",
151
+ month=4,
152
+ day=5,
153
+ observance=partial(
154
+ lunisolar, mapping=tsd_mapping, func=second_day_in_lieu, delta=1
155
+ ),
156
+ start_date=Timestamp(start_year, 4, 4),
157
+ ),
158
+ Holiday(
159
+ name="Tomb-sweeping Day",
160
+ month=4,
161
+ day=6,
162
+ observance=partial(
163
+ lunisolar, mapping=tsd_mapping, func=third_day_in_lieu, delta=2
164
+ ),
165
+ start_date=Timestamp(start_year, 4, 4),
166
+ ),
167
+ Holiday(
168
+ name="Dragon Boat Festival",
169
+ month=5,
170
+ day=27,
171
+ observance=partial(
172
+ lunisolar, mapping=dbf_mapping, func=next_monday
173
+ ),
174
+ start_date=Timestamp(start_year, 5, 27),
175
+ ),
176
+ Holiday(
177
+ name="Dragon Boat Festival",
178
+ month=5,
179
+ day=28,
180
+ observance=partial(
181
+ lunisolar, mapping=dbf_mapping, func=second_day_in_lieu, delta=1
182
+ ),
183
+ start_date=Timestamp(start_year, 5, 27),
184
+ ),
185
+ Holiday(
186
+ name="Dragon Boat Festival",
187
+ month=5,
188
+ day=29,
189
+ observance=partial(
190
+ lunisolar, mapping=dbf_mapping, func=third_day_in_lieu, delta=2
191
+ ),
192
+ start_date=Timestamp(start_year, 5, 27),
193
+ ),
194
+ Holiday(
195
+ name="Mid-autumn Festival",
196
+ month=9,
197
+ day=7,
198
+ observance=partial(
199
+ lunisolar, mapping=maf_mapping, func=next_monday
200
+ ),
201
+ start_date=Timestamp(start_year, 9, 7),
202
+ ),
203
+ Holiday(
204
+ name="Mid-autumn Festival",
205
+ month=9,
206
+ day=8,
207
+ observance=partial(
208
+ lunisolar, mapping=maf_mapping, func=second_day_in_lieu, delta=1
209
+ ),
210
+ start_date=Timestamp(start_year, 9, 7),
211
+ ),
212
+ Holiday(
213
+ name="Mid-autumn Festival",
214
+ month=9,
215
+ day=9,
216
+ observance=partial(
217
+ lunisolar, mapping=maf_mapping, func=third_day_in_lieu, delta=2
218
+ ),
219
+ start_date=Timestamp(start_year, 9, 7),
220
+ ),
221
+ Holiday(
222
+ name="National Day",
223
+ month=10,
224
+ day=1,
225
+ start_date=Timestamp(start_year, 10, 1),
226
+ ),
227
+ Holiday(
228
+ name="National Day",
229
+ month=10,
230
+ day=2,
231
+ start_date=Timestamp(start_year, 10, 2),
232
+ ),
233
+ Holiday(
234
+ name="National Day",
235
+ month=10,
236
+ day=3,
237
+ start_date=Timestamp(start_year, 10, 3),
238
+ ),
239
+ Holiday(
240
+ name="National Day",
241
+ month=10,
242
+ day=4,
243
+ start_date=Timestamp(start_year, 10, 4),
244
+ ),
245
+ Holiday(
246
+ name="National Day",
247
+ month=10,
248
+ day=5,
249
+ start_date=Timestamp(start_year, 10, 5),
250
+ ),
251
+ Holiday(
252
+ name="National Day",
253
+ month=10,
254
+ day=6,
255
+ start_date=Timestamp(start_year, 10, 6),
256
+ ),
257
+ Holiday(
258
+ name="National Day",
259
+ month=10,
260
+ day=7,
261
+ start_date=Timestamp(start_year, 10, 7),
262
+ ),
263
+ ]
264
+ )
265
+
266
+ @property
267
+ def adhoc_holidays(self):
268
+ return all_holidays
269
+
270
+
271
+ def second_day_in_lieu(dt):
272
+ dow = dt.weekday()
273
+ if dow == 0: # Holiday is Sunday, use Saturday
274
+ return dt - timedelta(2)
275
+ elif dow == 1: # Holiday is Monday, use Saturday
276
+ return dt - timedelta(3)
277
+ elif dow == 2: # Holiday is Tuesday, use Sunday
278
+ return dt - timedelta(3)
279
+ elif dow == 3: # Holiday is Wednesday, use Saturday
280
+ return dt - timedelta(5)
281
+
282
+ return dt
283
+
284
+
285
+ def third_day_in_lieu(dt):
286
+ dow = dt.weekday()
287
+ if dow == 0: # Holiday is Saturday, use Sunday
288
+ return dt - timedelta(1)
289
+ elif dow == 1: # Holiday is Sunday, use Sunday
290
+ return dt - timedelta(2)
291
+ elif dow == 2: # Holiday is Monday, use Sunday
292
+ return dt - timedelta(3)
293
+ elif dow == 3: # Holiday is Tuesday, use Monday
294
+ return dt - timedelta(3)
295
+ elif dow == 4: # Holiday is Wednesday, use Sunday
296
+ return dt - timedelta(5)
297
+
298
+ return dt
299
+
300
+
301
+ def lunisolar(dt, mapping, func=None, delta=None):
302
+ if mapping and (dt.year in mapping):
303
+ new_dt = mapping[dt.year]
304
+ else:
305
+ new_dt = dt
306
+ if delta:
307
+ new_dt = new_dt + timedelta(delta)
308
+ if func:
309
+ return func(new_dt)
310
+ else:
311
+ return new_dt