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,385 +1,385 @@
1
- import datetime
2
-
3
- from dateutil.relativedelta import MO, TH, FR
4
- from pandas import DateOffset, Timestamp
5
- from pandas.tseries.holiday import Holiday, Easter, nearest_workday
6
- from pandas.tseries.offsets import Day
7
-
8
- #########
9
- # Martin Luther King
10
- #########
11
- USMartinLutherKingJrAfter1998Before2022 = Holiday(
12
- "Dr. Martin Luther King Jr. Day",
13
- month=1,
14
- day=1,
15
- # The US markets didn't observe MLK day as a holiday until 1998.
16
- start_date=Timestamp("1998-01-01"),
17
- end_date=Timestamp("2021-12-31"),
18
- offset=DateOffset(weekday=MO(3)),
19
- )
20
-
21
- USMartinLutherKingJrAfter1998Before2015 = Holiday(
22
- "Dr. Martin Luther King Jr. Day",
23
- month=1,
24
- day=1,
25
- # The US markets didn't observe MLK day as a holiday until 1998.
26
- start_date=Timestamp("1998-01-01"),
27
- end_date=Timestamp("2014-12-31"),
28
- offset=DateOffset(weekday=MO(3)),
29
- )
30
-
31
- USMartinLutherKingJrAfter2015 = Holiday(
32
- "Dr. Martin Luther King Jr. Day",
33
- month=1,
34
- day=1,
35
- # The US markets didn't observe MLK day as a holiday until 1998.
36
- start_date=Timestamp("2015-01-01"),
37
- offset=DateOffset(weekday=MO(3)),
38
- )
39
-
40
- USMartinLutherKingJrAfter1998Before2016FridayBefore = Holiday(
41
- "Dr. Martin Luther King Jr. Day",
42
- month=1,
43
- day=1,
44
- start_date=Timestamp("1998-01-01"),
45
- end_date=Timestamp("2015-12-31"),
46
- offset=[DateOffset(weekday=MO(3)), DateOffset(weekday=FR(-1))],
47
- )
48
-
49
- #########
50
- # President's Day
51
- #########
52
- USPresidentsDayBefore2022 = Holiday(
53
- "President" "s Day",
54
- start_date=Timestamp("1971-01-01"),
55
- end_date=Timestamp("2021-12-31"),
56
- month=2,
57
- day=1,
58
- offset=DateOffset(weekday=MO(3)),
59
- )
60
- USPresidentsDayBefore2015 = Holiday(
61
- "President" "s Day",
62
- start_date=Timestamp("1971-01-01"),
63
- end_date=Timestamp("2014-12-31"),
64
- month=2,
65
- day=1,
66
- offset=DateOffset(weekday=MO(3)),
67
- )
68
-
69
- USPresidentsDayAfter2015 = Holiday(
70
- "President" "s Day",
71
- start_date=Timestamp("2015-01-01"),
72
- month=2,
73
- day=1,
74
- offset=DateOffset(weekday=MO(3)),
75
- )
76
-
77
- USPresidentsDayBefore2016FridayBefore = Holiday(
78
- "President" "s Day",
79
- start_date=Timestamp("1971-01-01"),
80
- end_date=Timestamp("2015-12-31"),
81
- month=2,
82
- day=1,
83
- offset=[DateOffset(weekday=MO(3)), DateOffset(weekday=FR(-1))],
84
- )
85
-
86
- #########
87
- # Good Friday
88
- #########
89
-
90
-
91
- GoodFridayBefore2021 = Holiday(
92
- "Good Friday",
93
- month=1,
94
- day=1,
95
- offset=[Easter(), Day(-2)],
96
- end_date=Timestamp("2020-12-31"),
97
- )
98
-
99
- # On some years (i.e. 2010,2012,2015) there is a special close for equities at 08:15
100
- # so here it is made sure that those are not full holidays
101
- easter = Easter()
102
- daymin2 = Day(-2)
103
-
104
-
105
- def not_0815_close(dt):
106
- if dt.year in (2010, 2012, 2015):
107
- return None
108
- else:
109
- return dt + easter + daymin2
110
-
111
-
112
- GoodFridayBefore2021NotEarlyClose = Holiday(
113
- "Good Friday",
114
- month=1,
115
- day=1,
116
- observance=not_0815_close,
117
- end_date=Timestamp("2020-12-31"),
118
- )
119
-
120
- # CME Interest Rate Products have this odd close
121
- GoodFriday2009 = Holiday(
122
- "Good Friday",
123
- month=1,
124
- day=1,
125
- offset=[Easter(), Day(-3)],
126
- start_date=Timestamp("2009-01-01"),
127
- end_date=Timestamp("2009-12-31"),
128
- )
129
-
130
- GoodFriday2021 = Holiday(
131
- "Good Friday",
132
- month=1,
133
- day=1,
134
- offset=[Easter(), Day(-2)],
135
- start_date=Timestamp("2021-01-01"),
136
- end_date=Timestamp("2021-12-31"),
137
- )
138
- GoodFridayAfter2021 = Holiday(
139
- "Good Friday",
140
- month=1,
141
- day=1,
142
- offset=[Easter(), Day(-2)],
143
- start_date=Timestamp("2022-01-01"),
144
- )
145
- GoodFriday2022 = Holiday(
146
- "Good Friday",
147
- month=1,
148
- day=1,
149
- offset=[Easter(), Day(-2)],
150
- start_date=Timestamp("2022-01-01"),
151
- end_date=Timestamp("2022-12-31"),
152
- )
153
- GoodFridayAfter2022 = Holiday(
154
- "Good Friday",
155
- month=1,
156
- day=1,
157
- offset=[Easter(), Day(-2)],
158
- start_date=Timestamp("2023-01-01"),
159
- )
160
- # Dates when equities closed at 08:15
161
- GoodFriday2010 = Holiday(
162
- "Good Friday",
163
- month=1,
164
- day=1,
165
- offset=[Easter(), Day(-2)],
166
- start_date=Timestamp("2010-01-01"),
167
- end_date=Timestamp("2010-12-31"),
168
- )
169
- GoodFriday2012 = Holiday(
170
- "Good Friday",
171
- month=1,
172
- day=1,
173
- offset=[Easter(), Day(-2)],
174
- start_date=Timestamp("2012-01-01"),
175
- end_date=Timestamp("2012-12-31"),
176
- )
177
-
178
- GoodFriday2015 = Holiday(
179
- "Good Friday",
180
- month=1,
181
- day=1,
182
- offset=[Easter(), Day(-2)],
183
- start_date=Timestamp("2015-01-01"),
184
- end_date=Timestamp("2015-12-31"),
185
- )
186
-
187
- #########
188
- # Memorial Day
189
- #########
190
-
191
- USMemorialDay2021AndPrior = Holiday(
192
- "Memorial Day",
193
- month=5,
194
- day=25,
195
- start_date=Timestamp("1971-01-01"),
196
- end_date=Timestamp("2021-12-31"),
197
- offset=DateOffset(weekday=MO(1)),
198
- ) # Equity Products
199
- USMemorialDay2013AndPrior = Holiday(
200
- "Memorial Day",
201
- month=5,
202
- day=25,
203
- start_date=Timestamp("1971-01-01"),
204
- end_date=Timestamp("2013-12-31"),
205
- offset=DateOffset(weekday=MO(1)),
206
- )
207
- USMemorialDayAfter2013 = Holiday(
208
- "Memorial Day",
209
- month=5,
210
- day=25,
211
- start_date=Timestamp("2014-01-01"),
212
- offset=DateOffset(weekday=MO(1)),
213
- )
214
- USMemorialDay2015AndPriorFridayBefore = Holiday(
215
- "Memorial Day",
216
- month=5,
217
- day=25,
218
- start_date=Timestamp("1971-01-01"),
219
- end_date=Timestamp("2015-12-31"),
220
- offset=[DateOffset(weekday=MO(1)), DateOffset(weekday=FR(-1))],
221
- )
222
-
223
- #######
224
- # Independence Day
225
- #######
226
-
227
- USIndependenceDayBefore2022 = Holiday(
228
- "July 4th",
229
- month=7,
230
- day=4,
231
- start_date=Timestamp("1954-01-01"),
232
- end_date=Timestamp("2021-12-31"),
233
- observance=nearest_workday,
234
- )
235
- USIndependenceDayBefore2014 = Holiday(
236
- "July 4th",
237
- month=7,
238
- day=4,
239
- start_date=Timestamp("1954-01-01"),
240
- end_date=Timestamp("2013-12-31"),
241
- observance=nearest_workday,
242
- )
243
- USIndependenceDayAfter2014 = Holiday(
244
- "July 4th",
245
- month=7,
246
- day=4,
247
- start_date=Timestamp("2014-01-01"),
248
- observance=nearest_workday,
249
- )
250
-
251
-
252
- # Necessary for equities and crypto
253
- def previous_workday_if_july_4th_is_tue_to_fri(dt):
254
- july4th = datetime.datetime(dt.year, 7, 4)
255
- if july4th.weekday() in (1, 2, 3, 4):
256
- return july4th - datetime.timedelta(days=1)
257
- # else None
258
-
259
-
260
- USIndependenceDayBefore2022PreviousDay = Holiday(
261
- "July 4th",
262
- month=7,
263
- day=4,
264
- start_date=Timestamp("1954-01-01"),
265
- observance=previous_workday_if_july_4th_is_tue_to_fri,
266
- )
267
-
268
- #########
269
- # Labor Day
270
- #########
271
-
272
- USLaborDayStarting1887Before2022 = Holiday(
273
- "Labor Day",
274
- month=9,
275
- day=1,
276
- start_date=Timestamp("1887-01-01"),
277
- end_date=Timestamp("2021-12-31"),
278
- offset=DateOffset(weekday=MO(1)),
279
- )
280
- USLaborDayStarting1887Before2014 = Holiday(
281
- "Labor Day",
282
- month=9,
283
- day=1,
284
- start_date=Timestamp("1887-01-01"),
285
- end_date=Timestamp("2013-12-31"),
286
- offset=DateOffset(weekday=MO(1)),
287
- )
288
- USLaborDayStarting1887Before2015FridayBefore = Holiday(
289
- "Labor Day",
290
- month=9,
291
- day=1,
292
- start_date=Timestamp("1887-01-01"),
293
- end_date=Timestamp("2014-12-31"),
294
- offset=[DateOffset(weekday=MO(1)), DateOffset(weekday=FR(-1))],
295
- )
296
- USLaborDayStarting1887After2014 = Holiday(
297
- "Labor Day",
298
- month=9,
299
- day=1,
300
- start_date=Timestamp("2014-01-01"),
301
- offset=DateOffset(weekday=MO(1)),
302
- )
303
-
304
- #########
305
- # Thanksgiving
306
- #########
307
-
308
- USThanksgivingBefore2022 = Holiday(
309
- "ThanksgivingFriday",
310
- start_date=Timestamp("1942-01-01"),
311
- end_date=Timestamp("2021-12-31"),
312
- month=11,
313
- day=1,
314
- offset=DateOffset(weekday=TH(4)),
315
- )
316
- USThanksgivingBefore2014 = Holiday(
317
- "ThanksgivingFriday",
318
- start_date=Timestamp("1942-01-01"),
319
- end_date=Timestamp("2013-12-31"),
320
- month=11,
321
- day=1,
322
- offset=DateOffset(weekday=TH(4)),
323
- )
324
- USThanksgivingAfter2014 = Holiday(
325
- "ThanksgivingFriday",
326
- start_date=Timestamp("2014-01-01"),
327
- month=11,
328
- day=1,
329
- offset=DateOffset(weekday=TH(4)),
330
- )
331
-
332
-
333
- # The following Holidays shouldn't be set with the FR offset
334
- # In 2013, Nov 1st is a friday, so the 4th Friday is before the 4th Thursday...
335
- # the observance rule defined herafter fixes this
336
-
337
- # USThanksgivingFridayBefore2022 = Holiday(
338
- # 'ThanksgivingFriday',
339
- # start_date=Timestamp('1942-01-01'),
340
- # end_date=Timestamp('2021-12-31'),
341
- # month=11, day=1,
342
- # offset=DateOffset(weekday=FR(4)),
343
- # )
344
- #
345
- # USThanksgivingFriday2022AndAfter = Holiday(
346
- # 'ThanksgivingFriday',
347
- # start_date=Timestamp('2022-01-01'),
348
- # month=11, day=1,
349
- # offset=DateOffset(weekday=FR(4)),
350
- # )
351
- # USThanksgivingFriday = Holiday(
352
- # 'ThanksgivingFriday',
353
- # month=11, day=1,
354
- # offset=DateOffset(weekday=FR(4)),
355
- # )
356
-
357
-
358
- def fri_after_4th_thu(dt):
359
- # dt will just be Nov 1st
360
- diff_to_thu = 3 - dt.weekday()
361
- if diff_to_thu < 0:
362
- diff_to_thu += 7
363
- return dt + datetime.timedelta(days=diff_to_thu + 22)
364
-
365
-
366
- USThanksgivingFriday = Holiday(
367
- "ThanksgivingFriday",
368
- start_date=Timestamp("1942-01-01"),
369
- month=11,
370
- day=1,
371
- observance=fri_after_4th_thu,
372
- )
373
-
374
- USThanksgivingFriday2022AndAfter = Holiday(
375
- "ThanksgivingFriday",
376
- start_date=Timestamp("2022-01-01"),
377
- month=11,
378
- day=1,
379
- observance=fri_after_4th_thu,
380
- )
381
- # USThanksgivingFriday = Holiday(
382
- # 'ThanksgivingFriday',
383
- # month=11, day=1,
384
- # observance= fri_after_4th_thu,
385
- # )
1
+ import datetime
2
+
3
+ from dateutil.relativedelta import MO, TH, FR
4
+ from pandas import DateOffset, Timestamp
5
+ from pandas.tseries.holiday import Holiday, Easter, nearest_workday
6
+ from pandas.tseries.offsets import Day
7
+
8
+ #########
9
+ # Martin Luther King
10
+ #########
11
+ USMartinLutherKingJrAfter1998Before2022 = Holiday(
12
+ "Dr. Martin Luther King Jr. Day",
13
+ month=1,
14
+ day=1,
15
+ # The US markets didn't observe MLK day as a holiday until 1998.
16
+ start_date=Timestamp("1998-01-01"),
17
+ end_date=Timestamp("2021-12-31"),
18
+ offset=DateOffset(weekday=MO(3)),
19
+ )
20
+
21
+ USMartinLutherKingJrAfter1998Before2015 = Holiday(
22
+ "Dr. Martin Luther King Jr. Day",
23
+ month=1,
24
+ day=1,
25
+ # The US markets didn't observe MLK day as a holiday until 1998.
26
+ start_date=Timestamp("1998-01-01"),
27
+ end_date=Timestamp("2014-12-31"),
28
+ offset=DateOffset(weekday=MO(3)),
29
+ )
30
+
31
+ USMartinLutherKingJrAfter2015 = Holiday(
32
+ "Dr. Martin Luther King Jr. Day",
33
+ month=1,
34
+ day=1,
35
+ # The US markets didn't observe MLK day as a holiday until 1998.
36
+ start_date=Timestamp("2015-01-01"),
37
+ offset=DateOffset(weekday=MO(3)),
38
+ )
39
+
40
+ USMartinLutherKingJrAfter1998Before2016FridayBefore = Holiday(
41
+ "Dr. Martin Luther King Jr. Day",
42
+ month=1,
43
+ day=1,
44
+ start_date=Timestamp("1998-01-01"),
45
+ end_date=Timestamp("2015-12-31"),
46
+ offset=[DateOffset(weekday=MO(3)), DateOffset(weekday=FR(-1))],
47
+ )
48
+
49
+ #########
50
+ # President's Day
51
+ #########
52
+ USPresidentsDayBefore2022 = Holiday(
53
+ "President" "s Day",
54
+ start_date=Timestamp("1971-01-01"),
55
+ end_date=Timestamp("2021-12-31"),
56
+ month=2,
57
+ day=1,
58
+ offset=DateOffset(weekday=MO(3)),
59
+ )
60
+ USPresidentsDayBefore2015 = Holiday(
61
+ "President" "s Day",
62
+ start_date=Timestamp("1971-01-01"),
63
+ end_date=Timestamp("2014-12-31"),
64
+ month=2,
65
+ day=1,
66
+ offset=DateOffset(weekday=MO(3)),
67
+ )
68
+
69
+ USPresidentsDayAfter2015 = Holiday(
70
+ "President" "s Day",
71
+ start_date=Timestamp("2015-01-01"),
72
+ month=2,
73
+ day=1,
74
+ offset=DateOffset(weekday=MO(3)),
75
+ )
76
+
77
+ USPresidentsDayBefore2016FridayBefore = Holiday(
78
+ "President" "s Day",
79
+ start_date=Timestamp("1971-01-01"),
80
+ end_date=Timestamp("2015-12-31"),
81
+ month=2,
82
+ day=1,
83
+ offset=[DateOffset(weekday=MO(3)), DateOffset(weekday=FR(-1))],
84
+ )
85
+
86
+ #########
87
+ # Good Friday
88
+ #########
89
+
90
+
91
+ GoodFridayBefore2021 = Holiday(
92
+ "Good Friday",
93
+ month=1,
94
+ day=1,
95
+ offset=[Easter(), Day(-2)],
96
+ end_date=Timestamp("2020-12-31"),
97
+ )
98
+
99
+ # On some years (i.e. 2010,2012,2015) there is a special close for equities at 08:15
100
+ # so here it is made sure that those are not full holidays
101
+ easter = Easter()
102
+ daymin2 = Day(-2)
103
+
104
+
105
+ def not_0815_close(dt):
106
+ if dt.year in (2010, 2012, 2015):
107
+ return None
108
+ else:
109
+ return dt + easter + daymin2
110
+
111
+
112
+ GoodFridayBefore2021NotEarlyClose = Holiday(
113
+ "Good Friday",
114
+ month=1,
115
+ day=1,
116
+ observance=not_0815_close,
117
+ end_date=Timestamp("2020-12-31"),
118
+ )
119
+
120
+ # CME Interest Rate Products have this odd close
121
+ GoodFriday2009 = Holiday(
122
+ "Good Friday",
123
+ month=1,
124
+ day=1,
125
+ offset=[Easter(), Day(-3)],
126
+ start_date=Timestamp("2009-01-01"),
127
+ end_date=Timestamp("2009-12-31"),
128
+ )
129
+
130
+ GoodFriday2021 = Holiday(
131
+ "Good Friday",
132
+ month=1,
133
+ day=1,
134
+ offset=[Easter(), Day(-2)],
135
+ start_date=Timestamp("2021-01-01"),
136
+ end_date=Timestamp("2021-12-31"),
137
+ )
138
+ GoodFridayAfter2021 = Holiday(
139
+ "Good Friday",
140
+ month=1,
141
+ day=1,
142
+ offset=[Easter(), Day(-2)],
143
+ start_date=Timestamp("2022-01-01"),
144
+ )
145
+ GoodFriday2022 = Holiday(
146
+ "Good Friday",
147
+ month=1,
148
+ day=1,
149
+ offset=[Easter(), Day(-2)],
150
+ start_date=Timestamp("2022-01-01"),
151
+ end_date=Timestamp("2022-12-31"),
152
+ )
153
+ GoodFridayAfter2022 = Holiday(
154
+ "Good Friday",
155
+ month=1,
156
+ day=1,
157
+ offset=[Easter(), Day(-2)],
158
+ start_date=Timestamp("2023-01-01"),
159
+ )
160
+ # Dates when equities closed at 08:15
161
+ GoodFriday2010 = Holiday(
162
+ "Good Friday",
163
+ month=1,
164
+ day=1,
165
+ offset=[Easter(), Day(-2)],
166
+ start_date=Timestamp("2010-01-01"),
167
+ end_date=Timestamp("2010-12-31"),
168
+ )
169
+ GoodFriday2012 = Holiday(
170
+ "Good Friday",
171
+ month=1,
172
+ day=1,
173
+ offset=[Easter(), Day(-2)],
174
+ start_date=Timestamp("2012-01-01"),
175
+ end_date=Timestamp("2012-12-31"),
176
+ )
177
+
178
+ GoodFriday2015 = Holiday(
179
+ "Good Friday",
180
+ month=1,
181
+ day=1,
182
+ offset=[Easter(), Day(-2)],
183
+ start_date=Timestamp("2015-01-01"),
184
+ end_date=Timestamp("2015-12-31"),
185
+ )
186
+
187
+ #########
188
+ # Memorial Day
189
+ #########
190
+
191
+ USMemorialDay2021AndPrior = Holiday(
192
+ "Memorial Day",
193
+ month=5,
194
+ day=25,
195
+ start_date=Timestamp("1971-01-01"),
196
+ end_date=Timestamp("2021-12-31"),
197
+ offset=DateOffset(weekday=MO(1)),
198
+ ) # Equity Products
199
+ USMemorialDay2013AndPrior = Holiday(
200
+ "Memorial Day",
201
+ month=5,
202
+ day=25,
203
+ start_date=Timestamp("1971-01-01"),
204
+ end_date=Timestamp("2013-12-31"),
205
+ offset=DateOffset(weekday=MO(1)),
206
+ )
207
+ USMemorialDayAfter2013 = Holiday(
208
+ "Memorial Day",
209
+ month=5,
210
+ day=25,
211
+ start_date=Timestamp("2014-01-01"),
212
+ offset=DateOffset(weekday=MO(1)),
213
+ )
214
+ USMemorialDay2015AndPriorFridayBefore = Holiday(
215
+ "Memorial Day",
216
+ month=5,
217
+ day=25,
218
+ start_date=Timestamp("1971-01-01"),
219
+ end_date=Timestamp("2015-12-31"),
220
+ offset=[DateOffset(weekday=MO(1)), DateOffset(weekday=FR(-1))],
221
+ )
222
+
223
+ #######
224
+ # Independence Day
225
+ #######
226
+
227
+ USIndependenceDayBefore2022 = Holiday(
228
+ "July 4th",
229
+ month=7,
230
+ day=4,
231
+ start_date=Timestamp("1954-01-01"),
232
+ end_date=Timestamp("2021-12-31"),
233
+ observance=nearest_workday,
234
+ )
235
+ USIndependenceDayBefore2014 = Holiday(
236
+ "July 4th",
237
+ month=7,
238
+ day=4,
239
+ start_date=Timestamp("1954-01-01"),
240
+ end_date=Timestamp("2013-12-31"),
241
+ observance=nearest_workday,
242
+ )
243
+ USIndependenceDayAfter2014 = Holiday(
244
+ "July 4th",
245
+ month=7,
246
+ day=4,
247
+ start_date=Timestamp("2014-01-01"),
248
+ observance=nearest_workday,
249
+ )
250
+
251
+
252
+ # Necessary for equities and crypto
253
+ def previous_workday_if_july_4th_is_tue_to_fri(dt):
254
+ july4th = datetime.datetime(dt.year, 7, 4)
255
+ if july4th.weekday() in (1, 2, 3, 4):
256
+ return july4th - datetime.timedelta(days=1)
257
+ # else None
258
+
259
+
260
+ USIndependenceDayBefore2022PreviousDay = Holiday(
261
+ "July 4th",
262
+ month=7,
263
+ day=4,
264
+ start_date=Timestamp("1954-01-01"),
265
+ observance=previous_workday_if_july_4th_is_tue_to_fri,
266
+ )
267
+
268
+ #########
269
+ # Labor Day
270
+ #########
271
+
272
+ USLaborDayStarting1887Before2022 = Holiday(
273
+ "Labor Day",
274
+ month=9,
275
+ day=1,
276
+ start_date=Timestamp("1887-01-01"),
277
+ end_date=Timestamp("2021-12-31"),
278
+ offset=DateOffset(weekday=MO(1)),
279
+ )
280
+ USLaborDayStarting1887Before2014 = Holiday(
281
+ "Labor Day",
282
+ month=9,
283
+ day=1,
284
+ start_date=Timestamp("1887-01-01"),
285
+ end_date=Timestamp("2013-12-31"),
286
+ offset=DateOffset(weekday=MO(1)),
287
+ )
288
+ USLaborDayStarting1887Before2015FridayBefore = Holiday(
289
+ "Labor Day",
290
+ month=9,
291
+ day=1,
292
+ start_date=Timestamp("1887-01-01"),
293
+ end_date=Timestamp("2014-12-31"),
294
+ offset=[DateOffset(weekday=MO(1)), DateOffset(weekday=FR(-1))],
295
+ )
296
+ USLaborDayStarting1887After2014 = Holiday(
297
+ "Labor Day",
298
+ month=9,
299
+ day=1,
300
+ start_date=Timestamp("2014-01-01"),
301
+ offset=DateOffset(weekday=MO(1)),
302
+ )
303
+
304
+ #########
305
+ # Thanksgiving
306
+ #########
307
+
308
+ USThanksgivingBefore2022 = Holiday(
309
+ "ThanksgivingFriday",
310
+ start_date=Timestamp("1942-01-01"),
311
+ end_date=Timestamp("2021-12-31"),
312
+ month=11,
313
+ day=1,
314
+ offset=DateOffset(weekday=TH(4)),
315
+ )
316
+ USThanksgivingBefore2014 = Holiday(
317
+ "ThanksgivingFriday",
318
+ start_date=Timestamp("1942-01-01"),
319
+ end_date=Timestamp("2013-12-31"),
320
+ month=11,
321
+ day=1,
322
+ offset=DateOffset(weekday=TH(4)),
323
+ )
324
+ USThanksgivingAfter2014 = Holiday(
325
+ "ThanksgivingFriday",
326
+ start_date=Timestamp("2014-01-01"),
327
+ month=11,
328
+ day=1,
329
+ offset=DateOffset(weekday=TH(4)),
330
+ )
331
+
332
+
333
+ # The following Holidays shouldn't be set with the FR offset
334
+ # In 2013, Nov 1st is a friday, so the 4th Friday is before the 4th Thursday...
335
+ # the observance rule defined herafter fixes this
336
+
337
+ # USThanksgivingFridayBefore2022 = Holiday(
338
+ # 'ThanksgivingFriday',
339
+ # start_date=Timestamp('1942-01-01'),
340
+ # end_date=Timestamp('2021-12-31'),
341
+ # month=11, day=1,
342
+ # offset=DateOffset(weekday=FR(4)),
343
+ # )
344
+ #
345
+ # USThanksgivingFriday2022AndAfter = Holiday(
346
+ # 'ThanksgivingFriday',
347
+ # start_date=Timestamp('2022-01-01'),
348
+ # month=11, day=1,
349
+ # offset=DateOffset(weekday=FR(4)),
350
+ # )
351
+ # USThanksgivingFriday = Holiday(
352
+ # 'ThanksgivingFriday',
353
+ # month=11, day=1,
354
+ # offset=DateOffset(weekday=FR(4)),
355
+ # )
356
+
357
+
358
+ def fri_after_4th_thu(dt):
359
+ # dt will just be Nov 1st
360
+ diff_to_thu = 3 - dt.weekday()
361
+ if diff_to_thu < 0:
362
+ diff_to_thu += 7
363
+ return dt + datetime.timedelta(days=diff_to_thu + 22)
364
+
365
+
366
+ USThanksgivingFriday = Holiday(
367
+ "ThanksgivingFriday",
368
+ start_date=Timestamp("1942-01-01"),
369
+ month=11,
370
+ day=1,
371
+ observance=fri_after_4th_thu,
372
+ )
373
+
374
+ USThanksgivingFriday2022AndAfter = Holiday(
375
+ "ThanksgivingFriday",
376
+ start_date=Timestamp("2022-01-01"),
377
+ month=11,
378
+ day=1,
379
+ observance=fri_after_4th_thu,
380
+ )
381
+ # USThanksgivingFriday = Holiday(
382
+ # 'ThanksgivingFriday',
383
+ # month=11, day=1,
384
+ # observance= fri_after_4th_thu,
385
+ # )