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