Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
qle_calendars.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19#include "toplevelfixture.hpp"
20#include <boost/test/unit_test.hpp>
21#include <ql/time/calendar.hpp>
22#include <ql/time/calendars/austria.hpp>
23#include <ql/time/calendars/thailand.hpp>
24#include <ql/time/calendars/chile.hpp>
38
39using namespace QuantLib;
40using namespace QuantExt;
41using namespace boost::unit_test_framework;
42using namespace std;
43
44namespace check {
45
46void checkCalendars(const std::vector<Date>& expectedHolidays, const std::vector<Date>& testHolidays) {
47
48 for (Size i = 0; i < expectedHolidays.size(); i++) {
49 if (testHolidays[i] != expectedHolidays[i])
50 BOOST_FAIL("expected holiday was " << expectedHolidays[i] << " while calculated holiday is "
51 << testHolidays[i]);
52 }
53}
54} // namespace check
55
56BOOST_FIXTURE_TEST_SUITE(QuantExtTestSuite, qle::test::TopLevelFixture)
57
58BOOST_AUTO_TEST_SUITE(CalendarsTest)
59
60BOOST_AUTO_TEST_CASE(testPeruvianCalendar) {
61
62 BOOST_TEST_MESSAGE("Testing Peruvian holiday list");
63
64 std::vector<Date> expectedHolidays;
65
66 expectedHolidays.push_back(Date(1, January, 2018));
67 expectedHolidays.push_back(Date(29, March, 2018));
68 expectedHolidays.push_back(Date(30, March, 2018));
69 expectedHolidays.push_back(Date(1, May, 2018));
70 expectedHolidays.push_back(Date(29, June, 2018));
71 expectedHolidays.push_back(Date(27, July, 2018));
72 expectedHolidays.push_back(Date(30, August, 2018));
73 expectedHolidays.push_back(Date(31, August, 2018));
74 expectedHolidays.push_back(Date(8, October, 2018));
75 expectedHolidays.push_back(Date(1, November, 2018));
76 expectedHolidays.push_back(Date(2, November, 2018));
77 expectedHolidays.push_back(Date(25, December, 2018));
78
79 Calendar c = Peru();
80
81 std::vector<Date> hol = c.holidayList(Date(1, January, 2018), Date(31, December, 2018));
82
83 BOOST_CHECK(hol.size() == expectedHolidays.size());
84
85 check::checkCalendars(expectedHolidays, hol);
86}
87
88BOOST_AUTO_TEST_CASE(testColombianCalendar) {
89
90 BOOST_TEST_MESSAGE("Testing Colombian holiday list");
91
92 std::vector<Date> expectedHolidays;
93
94 expectedHolidays.push_back(Date(1, January, 2018));
95 expectedHolidays.push_back(Date(8, January, 2018));
96 expectedHolidays.push_back(Date(19, March, 2018));
97 expectedHolidays.push_back(Date(29, March, 2018));
98 expectedHolidays.push_back(Date(30, March, 2018));
99 expectedHolidays.push_back(Date(1, May, 2018));
100 expectedHolidays.push_back(Date(14, May, 2018));
101 expectedHolidays.push_back(Date(4, June, 2018));
102 expectedHolidays.push_back(Date(11, June, 2018));
103 expectedHolidays.push_back(Date(2, July, 2018));
104 expectedHolidays.push_back(Date(20, July, 2018));
105 expectedHolidays.push_back(Date(7, August, 2018));
106 expectedHolidays.push_back(Date(20, August, 2018));
107 expectedHolidays.push_back(Date(15, October, 2018));
108 expectedHolidays.push_back(Date(5, November, 2018));
109 expectedHolidays.push_back(Date(12, November, 2018));
110 expectedHolidays.push_back(Date(25, December, 2018));
111
112 Calendar c = Colombia();
113
114 std::vector<Date> hol = c.holidayList(Date(1, January, 2018), Date(31, December, 2018));
115
116 BOOST_CHECK(hol.size() == expectedHolidays.size());
117
118 check::checkCalendars(expectedHolidays, hol);
119}
120
121BOOST_AUTO_TEST_CASE(testPhilippineCalendar) {
122
123 BOOST_TEST_MESSAGE("Testing Philippine holiday list");
124
125 std::vector<Date> expectedHolidays;
126
127 expectedHolidays.push_back(Date(1, January, 2018));
128 expectedHolidays.push_back(Date(2, January, 2018));
129 expectedHolidays.push_back(Date(29, March, 2018));
130 expectedHolidays.push_back(Date(30, March, 2018));
131 expectedHolidays.push_back(Date(9, April, 2018));
132 expectedHolidays.push_back(Date(1, May, 2018));
133 expectedHolidays.push_back(Date(12, June, 2018));
134 expectedHolidays.push_back(Date(21, August, 2018));
135 expectedHolidays.push_back(Date(27, August, 2018));
136 expectedHolidays.push_back(Date(1, November, 2018));
137 expectedHolidays.push_back(Date(30, November, 2018));
138 expectedHolidays.push_back(Date(25, December, 2018));
139 expectedHolidays.push_back(Date(31, December, 2018));
140
141 Calendar c = Philippines();
142
143 std::vector<Date> hol = c.holidayList(Date(1, January, 2018), Date(31, December, 2018));
144
145 check::checkCalendars(expectedHolidays, hol);
146}
147
148BOOST_AUTO_TEST_CASE(testThaiCalendar) {
149
150 BOOST_TEST_MESSAGE("Testing Thai holiday list");
151
152 std::vector<Date> expectedHolidays;
153
154 expectedHolidays.push_back(Date(1, January, 2018));
155 expectedHolidays.push_back(Date(2, January, 2018));
156 expectedHolidays.push_back(Date(1, March, 2018)); // Makha Bucha Day
157 expectedHolidays.push_back(Date(6, April, 2018));
158 expectedHolidays.push_back(Date(13, April, 2018));
159 expectedHolidays.push_back(Date(16, April, 2018));
160 expectedHolidays.push_back(Date(1, May, 2018));
161 expectedHolidays.push_back(Date(29, May, 2018)); // Wisakha Bucha Day
162 expectedHolidays.push_back(Date(27, July, 2018)); // Asarnha Bucha Day
163 expectedHolidays.push_back(Date(30, July, 2018));
164 expectedHolidays.push_back(Date(13, August, 2018));
165 expectedHolidays.push_back(Date(15, October, 2018));
166 expectedHolidays.push_back(Date(23, October, 2018));
167 expectedHolidays.push_back(Date(5, December, 2018));
168 expectedHolidays.push_back(Date(10, December, 2018));
169 expectedHolidays.push_back(Date(31, December, 2018));
170
171 Calendar c = Thailand();
172
173 std::vector<Date> hol = c.holidayList(Date(1, January, 2018), Date(31, December, 2018));
174
175 BOOST_CHECK(hol.size() == expectedHolidays.size());
176
177 check::checkCalendars(expectedHolidays, hol);
178}
179
180BOOST_AUTO_TEST_CASE(testMalaysianCalendar) {
181
182 BOOST_TEST_MESSAGE("Testing Malaysian holiday list");
183
184 std::vector<Date> expectedHolidays;
185
186 expectedHolidays.push_back(Date(1, January, 2018));
187 expectedHolidays.push_back(Date(1, February, 2018));
188 expectedHolidays.push_back(Date(1, May, 2018));
189 expectedHolidays.push_back(Date(31, August, 2018));
190 expectedHolidays.push_back(Date(17, September, 2018));
191 expectedHolidays.push_back(Date(25, December, 2018));
192
193 Calendar c = Malaysia();
194
195 std::vector<Date> hol = c.holidayList(Date(1, January, 2018), Date(31, December, 2018));
196
197 BOOST_CHECK(hol.size() == expectedHolidays.size());
198
199 check::checkCalendars(expectedHolidays, hol);
200}
201
202BOOST_AUTO_TEST_CASE(testChileanCalendar) {
203
204 BOOST_TEST_MESSAGE("Testing Chilean holiday list");
205
206 std::vector<Date> expectedHolidays;
207
208 expectedHolidays.push_back(Date(1, January, 2018));
209 expectedHolidays.push_back(Date(30, March, 2018));
210 expectedHolidays.push_back(Date(1, May, 2018));
211 expectedHolidays.push_back(Date(21, May, 2018));
212 expectedHolidays.push_back(Date(2, July, 2018));
213 expectedHolidays.push_back(Date(16, July, 2018));
214 expectedHolidays.push_back(Date(15, August, 2018));
215 expectedHolidays.push_back(Date(17, September, 2018));
216 expectedHolidays.push_back(Date(18, September, 2018));
217 expectedHolidays.push_back(Date(19, September, 2018));
218 expectedHolidays.push_back(Date(15, October, 2018));
219 expectedHolidays.push_back(Date(1, November, 2018));
220 expectedHolidays.push_back(Date(2, November, 2018));
221 expectedHolidays.push_back(Date(25, December, 2018));
222
223 Calendar c = Chile();
224
225 std::vector<Date> hol = c.holidayList(Date(1, January, 2018), Date(31, December, 2018));
226
227 BOOST_CHECK(hol.size() == expectedHolidays.size());
228
229 check::checkCalendars(expectedHolidays, hol);
230}
231
232BOOST_AUTO_TEST_CASE(testNetherlandianCalendar) {
233
234 BOOST_TEST_MESSAGE("Testing Netherlandian holiday list");
235
236 std::vector<Date> expectedHolidays;
237
238 expectedHolidays.push_back(Date(1, January, 2018));
239 expectedHolidays.push_back(Date(30, March, 2018));
240 expectedHolidays.push_back(Date(2, April, 2018));
241 expectedHolidays.push_back(Date(27, April, 2018));
242 expectedHolidays.push_back(Date(10, May, 2018));
243 expectedHolidays.push_back(Date(21, May, 2018));
244 expectedHolidays.push_back(Date(25, December, 2018));
245 expectedHolidays.push_back(Date(26, December, 2018));
246
247 Calendar c = Netherlands();
248
249 std::vector<Date> hol = c.holidayList(Date(1, January, 2018), Date(31, December, 2018));
250
251 BOOST_CHECK(hol.size() == expectedHolidays.size());
252
253 check::checkCalendars(expectedHolidays, hol);
254}
255
256BOOST_AUTO_TEST_CASE(testFrenchCalendar) {
257
258 BOOST_TEST_MESSAGE("Testing French holiday list");
259
260 std::vector<Date> expectedHolidays;
261
262 expectedHolidays.push_back(Date(1, January, 2018));
263 expectedHolidays.push_back(Date(30, March, 2018));
264 expectedHolidays.push_back(Date(2, April, 2018));
265 expectedHolidays.push_back(Date(1, May, 2018));
266 expectedHolidays.push_back(Date(8, May, 2018));
267 expectedHolidays.push_back(Date(10, May, 2018));
268 expectedHolidays.push_back(Date(21, May, 2018));
269 expectedHolidays.push_back(Date(15, August, 2018));
270 expectedHolidays.push_back(Date(1, November, 2018));
271 expectedHolidays.push_back(Date(25, December, 2018));
272 expectedHolidays.push_back(Date(26, December, 2018));
273
274 Calendar c = France();
275
276 std::vector<Date> hol = c.holidayList(Date(1, January, 2018), Date(31, December, 2018));
277
278 BOOST_CHECK(hol.size() == expectedHolidays.size());
279
280 check::checkCalendars(expectedHolidays, hol);
281}
282
283BOOST_AUTO_TEST_CASE(testIsraelTelbor) {
284
285 BOOST_TEST_MESSAGE("Testing Israel Telbor standard weekends");
286
288
289 BOOST_CHECK(!c.isWeekend(Friday));
290 BOOST_CHECK(c.isWeekend(Saturday));
291 BOOST_CHECK(c.isWeekend(Sunday));
292}
293
294BOOST_AUTO_TEST_CASE(testIsraelTelAviv) {
295
296 BOOST_TEST_MESSAGE("Testing Israel TelAviv weekends");
297
299
300 BOOST_CHECK(c.isWeekend(Friday));
301 BOOST_CHECK(c.isWeekend(Saturday));
302 BOOST_CHECK(!c.isWeekend(Sunday));
303}
304
305BOOST_AUTO_TEST_CASE(testAustrianCalendar) {
306
307 BOOST_TEST_MESSAGE("Testing Austrian holiday list");
308
309 std::vector<Date> expectedHolidays;
310
311 expectedHolidays.push_back(Date(1, January, 2020));
312 expectedHolidays.push_back(Date(6, January, 2020));
313 expectedHolidays.push_back(Date(13, April, 2020));
314 expectedHolidays.push_back(Date(1, May, 2020));
315 expectedHolidays.push_back(Date(21, May, 2020));
316 expectedHolidays.push_back(Date(1, June, 2020));
317 expectedHolidays.push_back(Date(11, June, 2020));
318 // expectedHolidays.push_back(Date(15, August, 2020)); //Saturday
319 expectedHolidays.push_back(Date(26, October, 2020));
320 // expectedHolidays.push_back(Date(1, November, 2020)); //Sunday
321 expectedHolidays.push_back(Date(8, December, 2020));
322 expectedHolidays.push_back(Date(25, December, 2020));
323 // expectedHolidays.push_back(Date(26, December, 2020)); //Saturday
324
325 Calendar c = Austria();
326
327 std::vector<Date> hol = c.holidayList(Date(1, January, 2020), Date(31, December, 2020));
328
329 BOOST_CHECK(hol.size() == expectedHolidays.size());
330
331 check::checkCalendars(expectedHolidays, hol);
332}
333
334BOOST_AUTO_TEST_CASE(testSpanishCalendar) {
335
336 BOOST_TEST_MESSAGE("Testing Spanish holiday list");
337
338 std::vector<Date> expectedHolidays;
339
340 expectedHolidays.push_back(Date(1, January, 2020));
341 expectedHolidays.push_back(Date(6, January, 2020));
342 expectedHolidays.push_back(Date(10, April, 2020));
343 expectedHolidays.push_back(Date(1, May, 2020));
344 // expectedHolidays.push_back(Date(15, August, 2020)); //Saturday
345 expectedHolidays.push_back(Date(12, October, 2020));
346 // expectedHolidays.push_back(Date(1, November, 2020)); //Sunday
347 // expectedHolidays.push_back(Date(6, December, 2020)); //Sunday
348 expectedHolidays.push_back(Date(8, December, 2020));
349 expectedHolidays.push_back(Date(25, December, 2020));
350
351 Calendar c = Spain();
352
353 std::vector<Date> hol = c.holidayList(Date(1, January, 2020), Date(31, December, 2020));
354
355 BOOST_CHECK(hol.size() == expectedHolidays.size());
356
357 check::checkCalendars(expectedHolidays, hol);
358}
359
360BOOST_AUTO_TEST_CASE(testLuxembourgianCalendar) {
361
362 BOOST_TEST_MESSAGE("Testing Luxembourgian holiday list");
363
364 std::vector<Date> expectedHolidays;
365
366 expectedHolidays.push_back(Date(1, January, 2020));
367 expectedHolidays.push_back(Date(13, April, 2020));
368 expectedHolidays.push_back(Date(1, May, 2020));
369 // expectedHolidays.push_back(Date(9, May, 2020)); //Saturday
370 expectedHolidays.push_back(Date(21, May, 2020));
371 expectedHolidays.push_back(Date(1, June, 2020));
372 expectedHolidays.push_back(Date(23, June, 2020));
373 // expectedHolidays.push_back(Date(15, August, 2020)); //Saturday
374 // expectedHolidays.push_back(Date(1, November, 2020)); //Sunday
375 expectedHolidays.push_back(Date(25, December, 2020));
376 // expectedHolidays.push_back(Date(26, December, 2020)); //Saturday
377
378 Calendar c = Luxembourg();
379
380 std::vector<Date> hol = c.holidayList(Date(1, January, 2020), Date(31, December, 2020));
381
382 BOOST_CHECK(hol.size() == expectedHolidays.size());
383
384 check::checkCalendars(expectedHolidays, hol);
385}
386
387BOOST_AUTO_TEST_CASE(testBelgianCalendar) {
388
389 BOOST_TEST_MESSAGE("Testing Belgian holiday list");
390
391 std::vector<Date> expectedHolidays;
392
393 expectedHolidays.push_back(Date(1, January, 2020));
394 // expectedHolidays.push_back(Date(12, April, 2020)); //Sunday
395 expectedHolidays.push_back(Date(13, April, 2020));
396 expectedHolidays.push_back(Date(1, May, 2020));
397 expectedHolidays.push_back(Date(21, May, 2020));
398 // expectedHolidays.push_back(Date(31, May, 2020)); //Sunday
399 expectedHolidays.push_back(Date(1, June, 2020));
400 expectedHolidays.push_back(Date(21, July, 2020));
401 // expectedHolidays.push_back(Date(15, August, 2020)); //Saturday
402 // expectedHolidays.push_back(Date(1, November, 2020)); //Sunday
403 expectedHolidays.push_back(Date(11, November, 2020));
404 expectedHolidays.push_back(Date(25, December, 2020));
405
406 Calendar c = Belgium();
407
408 std::vector<Date> hol = c.holidayList(Date(1, January, 2020), Date(31, December, 2020));
409
410 BOOST_CHECK(hol.size() == expectedHolidays.size());
411
412 check::checkCalendars(expectedHolidays, hol);
413}
414
415BOOST_AUTO_TEST_CASE(testCyprusCalendar) {
416
417 BOOST_TEST_MESSAGE("Testing Cyprus holiday list");
418
419 std::vector<Date> expectedHolidays;
420
421 //expectedHolidays.push_back(Date(1, January, 2022)); //weekend
422 expectedHolidays.push_back(Date(6, January, 2022));
423 expectedHolidays.push_back(Date(7, March, 2022));
424 expectedHolidays.push_back(Date(25, March, 2022));
425 expectedHolidays.push_back(Date(1, April, 2022));
426 expectedHolidays.push_back(Date(22, April, 2022));
427 expectedHolidays.push_back(Date(25, April, 2022));
428 expectedHolidays.push_back(Date(26, April, 2022));
429 //expectedHolidays.push_back(Date(1, May, 2022)); //weekend
430 expectedHolidays.push_back(Date(13, June, 2022));
431 expectedHolidays.push_back(Date(15, August, 2022));
432 //expectedHolidays.push_back(Date(1, October, 2022)); weekend
433 expectedHolidays.push_back(Date(28, October, 2022));
434 //expectedHolidays.push_back(Date(25, December, 2022));weekend
435 expectedHolidays.push_back(Date(26, December, 2022));
436
437 Calendar c = Cyprus();
438
439 std::vector<Date> hol = c.holidayList(Date(1, January, 2022), Date(31, December, 2022));
440
441 BOOST_CHECK(hol.size() == expectedHolidays.size());
442
443 check::checkCalendars(expectedHolidays, hol);
444}
445
446BOOST_AUTO_TEST_CASE(testGreeceCalendar) {
447
448 BOOST_TEST_MESSAGE("Testing Greece holiday list");
449
450 std::vector<Date> expectedHolidays;
451
452 expectedHolidays.push_back(Date(1, January, 2021));
453 expectedHolidays.push_back(Date(6, January, 2021));
454 expectedHolidays.push_back(Date(15, March, 2021));
455 expectedHolidays.push_back(Date(25, March, 2021));
456 expectedHolidays.push_back(Date(30, April, 2021));
457 expectedHolidays.push_back(Date(3, May, 2021));
458 expectedHolidays.push_back(Date(4, May, 2021));
459 expectedHolidays.push_back(Date(21, June, 2021));
460 expectedHolidays.push_back(Date(28, October, 2021));
461
462 expectedHolidays.push_back(Date(6, January, 2022));
463 expectedHolidays.push_back(Date(7, March, 2022));
464 expectedHolidays.push_back(Date(25, March, 2022));
465 expectedHolidays.push_back(Date(22, April, 2022));
466 expectedHolidays.push_back(Date(25, April, 2022));
467 expectedHolidays.push_back(Date(13, June, 2022));
468 expectedHolidays.push_back(Date(15, August, 2022));
469 expectedHolidays.push_back(Date(28, October, 2022));
470 expectedHolidays.push_back(Date(26, December, 2022));
471
472
473
474 Calendar c = Greece();
475
476 std::vector<Date> hol = c.holidayList(Date(1, January, 2021), Date(31, December, 2022));
477
478 BOOST_CHECK(hol.size() == expectedHolidays.size());
479
480 check::checkCalendars(expectedHolidays, hol);
481}
482
483BOOST_AUTO_TEST_CASE(testIrishStockExchangeCalendar) {
484
485 BOOST_TEST_MESSAGE("Testing Irish Stock Exchange holiday list");
486
487 std::vector<Date> expectedHolidays;
488
489 expectedHolidays.push_back(Date(1, January, 2021));
490 expectedHolidays.push_back(Date(17, March, 2021));
491 expectedHolidays.push_back(Date(2, April, 2021));
492 expectedHolidays.push_back(Date(5, April, 2021));
493 expectedHolidays.push_back(Date(3, May, 2021));
494 expectedHolidays.push_back(Date(7, June, 2021));
495 expectedHolidays.push_back(Date(2, August, 2021));
496 expectedHolidays.push_back(Date(25, October, 2021));
497 //expectedHolidays.push_back(Date(25, December, 2021)); Falls on weekend
498 //expectedHolidays.push_back(Date(26, December, 2021)); Falls on weekend
499 expectedHolidays.push_back(Date(27, December, 2021));
500 expectedHolidays.push_back(Date(28, December, 2021));
501
502 Calendar c = Ireland();
503
504 std::vector<Date> hol = c.holidayList(Date(1, January, 2021), Date(31, December, 2021));
505
506 BOOST_CHECK(hol.size() == expectedHolidays.size());
507
508 check::checkCalendars(expectedHolidays, hol);
509}
510
511BOOST_AUTO_TEST_CASE(testIrishBankHolidaysCalendar) {
512
513 BOOST_TEST_MESSAGE("Testing Irish bank holiday list");
514
515 std::vector<Date> expectedHolidays;
516
517 expectedHolidays.push_back(Date(1, January, 2021));
518 expectedHolidays.push_back(Date(17, March, 2021));
519 expectedHolidays.push_back(Date(2, April, 2021));
520 expectedHolidays.push_back(Date(5, April, 2021));
521 expectedHolidays.push_back(Date(3, May, 2021));
522 expectedHolidays.push_back(Date(7, June, 2021));
523 expectedHolidays.push_back(Date(2, August, 2021));
524 expectedHolidays.push_back(Date(25, October, 2021));
525 // expectedHolidays.push_back(Date(25, December, 2021)); Falls on weekend
526 // expectedHolidays.push_back(Date(26, December, 2021)); Falls on weekend
527 expectedHolidays.push_back(Date(27, December, 2021));
528 expectedHolidays.push_back(Date(28, December, 2021));
529 expectedHolidays.push_back(Date(29, December, 2021));
530
531 Calendar c = Ireland(Ireland::BankHolidays);
532
533 std::vector<Date> hol = c.holidayList(Date(1, January, 2021), Date(31, December, 2021));
534
535 BOOST_CHECK(hol.size() == expectedHolidays.size());
536
537 check::checkCalendars(expectedHolidays, hol);
538}
539
540
541BOOST_AUTO_TEST_SUITE_END()
542
543BOOST_AUTO_TEST_SUITE_END()
Belgian calendar.
Cyprus Calendar.
Definition: cyprus.hpp:62
Greece Calendar.
Definition: greece.hpp:57
Ireland Calendars.
Definition: ireland.hpp:54
Israel calendar.
Definition: israel.hpp:40
Colombian calendar.
Cyprus Calendar.
French calendar.
Greece Calendars.
Ireland Calendar.
Israel calendar extension to cover TELBOR publication days.
Luxembourgish calendar.
Malaysian calendar.
void checkCalendars(const std::vector< Date > &expectedHolidays, const std::vector< Date > &testHolidays)
Dutch calendar.
Peru calendar.
Philippine calendar.
BOOST_AUTO_TEST_CASE(testPeruvianCalendar)
Spanish calendar.
Fixture that can be used at top level.