58 {
59
60 BOOST_TEST_MESSAGE("Testing expiry dates for commodity: " << commodityName);
61
62
64 string filename = commodityName + "_conventions.xml";
65 conventions.
fromFile(TEST_INPUT_FILE(filename));
66
67
68 BOOST_TEST_REQUIRE(conventions.
has(commodityName));
69 auto convention = QuantLib::ext::dynamic_pointer_cast<CommodityFutureConvention>(conventions.
get(commodityName));
70 BOOST_TEST_REQUIRE(convention);
72
73
74 filename = commodityName + "_expiries.csv";
76 BOOST_REQUIRE_EQUAL(reader.numberOfColumns(), 3);
77
78 while (reader.next()) {
79
80
81 Date contractDate =
parseDate(reader.get(0));
82 Date expExpiryDate =
parseDate(reader.get(1));
83
84
85 Date expiryDate = cbfe.expiryDate(contractDate, 0);
86
87
88 BOOST_CHECK_EQUAL(expExpiryDate, expiryDate);
89
90
91 string strExpOptionExpiry = reader.get(2);
92 if (!strExpOptionExpiry.empty()) {
93
94
95 Date expOptionExpiry =
parseDate(strExpOptionExpiry);
96
97
98 Date optionExpiry = cbfe.expiryDate(contractDate, 0, true);
99
100 BOOST_CHECK_EQUAL(expOptionExpiry, optionExpiry);
101 }
102 }
103}
Perform date calculations for future contracts based on conventions.
Repository for currency dependent market conventions.
bool has(const std::string &id) const
Checks if we have a convention with the given id.
QuantLib::ext::shared_ptr< Convention > get(const string &id) const
void fromFile(const std::string &filename)
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.