Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
calendars.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 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>
23#include <ql/settings.hpp>
24
25using namespace std;
26using namespace boost::unit_test_framework;
27using namespace QuantLib;
28using namespace QuantExt;
29
30BOOST_FIXTURE_TEST_SUITE(QuantExtTestSuite, qle::test::TopLevelFixture)
31
32BOOST_AUTO_TEST_SUITE(CalendarTests)
33
34BOOST_AUTO_TEST_CASE(testRussiaModified) {
35
36 BOOST_TEST_MESSAGE("Testing RussiaModified calendar");
37
38 Calendar russiaSettlement = Russia(Russia::Settlement);
39 Calendar russiaExchange = Russia(Russia::MOEX);
40 Calendar russiaModifiedSettlement = RussiaModified(Russia::Settlement);
41 Calendar russiaModifiedExchange = RussiaModified(Russia::MOEX);
42
43 // check that the new modified Russia exchange calendar does not throw before 2012
44 Date pre(31, December, 2011);
45 BOOST_CHECK_THROW(russiaExchange.isBusinessDay(pre), QuantLib::Error);
46 BOOST_CHECK_NO_THROW(russiaModifiedExchange.isBusinessDay(pre));
47
48 // before 2012: The new modifed Russia exchange calendar uses QuantLib's Russia settlement
49 Date start2011(1, Jan, 2011);
50 Date end2011(31, Dec, 2011);
51 for(Date d = start2011; d <= end2011; d++) {
52 BOOST_CHECK_EQUAL(russiaSettlement.isBusinessDay(d), russiaModifiedSettlement.isBusinessDay(d));
53 BOOST_CHECK_EQUAL(russiaSettlement.isBusinessDay(d), russiaModifiedExchange.isBusinessDay(d));
54 }
55
56 // 2012 onwards: The new modifed Russia exchange calendar matches uses QuantLib's Russia exchange
57 Date start2012(1, Jan, 2012);
58 Date end2012(31, Dec, 2012);
59 for(Date d = start2012; d <= end2012; d++) {
60 BOOST_CHECK_EQUAL(russiaSettlement.isBusinessDay(d), russiaModifiedSettlement.isBusinessDay(d));
61 BOOST_CHECK_EQUAL(russiaExchange.isBusinessDay(d), russiaModifiedExchange.isBusinessDay(d));
62 }
63}
64
65BOOST_AUTO_TEST_CASE(updatedArabEmirates){
66 BOOST_TEST_MESSAGE("Testing updated UAE calendar");
67 Calendar UAE = UnitedArabEmirates();
68 std::vector<QuantLib::Date> testDates{
69 Date(4,Feb,2021),
70 Date(5,Feb,2021),
71 Date(6,Feb,2021),
72 Date(7,Feb,2021),
73 Date(8,Feb,2021),
74 Date(9,Feb,2021),
75 Date(10,Feb,2021),
76 Date(30,Dec,2021),
77 Date(31,Dec,2021),
78 Date(1,Jan,2022), // this is always holiday, but being Sat it serves the goal of the test
79 Date(2,Jan,2022),
80 Date(3,Jan,2022),
81 Date(4,Jan,2022),
82 Date(5,Jan,2022),
83 Date(4,Feb,2022),
84 Date(5,Feb,2022),
85 Date(6,Feb,2022),
86 Date(7,Feb,2022),
87 Date(8,Feb,2022),
88 Date(9,Feb,2022),
89 Date(10,Feb,2022),
90 };
91
92 for (auto d:testDates){
93 if(d.year()<2022)
94 switch (d.weekday()) {
95 case QuantLib::Friday:
96 case QuantLib::Saturday:
97 BOOST_TEST(!UAE.isBusinessDay(d));
98 break ;
99 default:
100 BOOST_TEST(UAE.isBusinessDay(d));
101 break ;
102 }
103 else{
104 switch (d.weekday()) {
105 case QuantLib::Saturday:
106 case QuantLib::Sunday:
107 BOOST_TEST(!UAE.isBusinessDay(d));
108 break ;
109 default:
110 BOOST_TEST(UAE.isBusinessDay(d));
111 break ;
112 }
113 }
114 }
115
116}
117
118BOOST_AUTO_TEST_SUITE_END()
119
120BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(testRussiaModified)
Definition: calendars.cpp:34
Russian calendars.
Definition: russia.hpp:37
Islamic Weekends-only calendar.
Russian calendar, modified QuantLib Russia to extend MOEX before 2012.
Fixture that can be used at top level.