pandas-market-calendars 4.3.2__py3-none-any.whl → 4.3.3__py3-none-any.whl

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