Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
schedule.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 <boost/test/unit_test.hpp>
21#include <oret/toplevelfixture.hpp>
22
23using namespace boost::unit_test_framework;
24using namespace ore::data;
25using namespace QuantLib;
26
27BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
28
29BOOST_AUTO_TEST_SUITE(ScheduleDataTests)
30
31BOOST_AUTO_TEST_CASE(testScheduleData) {
32
33 BOOST_TEST_MESSAGE("Testing ScheduleData...");
34
35 ScheduleDates dates1("TARGET", "", "", {"2015-01-09", "2015-02-09", "2015-03-09", "2015-04-09"});
36
37 ScheduleDates dates2("TARGET", "", "",
38 {"2015-04-09",
39 "2016-04-11", // 9th = Saturday
40 "2017-04-10", // 9th = Sunday
41 "2018-04-09"});
42
43 ScheduleRules rules1("2015-01-09", "2015-04-09", "1M", "TARGET", "MF", "MF", "Forward");
44
45 ScheduleRules rules2("2015-04-09", "2018-04-09", "1Y", "TARGET", "MF", "MF", "Forward");
46
47 // Test <Dates> and <Dates>
48 ScheduleData data(dates1);
49 data.addDates(dates2);
50 QuantLib::Schedule s = makeSchedule(data);
51 BOOST_CHECK_EQUAL(s.size(), 7UL); // 7 dates, 6 coupons
52 BOOST_CHECK_EQUAL(s.startDate(), Date(9, Jan, 2015));
53 BOOST_CHECK_EQUAL(s.endDate(), Date(9, Apr, 2018));
54
55 // Test <Rules> and <Rules>
56 data = ScheduleData(rules1);
57 data.addRules(rules2);
58 QuantLib::Schedule s2 = makeSchedule(data);
59 BOOST_CHECK_EQUAL(s2.size(), s.size());
60 for (Size i = 0; i < s.size(); i++)
61 BOOST_CHECK_EQUAL(s[i], s2[i]);
62
63 // Test <Dates> and <Rules>
64 data = ScheduleData(dates1);
65 data.addRules(rules2);
66 QuantLib::Schedule s3 = makeSchedule(data);
67 BOOST_CHECK_EQUAL(s3.size(), s.size());
68 for (Size i = 0; i < s.size(); i++)
69 BOOST_CHECK_EQUAL(s[i], s3[i]);
70}
71
72// The original reason for adding the LastWednesday date generation rule was to generate the AU CPI publication dates
73// using a rules based schedule. Here, we compare the dates for a number of years against the release dates from
74// https://www.abs.gov.au/statistics/economy/price-indexes-and-inflation/consumer-price-index-australia
75BOOST_AUTO_TEST_CASE(testLastWednesdayDateGenerationRule) {
76
77 vector<Date> expected{
78 Date(30, Oct, 2018),
79 Date(30, Jan, 2019), Date(24, Apr, 2019), Date(31, Jul, 2019), Date(30, Oct, 2019), // 2019
80 Date(29, Jan, 2020), Date(29, Apr, 2020), Date(29, Jul, 2020), Date(28, Oct, 2020), // 2020
81 Date(27, Jan, 2021), Date(28, Apr, 2021), Date(28, Jul, 2021), Date(27, Oct, 2021), // 2021
82 Date(25, Jan, 2022)
83 };
84
85 // AU CPI publication dates are the last Wednesday of Jan, Apr, Jul and Oct. If that is not a good AU business
86 // day, it is the preceding good AU business day.
87 Schedule s = makeSchedule(ScheduleData(ScheduleRules("2018-10-30", "2022-01-25", "3M", "AUD",
88 "Preceding", "Unadjusted", "LastWednesday")));
89
90 // Check
91 BOOST_CHECK_EQUAL_COLLECTIONS(s.dates().begin(), s.dates().end(), expected.begin(), expected.end());
92}
93
94BOOST_AUTO_TEST_SUITE_END()
95
96BOOST_AUTO_TEST_SUITE_END()
Serializable schedule data.
Definition: schedule.hpp:202
Serializable object holding schedule Dates data.
Definition: schedule.hpp:110
Serializable object holding schedule Rules data.
Definition: schedule.hpp:37
@ data
Definition: log.hpp:77
Schedule makeSchedule(const ScheduleDates &data)
Definition: schedule.cpp:263
trade schedule data model and serialization
BOOST_AUTO_TEST_CASE(testScheduleData)
Definition: schedule.cpp:31