-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathus.jl
242 lines (220 loc) · 7.27 KB
/
us.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# United States calendars
"""
United States federal holidays.
"""
struct USSettlement <: HolidayCalendar end
const UnitedStates = USSettlement
"""
United States NYSE holidays.
"""
struct USNYSE <: HolidayCalendar end
"""
United States Government Bond calendar. See <https://www.sifma.org/resources/general/holiday-schedule/>.
"""
struct USGovernmentBond <: HolidayCalendar end
function isholiday(::USSettlement , dt::Dates.Date)
yy = Dates.year(dt)
mm = Dates.month(dt)
dd = Dates.day(dt)
if (
# New Year's Day
adjustweekendholidayUS(Dates.Date(yy, 1, 1)) == dt
||
# New Year's Day on the previous year when 1st Jan is Saturday
(mm == 12 && dd == 31 && Dates.dayofweek(dt) == Dates.Friday)
||
# Birthday of Martin Luther King, Jr.
(yy >= 1983 && adjustweekendholidayUS(findweekday(Dates.Monday, yy, 1, 3, true)) == dt)
||
# Washington's Birthday
adjustweekendholidayUS(findweekday(Dates.Monday, yy, 2, 3, true)) == dt
||
# Memorial Day
adjustweekendholidayUS(findweekday(Dates.Monday, yy, 5, 1, false)) == dt
||
# Juneteenth
(yy >= 2021 && adjustweekendholidayUS(Dates.Date(yy, 6, 19)) == dt)
||
# Independence Day
adjustweekendholidayUS(Dates.Date(yy, 7, 4)) == dt
||
# Labor Day
adjustweekendholidayUS(findweekday(Dates.Monday, yy, 9, 1, true)) == dt
||
# Columbus Day
adjustweekendholidayUS(findweekday(Dates.Monday, yy, 10, 2, true)) == dt
||
# Veterans Day
adjustweekendholidayUS(Dates.Date(yy, 11, 11)) == dt
||
# Thanksgiving Day
adjustweekendholidayUS(findweekday(Dates.Thursday, yy, 11, 4, true)) == dt
||
# Christmas
adjustweekendholidayUS(Dates.Date(yy, 12, 25)) == dt
)
return true
end
return false
end
function isholiday(::USNYSE , dt::Dates.Date)
yy = Dates.year(dt)
mm = Dates.month(dt)
dd = Dates.day(dt)
dt_rata::Int = Dates.days(dt)
e_rata::Int = easter_rata(Dates.Year(yy))
if (
# New Year's Day
adjustweekendholidayUS(Dates.Date(yy, 1, 1)) == dt
||
# Birthday of Martin Luther King, Jr.
(yy >= 1998 && adjustweekendholidayUS(findweekday(Dates.Monday, yy, 1, 3, true)) == dt)
||
# Washington's Birthday
adjustweekendholidayUS(findweekday(Dates.Monday, yy, 2, 3, true)) == dt
||
# Good Friday
dt_rata == ( e_rata - 2 )
||
# Memorial Day
adjustweekendholidayUS(findweekday(Dates.Monday, yy, 5, 1, false)) == dt
||
# Juneteenth
(yy >= 2022 && adjustweekendholidayUS(Dates.Date(yy, 6, 19)) == dt)
||
# Independence Day
adjustweekendholidayUS(Dates.Date(yy, 7, 4)) == dt
||
# Labor Day
adjustweekendholidayUS(findweekday(Dates.Monday, yy, 9, 1, true)) == dt
||
# Thanksgiving Day
adjustweekendholidayUS(findweekday(Dates.Thursday, yy, 11, 4, true)) == dt
||
# Christmas
adjustweekendholidayUS(Dates.Date(yy, 12, 25)) == dt
)
return true
end
# Presidential election days
if (yy <= 1968 || (yy <= 1980 && yy % 4 == 0)) && mm == 11 && dd <= 7 && Dates.istuesday(dt)
return true
end
# Special Closings
if (
# President George H.W. Bush's funeral
dt == Dates.Date(2018,12,5)
||
# Hurricane Sandy
yy == 2012 && mm == 10 && (dd == 29 || dd == 30)
||
# Predient Ford's funeral
dt == Dates.Date(2007,1,2)
||
# President Reagan's funeral
dt == Dates.Date(2004,6,11)
||
# Sep 11th
yy == 2001 && mm == 9 && ( 11 <= dd && dd <= 14)
||
# President Nixon's funeral
dt == Dates.Date(1994,4,27)
||
# Hurricane Gloria
dt == Dates.Date(1985,9,27)
||
# 1977 Blackout
dt == Dates.Date(1977,7,14)
||
# Funeral of former President Lyndon B. Johnson
dt == Dates.Date(1973,1,25)
||
# Funeral of former President Harry S. Truman
dt == Dates.Date(1972,12,28)
||
# National Day of Participation for the lunar exploration
dt == Dates.Date(1969,7,21)
||
# Eisenhower's funeral
dt == Dates.Date(1969,3,31)
||
# Heavy snow
dt == Dates.Date(1969,2,10)
||
# Day after Independence Day
dt == Dates.Date(1968,7,5)
||
# Paperwork Crisis
yy == 1968 && Dates.dayofyear(dt) >= 163 && Dates.iswednesday(dt)
||
# Mourning for Martin Luther King Jr
dt == Dates.Date(1968,4,9)
||
# President Kennedy's funeral
dt == Dates.Date(1963,11,25)
||
# Day before Decoration Day
dt == Dates.Date(1961,5,29)
||
# Day after Christmas
dt == Dates.Date(1958,12,26)
||
# Christmas Eve
dt in [Dates.Date(1954,12,24), Dates.Date(1956,12,24), Dates.Date(1965,12,24)]
)
return true
end
return false
end
function isholiday(::USGovernmentBond , dt::Dates.Date)
yy = Dates.year(dt)
mm = Dates.month(dt)
dd = Dates.day(dt)
dt_rata::Int = Dates.days(dt)
e_rata::Int = easter_rata(Dates.Year(yy))
if (
# New Year's Day
adjustweekendholidayUS(Dates.Date(yy, 1, 1)) == dt
||
# Birthday of Martin Luther King, Jr.
yy >= 1983 && adjustweekendholidayUS(findweekday(Dates.Monday, yy, 1, 3, true)) == dt
||
# Washington's Birthday
adjustweekendholidayUS(findweekday(Dates.Monday, yy, 2, 3, true)) == dt
||
# Good Friday
dt_rata == ( e_rata - 2 )
||
# Memorial Day
adjustweekendholidayUS(findweekday(Dates.Monday, yy, 5, 1, false)) == dt
||
# Juneteenth
(yy >= 2022 && adjustweekendholidayUS(Dates.Date(yy, 6, 19)) == dt)
||
# Independence Day
adjustweekendholidayUS(Dates.Date(yy, 7, 4)) == dt
||
# Labor Day
adjustweekendholidayUS(findweekday(Dates.Monday, yy, 9, 1, true)) == dt
||
# Columbus Day
adjustweekendholidayUS(findweekday(Dates.Monday, yy, 10, 2, true)) == dt
||
# Veterans Day
adjustweekendholidayUS(Dates.Date(yy, 11, 11)) == dt
||
# Thanksgiving Day
adjustweekendholidayUS(findweekday(Dates.Thursday, yy, 11, 4, true)) == dt
||
# Christmas
adjustweekendholidayUS(Dates.Date(yy, 12, 25)) == dt
)
return true
end
# Special Closings
# President George H.W. Bush's funeral <https://www.newyorkfed.org/markets/opolicy/operating_policy_181204>
if dt == Dates.Date(2018, 12, 5)
return true
end
return false
end