-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathruntests.jl
More file actions
366 lines (308 loc) · 22.9 KB
/
Copy pathruntests.jl
File metadata and controls
366 lines (308 loc) · 22.9 KB
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
using DayCounts, Dates
using Test
# based on tests from OpenGamma Strata
# https://github.com/OpenGamma/Strata/blob/efaa0be0d08dc61c23692e7b86df101ea0fb7223/modules/basics/src/test/java/com/opengamma/strata/basics/date/DayCountTest.java
@testset "Actual365Fixed" begin
dc = DayCounts.Actual365Fixed()
@test yearfrac(Date(2011,12,28), Date(2012, 2,28), dc) == (4 + 58) / 365
@test yearfrac(Date(2011,12,28), Date(2012, 2,29), dc) == (4 + 59) / 365
@test yearfrac(Date(2011,12,28), Date(2012, 3, 1), dc) == (4 + 60) / 365
@test yearfrac(Date(2011,12,28), Date(2016, 2,28), dc) == (4 + 366 + 365 + 365 + 365 + 58) / 365
@test yearfrac(Date(2011,12,28), Date(2016, 2,29), dc) == (4 + 366 + 365 + 365 + 365 + 59) / 365
@test yearfrac(Date(2011,12,28), Date(2016, 3, 1), dc) == (4 + 366 + 365 + 365 + 365 + 60) / 365
@test yearfrac(Date(2012, 2,28), Date(2012, 3,28), dc) == 29 / 365
@test yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc) == 28 / 365
@test yearfrac(Date(2012, 3, 1), Date(2012, 3,28), dc) == 27 / 365
# zeros
@test yearfrac(Date(2011,12,28), Date(2011,12,28), dc) == 0
@test yearfrac(Date(2011,12,31), Date(2011,12,31), dc) == 0
@test yearfrac(Date(2012, 2,28), Date(2012, 2,28), dc) == 0
@test yearfrac(Date(2012, 2,29), Date(2012, 2,29), dc) == 0
# reflection
@test yearfrac(Date(2012, 2,28), Date(2011,12,28), dc) == -yearfrac(Date(2011,12,28), Date(2012, 2,28), dc)
@test yearfrac(Date(2012, 3,28), Date(2012, 2,29), dc) == -yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc)
end
@testset "Actual360" begin
dc = DayCounts.Actual360()
@test yearfrac(Date(2011,12,28), Date(2012, 2,28), dc) == (4 + 58) / 360
@test yearfrac(Date(2011,12,28), Date(2012, 2,29), dc) == (4 + 59) / 360
@test yearfrac(Date(2011,12,28), Date(2012, 3, 1), dc) == (4 + 60) / 360
@test yearfrac(Date(2011,12,28), Date(2016, 2,28), dc) == (4 + 366 + 365 + 365 + 365 + 58) / 360
@test yearfrac(Date(2011,12,28), Date(2016, 2,29), dc) == (4 + 366 + 365 + 365 + 365 + 59) / 360
@test yearfrac(Date(2011,12,28), Date(2016, 3, 1), dc) == (4 + 366 + 365 + 365 + 365 + 60) / 360
@test yearfrac(Date(2012, 2,28), Date(2012, 3,28), dc) == 29 / 360
@test yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc) == 28 / 360
@test yearfrac(Date(2012, 3, 1), Date(2012, 3,28), dc) == 27 / 360
# zeros
@test yearfrac(Date(2011,12,28), Date(2011,12,28), dc) == 0
@test yearfrac(Date(2011,12,31), Date(2011,12,31), dc) == 0
@test yearfrac(Date(2012, 2,28), Date(2012, 2,28), dc) == 0
@test yearfrac(Date(2012, 2,29), Date(2012, 2,29), dc) == 0
# reflection
@test yearfrac(Date(2012, 2,28), Date(2011,12,28), dc) == -yearfrac(Date(2011,12,28), Date(2012, 2,28), dc)
@test yearfrac(Date(2012, 3,28), Date(2012, 2,29), dc) == -yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc)
end
@testset "ActualActualISDA" begin
dc = DayCounts.ActualActualISDA()
@test yearfrac(Date(2011,12,28), Date(2012, 2,28), dc) == 4 / 365 + 58 / 366
@test yearfrac(Date(2011,12,28), Date(2012, 2,29), dc) == 4 / 365 + 59 / 366
@test yearfrac(Date(2011,12,28), Date(2012, 3, 1), dc) == 4 / 365 + 60 / 366
@test yearfrac(Date(2011,12,28), Date(2016, 2,28), dc) == 4 / 365 + 58 / 366 + 4
@test yearfrac(Date(2011,12,28), Date(2016, 2,29), dc) == 4 / 365 + 59 / 366 + 4
@test yearfrac(Date(2011,12,28), Date(2016, 3, 1), dc) == 4 / 365 + 60 / 366 + 4
@test yearfrac(Date(2012, 2,28), Date(2012, 3,28), dc) == 29 / 366
@test yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc) == 28 / 366
@test yearfrac(Date(2012, 3, 1), Date(2012, 3,28), dc) == 27 / 366
# zeros
@test yearfrac(Date(2011,12,28), Date(2011,12,28), dc) == 0
@test yearfrac(Date(2011,12,31), Date(2011,12,31), dc) == 0
@test yearfrac(Date(2012, 2,28), Date(2012, 2,28), dc) == 0
@test yearfrac(Date(2012, 2,29), Date(2012, 2,29), dc) == 0
# reflection
@test yearfrac(Date(2012, 2,28), Date(2011,12,28), dc) == -yearfrac(Date(2011,12,28), Date(2012, 2,28), dc)
@test yearfrac(Date(2012, 3,28), Date(2012, 2,29), dc) == -yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc)
end
@testset "Thirty360" begin
dc = DayCounts.Thirty360()
# usual rule: ((d2-d1) + (m2-m1)*30 + (y2-y1)*360)/360
@test yearfrac(Date(2011,12,28), Date(2012, 2,28), dc) == ((28-28) + (2-12)*30 + (2012-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2012, 2,29), dc) == ((29-28) + (2-12)*30 + (2012-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2012, 3, 1), dc) == ((1-28) + (3-12)*30 + (2012-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2016, 2,28), dc) == ((28-28) + (2-12)*30 + (2016-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2016, 2,29), dc) == ((29-28) + (2-12)*30 + (2016-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2016, 3, 1), dc) == ((1-28) + (3-12)*30 + (2016-2011)*360)/360
@test yearfrac(Date(2012, 2,28), Date(2012, 3,28), dc) == ((28-28) + (3-2)*30 + (2012-2012)*360)/360
@test yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc) == ((28-29) + (3-2)*30 + (2012-2012)*360)/360
@test yearfrac(Date(2012, 3, 1), Date(2012, 3,28), dc) == ((28-1) + (3-3)*30 + (2012-2012)*360)/360
@test yearfrac(Date(2012, 5,29), Date(2013, 8,29), dc) == ((29-29) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,29), Date(2013, 8,30), dc) == ((30-29) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,29), Date(2013, 8,31), dc) == ((31-29) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,30), Date(2013, 8,29), dc) == ((29-30) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,30), Date(2013, 8,30), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,30), Date(2013, 8,31), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,31), Date(2013, 8,29), dc) == ((29-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,31), Date(2013, 8,30), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,31), Date(2013, 8,31), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
# zeros
@test yearfrac(Date(2011,12,28), Date(2011,12,28), dc) == 0
@test yearfrac(Date(2011,12,31), Date(2011,12,31), dc) == 0
@test yearfrac(Date(2012, 2,28), Date(2012, 2,28), dc) == 0
@test yearfrac(Date(2012, 2,29), Date(2012, 2,29), dc) == 0
# reflection
@test yearfrac(Date(2012, 2,28), Date(2011,12,28), dc) == -yearfrac(Date(2011,12,28), Date(2012, 2,28), dc)
@test yearfrac(Date(2012, 3,28), Date(2012, 2,29), dc) == -yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc)
end
@testset "ThirtyE360" begin
dc = DayCounts.ThirtyE360()
# usual rule: ((d2-d1) + (m2-m1)*30 + (y2-y1)*360)/360
@test yearfrac(Date(2011,12,28), Date(2012, 2,28), dc) == ((28-28) + (2-12)*30 + (2012-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2012, 2,29), dc) == ((29-28) + (2-12)*30 + (2012-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2012, 3, 1), dc) == ((1-28) + (3-12)*30 + (2012-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2016, 2,28), dc) == ((28-28) + (2-12)*30 + (2016-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2016, 2,29), dc) == ((29-28) + (2-12)*30 + (2016-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2016, 3, 1), dc) == ((1-28) + (3-12)*30 + (2016-2011)*360)/360
@test yearfrac(Date(2012, 2,28), Date(2012, 3,28), dc) == ((28-28) + (3-2)*30 + (2012-2012)*360)/360
@test yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc) == ((28-29) + (3-2)*30 + (2012-2012)*360)/360
@test yearfrac(Date(2012, 3, 1), Date(2012, 3,28), dc) == ((28-1) + (3-3)*30 + (2012-2012)*360)/360
@test yearfrac(Date(2012, 5,29), Date(2013, 8,29), dc) == ((29-29) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,29), Date(2013, 8,30), dc) == ((30-29) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,29), Date(2013, 8,31), dc) == ((30-29) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,30), Date(2013, 8,29), dc) == ((29-30) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,30), Date(2013, 8,30), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,30), Date(2013, 8,31), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,31), Date(2013, 8,29), dc) == ((29-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,31), Date(2013, 8,30), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,31), Date(2013, 8,31), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
# zeros
@test yearfrac(Date(2011,12,28), Date(2011,12,28), dc) == 0
@test yearfrac(Date(2011,12,31), Date(2011,12,31), dc) == 0
@test yearfrac(Date(2012, 2,28), Date(2012, 2,28), dc) == 0
@test yearfrac(Date(2012, 2,29), Date(2012, 2,29), dc) == 0
# reflection
@test yearfrac(Date(2012, 2,28), Date(2011,12,28), dc) == -yearfrac(Date(2011,12,28), Date(2012, 2,28), dc)
@test yearfrac(Date(2012, 3,28), Date(2012, 2,29), dc) == -yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc)
end
@testset "ThirtyE360ISDA" begin
@testset "maturity not end of Feb" begin
dc = DayCounts.ThirtyE360ISDA(Date(2012, 8, 31))
@test yearfrac(Date(2011,12,28), Date(2012, 2,28), dc) == ((28-28) + (2-12)*30 + (2012-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2012, 2,29), dc) == ((30-28) + (2-12)*30 + (2012-2011)*360)/360 # exception
@test yearfrac(Date(2011,12,28), Date(2012, 3, 1), dc) == ((1-28) + (3-12)*30 + (2012-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2016, 2,28), dc) == ((28-28) + (2-12)*30 + (2016-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2016, 2,29), dc) == ((30-28) + (2-12)*30 + (2016-2011)*360)/360 # exception
@test yearfrac(Date(2011,12,28), Date(2016, 3, 1), dc) == ((1-28) + (3-12)*30 + (2016-2011)*360)/360
@test yearfrac(Date(2012, 2,28), Date(2012, 3,28), dc) == ((28-28) + (3-2)*30 + (2012-2012)*360)/360
@test yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc) == ((28-30) + (3-2)*30 + (2012-2012)*360)/360 # exception
@test yearfrac(Date(2012, 3, 1), Date(2012, 3,28), dc) == ((28-1) + (3-3)*30 + (2012-2012)*360)/360
@test yearfrac(Date(2012, 5,29), Date(2013, 8,29), dc) == ((29-29) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,29), Date(2013, 8,30), dc) == ((30-29) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,29), Date(2013, 8,31), dc) == ((30-29) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,30), Date(2013, 8,29), dc) == ((29-30) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,30), Date(2013, 8,30), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,30), Date(2013, 8,31), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,31), Date(2013, 8,29), dc) == ((29-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,31), Date(2013, 8,30), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,31), Date(2013, 8,31), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
# zeros
@test yearfrac(Date(2011,12,28), Date(2011,12,28), dc) == 0
@test yearfrac(Date(2011,12,31), Date(2011,12,31), dc) == 0
@test yearfrac(Date(2012, 2,28), Date(2012, 2,28), dc) == 0
@test yearfrac(Date(2012, 2,29), Date(2012, 2,29), dc) == 0
# reflection
@test yearfrac(Date(2012, 2,28), Date(2011,12,28), dc) == -yearfrac(Date(2011,12,28), Date(2012, 2,28), dc)
@test yearfrac(Date(2012, 3,28), Date(2012, 2,29), dc) == -yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc)
end
@testset "maturity end of Feb" begin
dc = DayCounts.ThirtyE360ISDA(Date(2012, 2,29)) # leap year, end of month
@test yearfrac(Date(2011,12,28), Date(2012, 2,28), dc) == ((28-28) + (2-12)*30 + (2012-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2012, 2,29), dc) == ((29-28) + (2-12)*30 + (2012-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2012, 3, 1), dc) == ((1-28) + (3-12)*30 + (2012-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2016, 2,28), dc) == ((28-28) + (2-12)*30 + (2016-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2016, 2,29), dc) == ((30-28) + (2-12)*30 + (2016-2011)*360)/360 # exception
@test yearfrac(Date(2011,12,28), Date(2016, 3, 1), dc) == ((1-28) + (3-12)*30 + (2016-2011)*360)/360
@test yearfrac(Date(2012, 2,28), Date(2012, 3,28), dc) == ((28-28) + (3-2)*30 + (2012-2012)*360)/360
@test yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc) == ((28-30) + (3-2)*30 + (2012-2012)*360)/360 # exception
@test yearfrac(Date(2012, 3, 1), Date(2012, 3,28), dc) == ((28-1) + (3-3)*30 + (2012-2012)*360)/360
@test yearfrac(Date(2012, 5,29), Date(2013, 8,29), dc) == ((29-29) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,29), Date(2013, 8,30), dc) == ((30-29) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,29), Date(2013, 8,31), dc) == ((30-29) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,30), Date(2013, 8,29), dc) == ((29-30) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,30), Date(2013, 8,30), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,30), Date(2013, 8,31), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,31), Date(2013, 8,29), dc) == ((29-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,31), Date(2013, 8,30), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,31), Date(2013, 8,31), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
# zeros
@test yearfrac(Date(2011,12,28), Date(2011,12,28), dc) == 0
@test yearfrac(Date(2011,12,31), Date(2011,12,31), dc) == 0
@test yearfrac(Date(2012, 2,28), Date(2012, 2,28), dc) == 0
@test yearfrac(Date(2012, 2,29), Date(2012, 2,29), dc) == 0
# reflection
@test yearfrac(Date(2012, 2,28), Date(2011,12,28), dc) == -yearfrac(Date(2011,12,28), Date(2012, 2,28), dc)
@test yearfrac(Date(2012, 3,28), Date(2012, 2,29), dc) == -yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc)
end
end
@testset "ActualActualICMA" begin
dc = DayCounts.ActualActualICMA(Date(2011,7,1):Month(6):Date(2012,7,1))
# zeros
@test yearfrac(Date(2011,12,28), Date(2011,12,28), dc) == 0
@test yearfrac(Date(2011,12,31), Date(2011,12,31), dc) == 0
@test yearfrac(Date(2012, 2,28), Date(2012, 2,28), dc) == 0
@test yearfrac(Date(2012, 2,29), Date(2012, 2,29), dc) == 0
# reflection
@test yearfrac(Date(2012, 2,28), Date(2011,12,28), dc) == -yearfrac(Date(2011,12,28), Date(2012, 2,28), dc)
@test yearfrac(Date(2012, 3,28), Date(2012, 2,29), dc) == -yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc)
end
@testset "ActuaActual ISDA Memo" begin
# these test cases are all derived from
# The Actual/Actual Day Count Fraction, ISDA
# Paper for use with the ISDA Market Conventions Survey - 3rd June 1999
# https://www.isda.org/a/pIJEE/The-Actual-Actual-Day-Count-Fraction-1999.pdf
@testset "Semi-annual payment" begin
dc_isda = DayCounts.ActualActualISDA()
dc_icma = DayCounts.ActualActualICMA(Date(2003,11,1):Month(6):Date(2004,5,1))
@test yearfrac(Date(2003,11,1), Date(2004,5,1), dc_isda) == (61/365 + 121/366)
@test yearfrac(Date(2003,11,1), Date(2004,5,1), dc_icma) == 182/(2*182)
end
@testset "short first" begin
dc_isda = DayCounts.ActualActualISDA()
dc_icma = DayCounts.ActualActualICMA(Date(1998,7,1):Month(12):Date(2000,7,1))
@test yearfrac(Date(1999,2,1), Date(1999,7,1), dc_isda) == 150/365
@test yearfrac(Date(1999,2,1), Date(1999,7,1), dc_icma) ≈ 150/365 atol=eps()
@test yearfrac(Date(1999,7,1), Date(2000,7,1), dc_isda) == 184/365 + 182/366
@test yearfrac(Date(1999,7,1), Date(2000,7,1), dc_icma) == 366/366
@test yearfrac(Date(1999,2,1), Date(2000,7,1), dc_isda) == (150 + 184)/365 + 182/366
@test yearfrac(Date(1999,2,1), Date(2000,7,1), dc_icma) ≈ 150/365 + 366/366 atol=eps()
end
@testset "long first" begin
dc_isda = DayCounts.ActualActualISDA()
dc_icma = DayCounts.ActualActualICMA(Date(2002,7,15):Month(6):Date(2004,1,15))
@test yearfrac(Date(2002,8,15), Date(2003,7,15), dc_isda) == 334/365
@test yearfrac(Date(2002,8,15), Date(2003,7,15), dc_icma) == 181/(181*2) + 153/(184*2)
@test yearfrac(Date(2003,7,15),Date(2004,1,15), dc_isda) == 170/365 + 14/366
@test yearfrac(Date(2003,7,15), Date(2004,1,15), dc_icma) == 184/(184*2)
@test yearfrac(Date(2002,8,15), Date(2004,1,15), dc_isda) ≈ (334+170)/365 + 14/366 rtol=eps()
@test yearfrac(Date(2002,8,15), Date(2004,1,15), dc_icma) == 181/(181*2) + (153+184)/(184*2)
end
@testset "short final" begin
dc_isda = DayCounts.ActualActualISDA()
dc_icma = DayCounts.ActualActualICMA(Date(1999,7,30):Month(6):Date(2000,7,30))
@test yearfrac(Date(1999,7,30), Date(2000,1,30), dc_isda) == 155/365 + 29/366
@test yearfrac(Date(1999,7,30), Date(2000,1,30), dc_icma) == 184/(184*2)
@test yearfrac(Date(2000,1,30), Date(2000,6,30), dc_isda) == 152/366
@test yearfrac(Date(2000,1,30), Date(2000,6,30), dc_icma) == 152/(182*2)
@test yearfrac(Date(1999,7,30), Date(2000,6,30), dc_isda) == 155/365 + (29+152)/366
@test yearfrac(Date(1999,7,30), Date(2000,6,30), dc_icma) == 184/(184*2) + 152/(182*2)
end
@testset "long final" begin
dc_isda = DayCounts.ActualActualISDA()
# TODO: need a way to express "last day of month" schedules.
dc_icma = DayCounts.ActualActualICMA(Date(1999,5,31):Month(3):Date(2000,5,31))
@test yearfrac(Date(1999,11,30), Date(2000,4,30), dc_isda) == 32/365 + 120/366
@test yearfrac(Date(1999,11,30), Date(2000,4,30), dc_icma) == 91/(91*4) + 61/(92*4)
end
end
@testset "ThirtyU360" begin
dc = DayCounts.ThirtyU360()
# usual rule: ((d2-d1) + (m2-m1)*30 + (y2-y1)*360)/360
@test yearfrac(Date(2011,12,28), Date(2012, 2,28), dc) == ((28-28) + (2-12)*30 + (2012-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2012, 2,29), dc) == ((29-28) + (2-12)*30 + (2012-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2012, 3, 1), dc) == ((1-28) + (3-12)*30 + (2012-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2016, 2,28), dc) == ((28-28) + (2-12)*30 + (2016-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2016, 2,29), dc) == ((29-28) + (2-12)*30 + (2016-2011)*360)/360
@test yearfrac(Date(2011,12,28), Date(2016, 3, 1), dc) == ((1-28) + (3-12)*30 + (2016-2011)*360)/360
@test yearfrac(Date(2012, 2,28), Date(2012, 3,28), dc) == ((28-28) + (3-2)*30 + (2012-2012)*360)/360
@test yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc) == ((28-30) + (3-2)*30 + (2012-2012)*360)/360 # exception
@test yearfrac(Date(2012, 3, 1), Date(2012, 3,28), dc) == ((28-1) + (3-3)*30 + (2012-2012)*360)/360
@test yearfrac(Date(2012, 5,29), Date(2013, 8,29), dc) == ((29-29) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,29), Date(2013, 8,30), dc) == ((30-29) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,29), Date(2013, 8,31), dc) == ((31-29) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,30), Date(2013, 8,29), dc) == ((29-30) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,30), Date(2013, 8,30), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360
@test yearfrac(Date(2012, 5,30), Date(2013, 8,31), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,31), Date(2013, 8,29), dc) == ((29-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,31), Date(2013, 8,30), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
@test yearfrac(Date(2012, 5,31), Date(2013, 8,31), dc) == ((30-30) + (8-5)*30 + (2013-2012)*360)/360 # exception
# zeros
@test yearfrac(Date(2011,12,28), Date(2011,12,28), dc) == 0
@test yearfrac(Date(2011,12,31), Date(2011,12,31), dc) == 0
@test yearfrac(Date(2012, 2,28), Date(2012, 2,28), dc) == 0
@test yearfrac(Date(2012, 2,29), Date(2012, 2,29), dc) == 0
# reflection
@test yearfrac(Date(2012, 2,28), Date(2011,12,28), dc) == -yearfrac(Date(2011,12,28), Date(2012, 2,28), dc)
@test yearfrac(Date(2012, 3,28), Date(2012, 2,29), dc) == -yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc)
end
@testset "Excel.ActualActual" begin
dc = DayCounts.Excel.ActualActual()
# calculated from Excel sheet
@test yearfrac(Date(2011,12,28), Date(2012, 2,28), dc) == 62/365
@test yearfrac(Date(2011,12,28), Date(2012, 2,29), dc) == 63/366
@test yearfrac(Date(2011,12,28), Date(2012, 3, 1), dc) == 64/366
@test yearfrac(Date(2011,12,28), Date(2016, 2,28), dc) == 1523/365.3333333333333
@test yearfrac(Date(2011,12,28), Date(2016, 2,29), dc) == 1524/365.3333333333333
@test yearfrac(Date(2011,12,28), Date(2016, 3, 1), dc) == 1525/365.3333333333333
@test yearfrac(Date(2012, 2,28), Date(2012, 3,28), dc) == 29/366
@test yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc) == 28/366
@test yearfrac(Date(2012, 3, 1), Date(2012, 3,28), dc) == 27/366
@test yearfrac(Date(2012, 2,28), Date(2013, 2,28), dc) == 366/366
@test yearfrac(Date(2012, 2,29), Date(2013, 2,28), dc) == 365/366
@test yearfrac(Date(2012, 3, 1), Date(2013, 2,28), dc) == 364/365
@test yearfrac(Date(2012, 2,28), Date(2013, 3, 1), dc) == 367/365.5
@test yearfrac(Date(2012, 2,29), Date(2013, 3, 1), dc) == 366/365.5
@test yearfrac(Date(2012, 3, 1), Date(2013, 3, 1), dc) == 365/365
@test yearfrac(Date(2011, 2,28), Date(2012, 2,28), dc) == 365/365
@test yearfrac(Date(2011, 3, 1), Date(2012, 2,28), dc) == 364/365
@test yearfrac(Date(2011, 2,28), Date(2012, 2,29), dc) == 366/365.5
@test yearfrac(Date(2011, 3, 1), Date(2012, 2,29), dc) == 365/366
@test yearfrac(Date(2011, 2,28), Date(2012, 3, 1), dc) == 367/365.5
@test yearfrac(Date(2011, 3, 1), Date(2012, 3, 1), dc) == 366/366
# zeros
@test yearfrac(Date(2011,12,28), Date(2011,12,28), dc) == 0
@test yearfrac(Date(2011,12,31), Date(2011,12,31), dc) == 0
@test yearfrac(Date(2012, 2,28), Date(2012, 2,28), dc) == 0
@test yearfrac(Date(2012, 2,29), Date(2012, 2,29), dc) == 0
# reflection
@test yearfrac(Date(2012, 2,28), Date(2011,12,28), dc) == -yearfrac(Date(2011,12,28), Date(2012, 2,28), dc)
@test yearfrac(Date(2012, 3,28), Date(2012, 2,29), dc) == -yearfrac(Date(2012, 2,29), Date(2012, 3,28), dc)
end
include("excel.jl")