pandas-market-calendars 5.0.0__py3-none-any.whl → 5.1.1__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.
- pandas_market_calendars/__init__.py +39 -39
- pandas_market_calendars/calendar_registry.py +57 -57
- pandas_market_calendars/calendar_utils.py +1151 -1147
- pandas_market_calendars/calendars/asx.py +77 -70
- pandas_market_calendars/calendars/bmf.py +226 -219
- pandas_market_calendars/calendars/bse.py +432 -425
- pandas_market_calendars/calendars/cboe.py +156 -149
- pandas_market_calendars/calendars/cme.py +412 -405
- pandas_market_calendars/calendars/cme_globex_agriculture.py +172 -172
- pandas_market_calendars/calendars/cme_globex_base.py +126 -119
- pandas_market_calendars/calendars/cme_globex_crypto.py +165 -158
- pandas_market_calendars/calendars/cme_globex_energy_and_metals.py +223 -216
- pandas_market_calendars/calendars/cme_globex_equities.py +130 -123
- pandas_market_calendars/calendars/cme_globex_fixed_income.py +136 -136
- pandas_market_calendars/calendars/cme_globex_fx.py +101 -101
- pandas_market_calendars/calendars/eurex.py +138 -131
- pandas_market_calendars/calendars/eurex_fixed_income.py +105 -98
- pandas_market_calendars/calendars/hkex.py +438 -431
- pandas_market_calendars/calendars/ice.py +88 -81
- pandas_market_calendars/calendars/iex.py +162 -155
- pandas_market_calendars/calendars/jpx.py +124 -117
- pandas_market_calendars/calendars/lse.py +125 -118
- pandas_market_calendars/calendars/mirror.py +144 -144
- pandas_market_calendars/calendars/nyse.py +1472 -1466
- pandas_market_calendars/calendars/ose.py +125 -118
- pandas_market_calendars/calendars/sifma.py +390 -356
- pandas_market_calendars/calendars/six.py +143 -136
- pandas_market_calendars/calendars/sse.py +322 -315
- pandas_market_calendars/calendars/tase.py +231 -224
- pandas_market_calendars/calendars/tsx.py +192 -185
- pandas_market_calendars/class_registry.py +115 -115
- pandas_market_calendars/holidays/cme.py +385 -385
- pandas_market_calendars/holidays/cme_globex.py +214 -214
- pandas_market_calendars/holidays/cn.py +1476 -1476
- pandas_market_calendars/holidays/jp.py +401 -401
- pandas_market_calendars/holidays/jpx_equinox.py +506 -506
- pandas_market_calendars/holidays/nyse.py +1536 -1536
- pandas_market_calendars/holidays/oz.py +63 -63
- pandas_market_calendars/holidays/sifma.py +350 -350
- pandas_market_calendars/holidays/us.py +376 -376
- pandas_market_calendars/market_calendar.py +1008 -1008
- {pandas_market_calendars-5.0.0.dist-info → pandas_market_calendars-5.1.1.dist-info}/METADATA +3 -1
- pandas_market_calendars-5.1.1.dist-info/RECORD +50 -0
- {pandas_market_calendars-5.0.0.dist-info → pandas_market_calendars-5.1.1.dist-info}/WHEEL +1 -1
- pandas_market_calendars-5.0.0.dist-info/RECORD +0 -50
- {pandas_market_calendars-5.0.0.dist-info → pandas_market_calendars-5.1.1.dist-info}/licenses/LICENSE +0 -0
- {pandas_market_calendars-5.0.0.dist-info → pandas_market_calendars-5.1.1.dist-info}/licenses/NOTICE +0 -0
- {pandas_market_calendars-5.0.0.dist-info → pandas_market_calendars-5.1.1.dist-info}/top_level.txt +0 -0
@@ -1,376 +1,376 @@
|
|
1
|
-
from dateutil.relativedelta import MO, TH, TU
|
2
|
-
from pandas import DateOffset, Timestamp, date_range
|
3
|
-
from pandas.tseries.holiday import Holiday, nearest_workday, sunday_to_monday
|
4
|
-
from pandas.tseries.offsets import Day
|
5
|
-
|
6
|
-
from pandas_market_calendars.market_calendar import (
|
7
|
-
FRIDAY,
|
8
|
-
MONDAY,
|
9
|
-
THURSDAY,
|
10
|
-
TUESDAY,
|
11
|
-
WEDNESDAY,
|
12
|
-
)
|
13
|
-
|
14
|
-
|
15
|
-
# These have the same definition, but are used in different places because the
|
16
|
-
# NYSE closed at 2:00 PM on Christmas Eve until 1993.
|
17
|
-
|
18
|
-
|
19
|
-
def following_tuesday_every_four_years_observance(dt):
|
20
|
-
return dt + DateOffset(years=(4 - (dt.year % 4)) % 4, weekday=TU(1))
|
21
|
-
|
22
|
-
|
23
|
-
ChristmasEveBefore1993 = Holiday(
|
24
|
-
"Christmas Eve",
|
25
|
-
month=12,
|
26
|
-
day=24,
|
27
|
-
end_date=Timestamp("1993-01-01"),
|
28
|
-
# When Christmas is a Saturday, the 24th is a full holiday.
|
29
|
-
days_of_week=(MONDAY, TUESDAY, WEDNESDAY, THURSDAY),
|
30
|
-
)
|
31
|
-
ChristmasEveInOrAfter1993 = Holiday(
|
32
|
-
"Christmas Eve",
|
33
|
-
month=12,
|
34
|
-
day=24,
|
35
|
-
start_date=Timestamp("1993-01-01"),
|
36
|
-
# When Christmas is a Saturday, the 24th is a full holiday.
|
37
|
-
days_of_week=(MONDAY, TUESDAY, WEDNESDAY, THURSDAY),
|
38
|
-
)
|
39
|
-
USNewYearsDay = Holiday(
|
40
|
-
"New Years Day",
|
41
|
-
month=1,
|
42
|
-
day=1,
|
43
|
-
# When Jan 1 is a Sunday, US markets observe the subsequent Monday.
|
44
|
-
# When Jan 1 is a Saturday (as in 2005 and 2011), no holiday is observed.
|
45
|
-
observance=sunday_to_monday,
|
46
|
-
)
|
47
|
-
USMartinLutherKingJrAfter1998 = Holiday(
|
48
|
-
"Dr. Martin Luther King Jr. Day",
|
49
|
-
month=1,
|
50
|
-
day=1,
|
51
|
-
# The US markets didn't observe MLK day as a holiday until 1998.
|
52
|
-
start_date=Timestamp("1998-01-01"),
|
53
|
-
offset=DateOffset(weekday=MO(3)),
|
54
|
-
)
|
55
|
-
USLincolnsBirthDayBefore1954 = Holiday(
|
56
|
-
"Lincoln" "s Birthday",
|
57
|
-
month=2,
|
58
|
-
day=12,
|
59
|
-
start_date=Timestamp("1874-01-01"),
|
60
|
-
end_date=Timestamp("1953-12-31"),
|
61
|
-
observance=sunday_to_monday,
|
62
|
-
)
|
63
|
-
USWashingtonsBirthDayBefore1964 = Holiday(
|
64
|
-
"Washington" "s Birthday",
|
65
|
-
month=2,
|
66
|
-
day=22,
|
67
|
-
start_date=Timestamp("1880-01-01"),
|
68
|
-
end_date=Timestamp("1963-12-31"),
|
69
|
-
observance=sunday_to_monday,
|
70
|
-
)
|
71
|
-
USWashingtonsBirthDay1964to1970 = Holiday(
|
72
|
-
"Washington" "s Birthday",
|
73
|
-
month=2,
|
74
|
-
day=22,
|
75
|
-
start_date=Timestamp("1964-01-01"),
|
76
|
-
end_date=Timestamp("1970-12-31"),
|
77
|
-
observance=nearest_workday,
|
78
|
-
)
|
79
|
-
USPresidentsDay = Holiday(
|
80
|
-
"President" "s Day",
|
81
|
-
start_date=Timestamp("1971-01-01"),
|
82
|
-
month=2,
|
83
|
-
day=1,
|
84
|
-
offset=DateOffset(weekday=MO(3)),
|
85
|
-
)
|
86
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
87
|
-
USThanksgivingDayBefore1939 = Holiday(
|
88
|
-
"Thanksgiving Before 1939",
|
89
|
-
start_date=Timestamp("1864-01-01"),
|
90
|
-
end_date=Timestamp("1938-12-31"),
|
91
|
-
month=11,
|
92
|
-
day=30,
|
93
|
-
offset=DateOffset(weekday=TH(-1)),
|
94
|
-
)
|
95
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
96
|
-
USThanksgivingDay1939to1941 = Holiday(
|
97
|
-
"Thanksgiving 1939 to 1941",
|
98
|
-
start_date=Timestamp("1939-01-01"),
|
99
|
-
end_date=Timestamp("1941-12-31"),
|
100
|
-
month=11,
|
101
|
-
day=30,
|
102
|
-
offset=DateOffset(weekday=TH(-2)),
|
103
|
-
)
|
104
|
-
USThanksgivingDay = Holiday(
|
105
|
-
"Thanksgiving",
|
106
|
-
start_date=Timestamp("1942-01-01"),
|
107
|
-
month=11,
|
108
|
-
day=1,
|
109
|
-
offset=DateOffset(weekday=TH(4)),
|
110
|
-
)
|
111
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
112
|
-
USMemorialDayBefore1964 = Holiday(
|
113
|
-
"Memorial Day",
|
114
|
-
month=5,
|
115
|
-
day=30,
|
116
|
-
end_date=Timestamp("1963-12-31"),
|
117
|
-
observance=sunday_to_monday,
|
118
|
-
)
|
119
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
120
|
-
USMemorialDay1964to1969 = Holiday(
|
121
|
-
"Memorial Day",
|
122
|
-
month=5,
|
123
|
-
day=30,
|
124
|
-
start_date=Timestamp("1964-01-01"),
|
125
|
-
end_date=Timestamp("1969-12-31"),
|
126
|
-
observance=nearest_workday,
|
127
|
-
)
|
128
|
-
USMemorialDay = Holiday(
|
129
|
-
# NOTE: The definition for Memorial Day is incorrect as of pandas 0.16.0.
|
130
|
-
# See https://github.com/pydata/pandas/issues/9760.
|
131
|
-
"Memorial Day",
|
132
|
-
month=5,
|
133
|
-
day=25,
|
134
|
-
start_date=Timestamp("1971-01-01"),
|
135
|
-
offset=DateOffset(weekday=MO(1)),
|
136
|
-
)
|
137
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
138
|
-
USIndependenceDayBefore1954 = Holiday(
|
139
|
-
"July 4th",
|
140
|
-
month=7,
|
141
|
-
day=4,
|
142
|
-
end_date=Timestamp("1953-12-31"),
|
143
|
-
observance=sunday_to_monday,
|
144
|
-
)
|
145
|
-
USIndependenceDay = Holiday(
|
146
|
-
"July 4th",
|
147
|
-
month=7,
|
148
|
-
day=4,
|
149
|
-
start_date=Timestamp("1954-01-01"),
|
150
|
-
observance=nearest_workday,
|
151
|
-
)
|
152
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
153
|
-
USElectionDay1848to1967 = Holiday(
|
154
|
-
"Election Day",
|
155
|
-
month=11,
|
156
|
-
day=2,
|
157
|
-
start_date=Timestamp("1848-1-1"),
|
158
|
-
end_date=Timestamp("1967-12-31"),
|
159
|
-
offset=DateOffset(weekday=TU(1)),
|
160
|
-
)
|
161
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
162
|
-
USElectionDay1968to1980 = Holiday(
|
163
|
-
"Election Day",
|
164
|
-
month=11,
|
165
|
-
day=2,
|
166
|
-
start_date=Timestamp("1968-01-01"),
|
167
|
-
end_date=Timestamp("1980-12-31"),
|
168
|
-
observance=following_tuesday_every_four_years_observance,
|
169
|
-
)
|
170
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
171
|
-
USVeteransDay1934to1953 = Holiday(
|
172
|
-
"Veteran Day",
|
173
|
-
month=11,
|
174
|
-
day=11,
|
175
|
-
start_date=Timestamp("1934-1-1"),
|
176
|
-
end_date=Timestamp("1953-12-31"),
|
177
|
-
observance=sunday_to_monday,
|
178
|
-
)
|
179
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
180
|
-
USColumbusDayBefore1954 = Holiday(
|
181
|
-
"Columbus Day",
|
182
|
-
month=10,
|
183
|
-
day=12,
|
184
|
-
end_date=Timestamp("1953-12-31"),
|
185
|
-
observance=sunday_to_monday,
|
186
|
-
)
|
187
|
-
ChristmasBefore1954 = Holiday(
|
188
|
-
"Christmas",
|
189
|
-
month=12,
|
190
|
-
day=25,
|
191
|
-
end_date=Timestamp("1953-12-31"),
|
192
|
-
observance=sunday_to_monday,
|
193
|
-
)
|
194
|
-
Christmas = Holiday(
|
195
|
-
"Christmas",
|
196
|
-
month=12,
|
197
|
-
day=25,
|
198
|
-
start_date=Timestamp("1954-01-01"),
|
199
|
-
observance=nearest_workday,
|
200
|
-
)
|
201
|
-
|
202
|
-
MonTuesThursBeforeIndependenceDay = Holiday(
|
203
|
-
# When July 4th is a Tuesday, Wednesday, or Friday, the previous day is a
|
204
|
-
# half day.
|
205
|
-
"Mondays, Tuesdays, and Thursdays Before Independence Day",
|
206
|
-
month=7,
|
207
|
-
day=3,
|
208
|
-
days_of_week=(MONDAY, TUESDAY, THURSDAY),
|
209
|
-
start_date=Timestamp("1995-01-01"),
|
210
|
-
)
|
211
|
-
FridayAfterIndependenceDayPre2013 = Holiday(
|
212
|
-
# When July 4th is a Thursday, the next day is a half day prior to 2013.
|
213
|
-
# Since 2013 the early close is on Wednesday and Friday is a full day
|
214
|
-
"Fridays after Independence Day prior to 2013",
|
215
|
-
month=7,
|
216
|
-
day=5,
|
217
|
-
days_of_week=(FRIDAY,),
|
218
|
-
start_date=Timestamp("1995-01-01"),
|
219
|
-
end_date=Timestamp("2012-12-31"),
|
220
|
-
)
|
221
|
-
WednesdayBeforeIndependenceDayPost2013 = Holiday(
|
222
|
-
# When July 4th is a Thursday, the next day is a half day prior to 2013.
|
223
|
-
# Since 2013 the early close is on Wednesday and Friday is a full day
|
224
|
-
"Wednesdays Before Independence Day including and after 2013",
|
225
|
-
month=7,
|
226
|
-
day=3,
|
227
|
-
days_of_week=(WEDNESDAY,),
|
228
|
-
start_date=Timestamp("2013-01-01"),
|
229
|
-
)
|
230
|
-
USBlackFridayBefore1993 = Holiday(
|
231
|
-
"Black Friday",
|
232
|
-
month=11,
|
233
|
-
day=1,
|
234
|
-
# Black Friday was not observed until 1992.
|
235
|
-
start_date=Timestamp("1992-01-01"),
|
236
|
-
end_date=Timestamp("1993-01-01"),
|
237
|
-
offset=[DateOffset(weekday=TH(4)), Day(1)],
|
238
|
-
)
|
239
|
-
USBlackFridayInOrAfter1993 = Holiday(
|
240
|
-
"Black Friday",
|
241
|
-
month=11,
|
242
|
-
day=1,
|
243
|
-
start_date=Timestamp("1993-01-01"),
|
244
|
-
offset=[DateOffset(weekday=TH(4)), Day(1)],
|
245
|
-
)
|
246
|
-
BattleOfGettysburg = Holiday(
|
247
|
-
# All of the floor traders in Chicago were sent to PA
|
248
|
-
"Markets were closed during the battle of Gettysburg",
|
249
|
-
month=7,
|
250
|
-
day=(1, 2, 3),
|
251
|
-
start_date=Timestamp("1863-07-01"),
|
252
|
-
end_date=Timestamp("1863-07-03"),
|
253
|
-
)
|
254
|
-
|
255
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
256
|
-
November29BacklogRelief = [
|
257
|
-
Timestamp("1929-11-01", tz="UTC"),
|
258
|
-
Timestamp("1929-11-29", tz="UTC"),
|
259
|
-
]
|
260
|
-
|
261
|
-
# https://en.wikipedia.org/wiki/March_1933#March_6,_1933_(Monday)
|
262
|
-
March33BankHoliday = [
|
263
|
-
Timestamp("1933-03-06", tz="UTC"),
|
264
|
-
Timestamp("1933-03-07", tz="UTC"),
|
265
|
-
Timestamp("1933-03-08", tz="UTC"),
|
266
|
-
Timestamp("1933-03-09", tz="UTC"),
|
267
|
-
Timestamp("1933-03-10", tz="UTC"),
|
268
|
-
Timestamp("1933-03-13", tz="UTC"),
|
269
|
-
Timestamp("1933-03-14", tz="UTC"),
|
270
|
-
]
|
271
|
-
|
272
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
273
|
-
August45VictoryOverJapan = date_range("1945-08-15", "1945-08-16", tz="UTC")
|
274
|
-
|
275
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
276
|
-
ChristmasEvesAdhoc = [
|
277
|
-
Timestamp("1945-12-24", tz="UTC"),
|
278
|
-
Timestamp("1956-12-24", tz="UTC"),
|
279
|
-
]
|
280
|
-
|
281
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
282
|
-
DayAfterChristmasAdhoc = [Timestamp("1958-12-26", tz="UTC")]
|
283
|
-
|
284
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
285
|
-
DayBeforeDecorationAdhoc = [Timestamp("1961-05-29", tz="UTC")]
|
286
|
-
|
287
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
288
|
-
LincolnsBirthDayAdhoc = [Timestamp("1968-02-12", tz="UTC")]
|
289
|
-
|
290
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
291
|
-
PaperworkCrisis68 = [
|
292
|
-
Timestamp("1968-06-12", tz="UTC"),
|
293
|
-
Timestamp("1968-06-19", tz="UTC"),
|
294
|
-
Timestamp("1968-06-26", tz="UTC"),
|
295
|
-
Timestamp("1968-07-10", tz="UTC"),
|
296
|
-
Timestamp("1968-07-17", tz="UTC"),
|
297
|
-
Timestamp("1968-07-24", tz="UTC"),
|
298
|
-
Timestamp("1968-07-31", tz="UTC"),
|
299
|
-
Timestamp("1968-08-07", tz="UTC"),
|
300
|
-
Timestamp("1968-08-14", tz="UTC"),
|
301
|
-
Timestamp("1968-08-21", tz="UTC"),
|
302
|
-
Timestamp("1968-08-28", tz="UTC"),
|
303
|
-
Timestamp("1968-09-11", tz="UTC"),
|
304
|
-
Timestamp("1968-09-18", tz="UTC"),
|
305
|
-
Timestamp("1968-09-25", tz="UTC"),
|
306
|
-
Timestamp("1968-10-02", tz="UTC"),
|
307
|
-
Timestamp("1968-10-09", tz="UTC"),
|
308
|
-
Timestamp("1968-10-16", tz="UTC"),
|
309
|
-
Timestamp("1968-10-23", tz="UTC"),
|
310
|
-
Timestamp("1968-10-30", tz="UTC"),
|
311
|
-
Timestamp("1968-11-11", tz="UTC"),
|
312
|
-
Timestamp("1968-11-20", tz="UTC"),
|
313
|
-
Timestamp("1968-12-04", tz="UTC"),
|
314
|
-
Timestamp("1968-12-11", tz="UTC"),
|
315
|
-
Timestamp("1968-12-18", tz="UTC"),
|
316
|
-
Timestamp("1968-12-25", tz="UTC"),
|
317
|
-
]
|
318
|
-
|
319
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
320
|
-
DayAfterIndependenceDayAdhoc = [Timestamp("1968-07-05", tz="UTC")]
|
321
|
-
|
322
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
323
|
-
WeatherSnowClosing = [Timestamp("1969-02-10", tz="UTC")]
|
324
|
-
|
325
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
326
|
-
FirstLunarLandingClosing = [Timestamp("1969-07-21", tz="UTC")]
|
327
|
-
|
328
|
-
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
329
|
-
NewYorkCityBlackout77 = [Timestamp("1977-07-14", tz="UTC")]
|
330
|
-
|
331
|
-
# http://en.wikipedia.org/wiki/Aftermath_of_the_September_11_attacks
|
332
|
-
September11Closings = [
|
333
|
-
Timestamp("2001-09-11", tz="UTC"),
|
334
|
-
Timestamp("2001-09-12", tz="UTC"),
|
335
|
-
Timestamp("2001-09-13", tz="UTC"),
|
336
|
-
Timestamp("2001-09-14", tz="UTC"),
|
337
|
-
]
|
338
|
-
|
339
|
-
# http://en.wikipedia.org/wiki/Hurricane_Gloria
|
340
|
-
HurricaneGloriaClosings = date_range("1985-09-27", "1985-09-27", tz="UTC")
|
341
|
-
|
342
|
-
# http://en.wikipedia.org/wiki/Hurricane_sandy
|
343
|
-
HurricaneSandyClosings = date_range("2012-10-29", "2012-10-30", tz="UTC")
|
344
|
-
|
345
|
-
# National Days of Mourning
|
346
|
-
# - President John F. Kennedy - November 25, 1963
|
347
|
-
# - Martin Luther King - April 9, 1968
|
348
|
-
# - President Dwight D. Eisenhower - March 31, 1969
|
349
|
-
# - President Harry S. Truman - December 28, 1972
|
350
|
-
# - President Lyndon B. Johnson - January 25, 1973
|
351
|
-
# - President Richard Nixon - April 27, 1994
|
352
|
-
# - President Ronald W. Reagan - June 11, 2004
|
353
|
-
# - President Gerald R. Ford - Jan 2, 2007
|
354
|
-
# - President George H.W. Bush - Dec 5, 2018
|
355
|
-
USNationalDaysofMourning = [
|
356
|
-
Timestamp("1963-11-25", tz="UTC"),
|
357
|
-
Timestamp("1968-04-09", tz="UTC"),
|
358
|
-
Timestamp("1969-03-31", tz="UTC"),
|
359
|
-
Timestamp("1972-12-28", tz="UTC"),
|
360
|
-
Timestamp("1973-01-25", tz="UTC"),
|
361
|
-
Timestamp("1994-04-27", tz="UTC"),
|
362
|
-
Timestamp("2004-06-11", tz="UTC"),
|
363
|
-
Timestamp("2007-01-02", tz="UTC"),
|
364
|
-
Timestamp("2018-12-05", tz="UTC"),
|
365
|
-
]
|
366
|
-
|
367
|
-
#######################################
|
368
|
-
# US Juneteenth (June 19th)
|
369
|
-
#######################################
|
370
|
-
USJuneteenthAfter2022 = Holiday(
|
371
|
-
"Juneteenth Starting at 2022",
|
372
|
-
start_date=Timestamp("2022-06-19"),
|
373
|
-
month=6,
|
374
|
-
day=19,
|
375
|
-
observance=nearest_workday,
|
376
|
-
)
|
1
|
+
from dateutil.relativedelta import MO, TH, TU
|
2
|
+
from pandas import DateOffset, Timestamp, date_range
|
3
|
+
from pandas.tseries.holiday import Holiday, nearest_workday, sunday_to_monday
|
4
|
+
from pandas.tseries.offsets import Day
|
5
|
+
|
6
|
+
from pandas_market_calendars.market_calendar import (
|
7
|
+
FRIDAY,
|
8
|
+
MONDAY,
|
9
|
+
THURSDAY,
|
10
|
+
TUESDAY,
|
11
|
+
WEDNESDAY,
|
12
|
+
)
|
13
|
+
|
14
|
+
|
15
|
+
# These have the same definition, but are used in different places because the
|
16
|
+
# NYSE closed at 2:00 PM on Christmas Eve until 1993.
|
17
|
+
|
18
|
+
|
19
|
+
def following_tuesday_every_four_years_observance(dt):
|
20
|
+
return dt + DateOffset(years=(4 - (dt.year % 4)) % 4, weekday=TU(1))
|
21
|
+
|
22
|
+
|
23
|
+
ChristmasEveBefore1993 = Holiday(
|
24
|
+
"Christmas Eve",
|
25
|
+
month=12,
|
26
|
+
day=24,
|
27
|
+
end_date=Timestamp("1993-01-01"),
|
28
|
+
# When Christmas is a Saturday, the 24th is a full holiday.
|
29
|
+
days_of_week=(MONDAY, TUESDAY, WEDNESDAY, THURSDAY),
|
30
|
+
)
|
31
|
+
ChristmasEveInOrAfter1993 = Holiday(
|
32
|
+
"Christmas Eve",
|
33
|
+
month=12,
|
34
|
+
day=24,
|
35
|
+
start_date=Timestamp("1993-01-01"),
|
36
|
+
# When Christmas is a Saturday, the 24th is a full holiday.
|
37
|
+
days_of_week=(MONDAY, TUESDAY, WEDNESDAY, THURSDAY),
|
38
|
+
)
|
39
|
+
USNewYearsDay = Holiday(
|
40
|
+
"New Years Day",
|
41
|
+
month=1,
|
42
|
+
day=1,
|
43
|
+
# When Jan 1 is a Sunday, US markets observe the subsequent Monday.
|
44
|
+
# When Jan 1 is a Saturday (as in 2005 and 2011), no holiday is observed.
|
45
|
+
observance=sunday_to_monday,
|
46
|
+
)
|
47
|
+
USMartinLutherKingJrAfter1998 = Holiday(
|
48
|
+
"Dr. Martin Luther King Jr. Day",
|
49
|
+
month=1,
|
50
|
+
day=1,
|
51
|
+
# The US markets didn't observe MLK day as a holiday until 1998.
|
52
|
+
start_date=Timestamp("1998-01-01"),
|
53
|
+
offset=DateOffset(weekday=MO(3)),
|
54
|
+
)
|
55
|
+
USLincolnsBirthDayBefore1954 = Holiday(
|
56
|
+
"Lincoln" "s Birthday",
|
57
|
+
month=2,
|
58
|
+
day=12,
|
59
|
+
start_date=Timestamp("1874-01-01"),
|
60
|
+
end_date=Timestamp("1953-12-31"),
|
61
|
+
observance=sunday_to_monday,
|
62
|
+
)
|
63
|
+
USWashingtonsBirthDayBefore1964 = Holiday(
|
64
|
+
"Washington" "s Birthday",
|
65
|
+
month=2,
|
66
|
+
day=22,
|
67
|
+
start_date=Timestamp("1880-01-01"),
|
68
|
+
end_date=Timestamp("1963-12-31"),
|
69
|
+
observance=sunday_to_monday,
|
70
|
+
)
|
71
|
+
USWashingtonsBirthDay1964to1970 = Holiday(
|
72
|
+
"Washington" "s Birthday",
|
73
|
+
month=2,
|
74
|
+
day=22,
|
75
|
+
start_date=Timestamp("1964-01-01"),
|
76
|
+
end_date=Timestamp("1970-12-31"),
|
77
|
+
observance=nearest_workday,
|
78
|
+
)
|
79
|
+
USPresidentsDay = Holiday(
|
80
|
+
"President" "s Day",
|
81
|
+
start_date=Timestamp("1971-01-01"),
|
82
|
+
month=2,
|
83
|
+
day=1,
|
84
|
+
offset=DateOffset(weekday=MO(3)),
|
85
|
+
)
|
86
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
87
|
+
USThanksgivingDayBefore1939 = Holiday(
|
88
|
+
"Thanksgiving Before 1939",
|
89
|
+
start_date=Timestamp("1864-01-01"),
|
90
|
+
end_date=Timestamp("1938-12-31"),
|
91
|
+
month=11,
|
92
|
+
day=30,
|
93
|
+
offset=DateOffset(weekday=TH(-1)),
|
94
|
+
)
|
95
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
96
|
+
USThanksgivingDay1939to1941 = Holiday(
|
97
|
+
"Thanksgiving 1939 to 1941",
|
98
|
+
start_date=Timestamp("1939-01-01"),
|
99
|
+
end_date=Timestamp("1941-12-31"),
|
100
|
+
month=11,
|
101
|
+
day=30,
|
102
|
+
offset=DateOffset(weekday=TH(-2)),
|
103
|
+
)
|
104
|
+
USThanksgivingDay = Holiday(
|
105
|
+
"Thanksgiving",
|
106
|
+
start_date=Timestamp("1942-01-01"),
|
107
|
+
month=11,
|
108
|
+
day=1,
|
109
|
+
offset=DateOffset(weekday=TH(4)),
|
110
|
+
)
|
111
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
112
|
+
USMemorialDayBefore1964 = Holiday(
|
113
|
+
"Memorial Day",
|
114
|
+
month=5,
|
115
|
+
day=30,
|
116
|
+
end_date=Timestamp("1963-12-31"),
|
117
|
+
observance=sunday_to_monday,
|
118
|
+
)
|
119
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
120
|
+
USMemorialDay1964to1969 = Holiday(
|
121
|
+
"Memorial Day",
|
122
|
+
month=5,
|
123
|
+
day=30,
|
124
|
+
start_date=Timestamp("1964-01-01"),
|
125
|
+
end_date=Timestamp("1969-12-31"),
|
126
|
+
observance=nearest_workday,
|
127
|
+
)
|
128
|
+
USMemorialDay = Holiday(
|
129
|
+
# NOTE: The definition for Memorial Day is incorrect as of pandas 0.16.0.
|
130
|
+
# See https://github.com/pydata/pandas/issues/9760.
|
131
|
+
"Memorial Day",
|
132
|
+
month=5,
|
133
|
+
day=25,
|
134
|
+
start_date=Timestamp("1971-01-01"),
|
135
|
+
offset=DateOffset(weekday=MO(1)),
|
136
|
+
)
|
137
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
138
|
+
USIndependenceDayBefore1954 = Holiday(
|
139
|
+
"July 4th",
|
140
|
+
month=7,
|
141
|
+
day=4,
|
142
|
+
end_date=Timestamp("1953-12-31"),
|
143
|
+
observance=sunday_to_monday,
|
144
|
+
)
|
145
|
+
USIndependenceDay = Holiday(
|
146
|
+
"July 4th",
|
147
|
+
month=7,
|
148
|
+
day=4,
|
149
|
+
start_date=Timestamp("1954-01-01"),
|
150
|
+
observance=nearest_workday,
|
151
|
+
)
|
152
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
153
|
+
USElectionDay1848to1967 = Holiday(
|
154
|
+
"Election Day",
|
155
|
+
month=11,
|
156
|
+
day=2,
|
157
|
+
start_date=Timestamp("1848-1-1"),
|
158
|
+
end_date=Timestamp("1967-12-31"),
|
159
|
+
offset=DateOffset(weekday=TU(1)),
|
160
|
+
)
|
161
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
162
|
+
USElectionDay1968to1980 = Holiday(
|
163
|
+
"Election Day",
|
164
|
+
month=11,
|
165
|
+
day=2,
|
166
|
+
start_date=Timestamp("1968-01-01"),
|
167
|
+
end_date=Timestamp("1980-12-31"),
|
168
|
+
observance=following_tuesday_every_four_years_observance,
|
169
|
+
)
|
170
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
171
|
+
USVeteransDay1934to1953 = Holiday(
|
172
|
+
"Veteran Day",
|
173
|
+
month=11,
|
174
|
+
day=11,
|
175
|
+
start_date=Timestamp("1934-1-1"),
|
176
|
+
end_date=Timestamp("1953-12-31"),
|
177
|
+
observance=sunday_to_monday,
|
178
|
+
)
|
179
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
180
|
+
USColumbusDayBefore1954 = Holiday(
|
181
|
+
"Columbus Day",
|
182
|
+
month=10,
|
183
|
+
day=12,
|
184
|
+
end_date=Timestamp("1953-12-31"),
|
185
|
+
observance=sunday_to_monday,
|
186
|
+
)
|
187
|
+
ChristmasBefore1954 = Holiday(
|
188
|
+
"Christmas",
|
189
|
+
month=12,
|
190
|
+
day=25,
|
191
|
+
end_date=Timestamp("1953-12-31"),
|
192
|
+
observance=sunday_to_monday,
|
193
|
+
)
|
194
|
+
Christmas = Holiday(
|
195
|
+
"Christmas",
|
196
|
+
month=12,
|
197
|
+
day=25,
|
198
|
+
start_date=Timestamp("1954-01-01"),
|
199
|
+
observance=nearest_workday,
|
200
|
+
)
|
201
|
+
|
202
|
+
MonTuesThursBeforeIndependenceDay = Holiday(
|
203
|
+
# When July 4th is a Tuesday, Wednesday, or Friday, the previous day is a
|
204
|
+
# half day.
|
205
|
+
"Mondays, Tuesdays, and Thursdays Before Independence Day",
|
206
|
+
month=7,
|
207
|
+
day=3,
|
208
|
+
days_of_week=(MONDAY, TUESDAY, THURSDAY),
|
209
|
+
start_date=Timestamp("1995-01-01"),
|
210
|
+
)
|
211
|
+
FridayAfterIndependenceDayPre2013 = Holiday(
|
212
|
+
# When July 4th is a Thursday, the next day is a half day prior to 2013.
|
213
|
+
# Since 2013 the early close is on Wednesday and Friday is a full day
|
214
|
+
"Fridays after Independence Day prior to 2013",
|
215
|
+
month=7,
|
216
|
+
day=5,
|
217
|
+
days_of_week=(FRIDAY,),
|
218
|
+
start_date=Timestamp("1995-01-01"),
|
219
|
+
end_date=Timestamp("2012-12-31"),
|
220
|
+
)
|
221
|
+
WednesdayBeforeIndependenceDayPost2013 = Holiday(
|
222
|
+
# When July 4th is a Thursday, the next day is a half day prior to 2013.
|
223
|
+
# Since 2013 the early close is on Wednesday and Friday is a full day
|
224
|
+
"Wednesdays Before Independence Day including and after 2013",
|
225
|
+
month=7,
|
226
|
+
day=3,
|
227
|
+
days_of_week=(WEDNESDAY,),
|
228
|
+
start_date=Timestamp("2013-01-01"),
|
229
|
+
)
|
230
|
+
USBlackFridayBefore1993 = Holiday(
|
231
|
+
"Black Friday",
|
232
|
+
month=11,
|
233
|
+
day=1,
|
234
|
+
# Black Friday was not observed until 1992.
|
235
|
+
start_date=Timestamp("1992-01-01"),
|
236
|
+
end_date=Timestamp("1993-01-01"),
|
237
|
+
offset=[DateOffset(weekday=TH(4)), Day(1)],
|
238
|
+
)
|
239
|
+
USBlackFridayInOrAfter1993 = Holiday(
|
240
|
+
"Black Friday",
|
241
|
+
month=11,
|
242
|
+
day=1,
|
243
|
+
start_date=Timestamp("1993-01-01"),
|
244
|
+
offset=[DateOffset(weekday=TH(4)), Day(1)],
|
245
|
+
)
|
246
|
+
BattleOfGettysburg = Holiday(
|
247
|
+
# All of the floor traders in Chicago were sent to PA
|
248
|
+
"Markets were closed during the battle of Gettysburg",
|
249
|
+
month=7,
|
250
|
+
day=(1, 2, 3),
|
251
|
+
start_date=Timestamp("1863-07-01"),
|
252
|
+
end_date=Timestamp("1863-07-03"),
|
253
|
+
)
|
254
|
+
|
255
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
256
|
+
November29BacklogRelief = [
|
257
|
+
Timestamp("1929-11-01", tz="UTC"),
|
258
|
+
Timestamp("1929-11-29", tz="UTC"),
|
259
|
+
]
|
260
|
+
|
261
|
+
# https://en.wikipedia.org/wiki/March_1933#March_6,_1933_(Monday)
|
262
|
+
March33BankHoliday = [
|
263
|
+
Timestamp("1933-03-06", tz="UTC"),
|
264
|
+
Timestamp("1933-03-07", tz="UTC"),
|
265
|
+
Timestamp("1933-03-08", tz="UTC"),
|
266
|
+
Timestamp("1933-03-09", tz="UTC"),
|
267
|
+
Timestamp("1933-03-10", tz="UTC"),
|
268
|
+
Timestamp("1933-03-13", tz="UTC"),
|
269
|
+
Timestamp("1933-03-14", tz="UTC"),
|
270
|
+
]
|
271
|
+
|
272
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
273
|
+
August45VictoryOverJapan = date_range("1945-08-15", "1945-08-16", tz="UTC")
|
274
|
+
|
275
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
276
|
+
ChristmasEvesAdhoc = [
|
277
|
+
Timestamp("1945-12-24", tz="UTC"),
|
278
|
+
Timestamp("1956-12-24", tz="UTC"),
|
279
|
+
]
|
280
|
+
|
281
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
282
|
+
DayAfterChristmasAdhoc = [Timestamp("1958-12-26", tz="UTC")]
|
283
|
+
|
284
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
285
|
+
DayBeforeDecorationAdhoc = [Timestamp("1961-05-29", tz="UTC")]
|
286
|
+
|
287
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
288
|
+
LincolnsBirthDayAdhoc = [Timestamp("1968-02-12", tz="UTC")]
|
289
|
+
|
290
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
291
|
+
PaperworkCrisis68 = [
|
292
|
+
Timestamp("1968-06-12", tz="UTC"),
|
293
|
+
Timestamp("1968-06-19", tz="UTC"),
|
294
|
+
Timestamp("1968-06-26", tz="UTC"),
|
295
|
+
Timestamp("1968-07-10", tz="UTC"),
|
296
|
+
Timestamp("1968-07-17", tz="UTC"),
|
297
|
+
Timestamp("1968-07-24", tz="UTC"),
|
298
|
+
Timestamp("1968-07-31", tz="UTC"),
|
299
|
+
Timestamp("1968-08-07", tz="UTC"),
|
300
|
+
Timestamp("1968-08-14", tz="UTC"),
|
301
|
+
Timestamp("1968-08-21", tz="UTC"),
|
302
|
+
Timestamp("1968-08-28", tz="UTC"),
|
303
|
+
Timestamp("1968-09-11", tz="UTC"),
|
304
|
+
Timestamp("1968-09-18", tz="UTC"),
|
305
|
+
Timestamp("1968-09-25", tz="UTC"),
|
306
|
+
Timestamp("1968-10-02", tz="UTC"),
|
307
|
+
Timestamp("1968-10-09", tz="UTC"),
|
308
|
+
Timestamp("1968-10-16", tz="UTC"),
|
309
|
+
Timestamp("1968-10-23", tz="UTC"),
|
310
|
+
Timestamp("1968-10-30", tz="UTC"),
|
311
|
+
Timestamp("1968-11-11", tz="UTC"),
|
312
|
+
Timestamp("1968-11-20", tz="UTC"),
|
313
|
+
Timestamp("1968-12-04", tz="UTC"),
|
314
|
+
Timestamp("1968-12-11", tz="UTC"),
|
315
|
+
Timestamp("1968-12-18", tz="UTC"),
|
316
|
+
Timestamp("1968-12-25", tz="UTC"),
|
317
|
+
]
|
318
|
+
|
319
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
320
|
+
DayAfterIndependenceDayAdhoc = [Timestamp("1968-07-05", tz="UTC")]
|
321
|
+
|
322
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
323
|
+
WeatherSnowClosing = [Timestamp("1969-02-10", tz="UTC")]
|
324
|
+
|
325
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
326
|
+
FirstLunarLandingClosing = [Timestamp("1969-07-21", tz="UTC")]
|
327
|
+
|
328
|
+
# http://www.tradingtheodds.com/nyse-full-day-closings/
|
329
|
+
NewYorkCityBlackout77 = [Timestamp("1977-07-14", tz="UTC")]
|
330
|
+
|
331
|
+
# http://en.wikipedia.org/wiki/Aftermath_of_the_September_11_attacks
|
332
|
+
September11Closings = [
|
333
|
+
Timestamp("2001-09-11", tz="UTC"),
|
334
|
+
Timestamp("2001-09-12", tz="UTC"),
|
335
|
+
Timestamp("2001-09-13", tz="UTC"),
|
336
|
+
Timestamp("2001-09-14", tz="UTC"),
|
337
|
+
]
|
338
|
+
|
339
|
+
# http://en.wikipedia.org/wiki/Hurricane_Gloria
|
340
|
+
HurricaneGloriaClosings = date_range("1985-09-27", "1985-09-27", tz="UTC")
|
341
|
+
|
342
|
+
# http://en.wikipedia.org/wiki/Hurricane_sandy
|
343
|
+
HurricaneSandyClosings = date_range("2012-10-29", "2012-10-30", tz="UTC")
|
344
|
+
|
345
|
+
# National Days of Mourning
|
346
|
+
# - President John F. Kennedy - November 25, 1963
|
347
|
+
# - Martin Luther King - April 9, 1968
|
348
|
+
# - President Dwight D. Eisenhower - March 31, 1969
|
349
|
+
# - President Harry S. Truman - December 28, 1972
|
350
|
+
# - President Lyndon B. Johnson - January 25, 1973
|
351
|
+
# - President Richard Nixon - April 27, 1994
|
352
|
+
# - President Ronald W. Reagan - June 11, 2004
|
353
|
+
# - President Gerald R. Ford - Jan 2, 2007
|
354
|
+
# - President George H.W. Bush - Dec 5, 2018
|
355
|
+
USNationalDaysofMourning = [
|
356
|
+
Timestamp("1963-11-25", tz="UTC"),
|
357
|
+
Timestamp("1968-04-09", tz="UTC"),
|
358
|
+
Timestamp("1969-03-31", tz="UTC"),
|
359
|
+
Timestamp("1972-12-28", tz="UTC"),
|
360
|
+
Timestamp("1973-01-25", tz="UTC"),
|
361
|
+
Timestamp("1994-04-27", tz="UTC"),
|
362
|
+
Timestamp("2004-06-11", tz="UTC"),
|
363
|
+
Timestamp("2007-01-02", tz="UTC"),
|
364
|
+
Timestamp("2018-12-05", tz="UTC"),
|
365
|
+
]
|
366
|
+
|
367
|
+
#######################################
|
368
|
+
# US Juneteenth (June 19th)
|
369
|
+
#######################################
|
370
|
+
USJuneteenthAfter2022 = Holiday(
|
371
|
+
"Juneteenth Starting at 2022",
|
372
|
+
start_date=Timestamp("2022-06-19"),
|
373
|
+
month=6,
|
374
|
+
day=19,
|
375
|
+
observance=nearest_workday,
|
376
|
+
)
|