20#include <boost/test/unit_test.hpp>
21#include <ql/time/calendars/target.hpp>
23#include <ql/time/schedule.hpp>
27using namespace boost::unit_test_framework;
33 const std::vector<Date>& expected) {
34 BOOST_CHECK(s.size() == expected.size());
35 for (Size i=0; i<expected.size(); ++i) {
36 if (s[i] != expected[i]) {
37 BOOST_ERROR(
"expected " << expected[i]
38 <<
" at index " << i <<
", "
46 for (Size i=1; i<s.size() - 1; ++i) {
47 if (s[i].weekday() != w) {
48 BOOST_ERROR(
"expected " << w
49 <<
" at index " << i <<
", "
50 "found " << s[i].weekday());
58BOOST_AUTO_TEST_SUITE(DateGenerationTest)
62 BOOST_TEST_MESSAGE(
"Testing ThirdThursday DateGeneration rule");
64 std::vector<Date> expectedDates;
66 expectedDates.push_back(Date(12, December, 2016));
67 expectedDates.push_back(Date(16, March, 2017));
68 expectedDates.push_back(Date(15, June, 2017));
69 expectedDates.push_back(Date(21, September, 2017));
70 expectedDates.push_back(Date(21, December, 2017));
71 expectedDates.push_back(Date(15, March, 2018));
72 expectedDates.push_back(Date(21, June, 2018));
73 expectedDates.push_back(Date(20, September, 2018));
74 expectedDates.push_back(Date(12, December, 2018));
77 MakeSchedule().from(Date(12, December, 2016))
78 .to(Date(12, December, 2016) + Period(2, Years))
79 .withCalendar(TARGET())
81 .withConvention(ModifiedFollowing)
82 .withTerminationDateConvention(Unadjusted)
83 .withRule(DateGeneration::ThirdThursday);
91 BOOST_TEST_MESSAGE(
"Testing ThirdFriday DateGeneration rule");
93 std::vector<Date> expectedDates;
95 expectedDates.push_back(Date(12, December, 2016));
96 expectedDates.push_back(Date(17, March, 2017));
97 expectedDates.push_back(Date(16, June, 2017));
98 expectedDates.push_back(Date(15, September, 2017));
99 expectedDates.push_back(Date(15, December, 2017));
100 expectedDates.push_back(Date(16, March, 2018));
101 expectedDates.push_back(Date(15, June, 2018));
102 expectedDates.push_back(Date(21, September, 2018));
103 expectedDates.push_back(Date(12, December, 2018));
106 MakeSchedule().from(Date(12, December, 2016))
107 .to(Date(12, December, 2016) + Period(2, Years))
108 .withCalendar(TARGET())
110 .withConvention(ModifiedFollowing)
111 .withTerminationDateConvention(Unadjusted)
112 .withRule(DateGeneration::ThirdFriday);
120 BOOST_TEST_MESSAGE(
"Testing MondayAfterThirdFriday DateGeneration rule");
122 std::vector<Date> expectedDates;
124 expectedDates.push_back(Date(12, December, 2016));
125 expectedDates.push_back(Date(20, March, 2017));
126 expectedDates.push_back(Date(19, June, 2017));
127 expectedDates.push_back(Date(18, September, 2017));
128 expectedDates.push_back(Date(18, December, 2017));
129 expectedDates.push_back(Date(19, March, 2018));
130 expectedDates.push_back(Date(18, June, 2018));
131 expectedDates.push_back(Date(24, September, 2018));
132 expectedDates.push_back(Date(12, December, 2018));
135 MakeSchedule().from(Date(12, December, 2016))
136 .to(Date(12, December, 2016) + Period(2, Years))
137 .withCalendar(TARGET())
139 .withConvention(ModifiedFollowing)
140 .withTerminationDateConvention(Unadjusted)
141 .withRule(DateGeneration::MondayAfterThirdFriday);
149 BOOST_TEST_MESSAGE(
"Testing TuesdayAfterThirdFriday DateGeneration rule");
151 std::vector<Date> expectedDates;
153 expectedDates.push_back(Date(12, December, 2016));
154 expectedDates.push_back(Date(21, March, 2017));
155 expectedDates.push_back(Date(20, June, 2017));
156 expectedDates.push_back(Date(19, September, 2017));
157 expectedDates.push_back(Date(19, December, 2017));
158 expectedDates.push_back(Date(20, March, 2018));
159 expectedDates.push_back(Date(19, June, 2018));
160 expectedDates.push_back(Date(25, September, 2018));
161 expectedDates.push_back(Date(12, December, 2018));
164 MakeSchedule().from(Date(12, December, 2016))
165 .to(Date(12, December, 2016) + Period(2, Years))
166 .withCalendar(TARGET())
168 .withConvention(ModifiedFollowing)
169 .withTerminationDateConvention(Unadjusted)
170 .withRule(DateGeneration::TuesdayAfterThirdFriday);
176BOOST_AUTO_TEST_SUITE_END()
178BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(testThirdThursday)
void checkDates(const Schedule &s, const std::vector< Date > &expected)
void checkDay(const Schedule &s, Weekday w)
Fixture that can be used at top level.