21#include <boost/test/unit_test.hpp>
22#include <boost/test/data/test_case.hpp>
29#include <oret/datapaths.hpp>
30#include <oret/toplevelfixture.hpp>
31#include <ql/time/date.hpp>
35using namespace boost::unit_test_framework;
39using ore::test::TopLevelFixture;
48class F :
public TopLevelFixture {
55 calendarAdjustments.
fromFile(TEST_INPUT_FILE(
"calendaradjustments.xml"));
56 startDate = Date(1, Jan, 2019);
57 endDate = Date(31, Dec, 2020);
65 std::vector<Date> holidays;
68std::vector<TestDatum> loadExpectedHolidays() {
70 string fileName = TEST_INPUT_FILE(
"holidays.csv");
71 std::vector<TestDatum>
data;
74 QL_REQUIRE(file.is_open(),
"error opening file " << fileName);
81 vector<string> elements;
82 boost::split(elements, line, boost::is_any_of(
","), boost::token_compress_on);
83 QL_REQUIRE(elements.size() > 1,
"Not enough elements in the calendar");
85 td.calendarName = elements.front();
86 for (Size i = 1; i < elements.size(); i++) {
88 if (d.weekday() != Saturday && d.weekday() != Sunday) {
89 td.holidays.push_back(
parseDate(elements[i]));
100BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, F)
102BOOST_AUTO_TEST_SUITE(CalendarAdjustmentsTests)
108 for (
auto expectedHolidays : loadExpectedHolidays()) {
109 vector<Date> qcalHols;
110 qcalHols =
parseCalendar(expectedHolidays.calendarName).holidayList(startDate, endDate,
false);
111 BOOST_CHECK_EQUAL_COLLECTIONS(qcalHols.begin(), qcalHols.end(), expectedHolidays.holidays.begin(),
112 expectedHolidays.holidays.end());
117 BOOST_TEST_MESSAGE(
"Testing calendar adjustments...");
127 BOOST_REQUIRE(cac.
getCalendars() == set<string>({
"UK settlement"}));
129 BOOST_REQUIRE(cac.
getHolidays(
"UK") == set<Date>({Date(29, April, 2011)}));
133 BOOST_REQUIRE(cac.
getBusinessDays(
"UK") == set<Date>({Date(25, December, 2011)}));
138 set<string> expcal = {
"Japan",
"UK settlement"};
140 BOOST_CHECK_EQUAL_COLLECTIONS(res.begin(), res.end(), expcal.begin(), expcal.end());
141 BOOST_REQUIRE(cac.
getHolidays(
"JPY") == set<Date>({Date(1, May, 2019)}));
145 BOOST_TEST_MESSAGE(
"Testing that incorrect CalendarAdjustments are not accepted...");
149 BOOST_CHECK_THROW(calendarAdjustments_1.
fromFile(TEST_INPUT_FILE(
"invalid_calendaradjustments_1.xml")), QuantLib::Error);
152BOOST_AUTO_TEST_SUITE_END()
154BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(testCalendarAdjustmentRealCalendars)
Interface for calendar modifications, additional holidays and business days.
const set< Date > & getHolidays(const string &calname) const
Returns all the holidays for a given cal name.
void addBusinessDays(const string &calname, const Date &d)
This method adds d to the list of business days for cal name.
set< string > getCalendars() const
const set< Date > & getBusinessDays(const string &calname) const
Returns all the business days for a given calname.
void addHolidays(const string &calname, const Date &d)
This method adds d to the list of holidays for cal name.
void append(const CalendarAdjustmentConfig &c)
add all holidays and business days from c to this instance
void fromFile(const std::string &filename)
utility class to access CSV files
Market Datum Loader Implementation.
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Map text representations to QuantLib/QuantExt types.
string conversion utilities