Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions | Variables
conventionsbasedfutureexpiry.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <oret/datapaths.hpp>
#include <oret/toplevelfixture.hpp>
#include <ored/utilities/conventionsbasedfutureexpiry.hpp>
#include <ored/utilities/csvfilereader.hpp>
#include <ored/utilities/parsers.hpp>

Go to the source code of this file.

Functions

 BOOST_DATA_TEST_CASE (testExpiryDates, bdata::make(commodityNames), commodityName)
 

Variables

vector< string > commodityNames
 

Function Documentation

◆ BOOST_DATA_TEST_CASE()

BOOST_DATA_TEST_CASE ( testExpiryDates  ,
bdata::make(commodityNames ,
commodityName   
)

Definition at line 58 of file conventionsbasedfutureexpiry.cpp.

58 {
59
60 BOOST_TEST_MESSAGE("Testing expiry dates for commodity: " << commodityName);
61
62 // Read in the relevant conventions file
63 Conventions conventions;
64 string filename = commodityName + "_conventions.xml";
65 conventions.fromFile(TEST_INPUT_FILE(filename));
66
67 // Create the conventions based expiry calculator
68 BOOST_TEST_REQUIRE(conventions.has(commodityName));
69 auto convention = QuantLib::ext::dynamic_pointer_cast<CommodityFutureConvention>(conventions.get(commodityName));
70 BOOST_TEST_REQUIRE(convention);
71 ConventionsBasedFutureExpiry cbfe(*convention);
72
73 // Read in the contract months and expected expiry dates
74 filename = commodityName + "_expiries.csv";
75 CSVFileReader reader(TEST_INPUT_FILE(filename), true, ",");
76 BOOST_REQUIRE_EQUAL(reader.numberOfColumns(), 3);
77
78 while (reader.next()) {
79
80 // Get the contract date and the expected expiry date from the file
81 Date contractDate = parseDate(reader.get(0));
82 Date expExpiryDate = parseDate(reader.get(1));
83
84 // Calculate the expiry date using the future expiry calculator
85 Date expiryDate = cbfe.expiryDate(contractDate, 0);
86
87 // Check that the calculated expiry equals the expected expiry date
88 BOOST_CHECK_EQUAL(expExpiryDate, expiryDate);
89
90 // If there is an expected option expiry date, test that also
91 string strExpOptionExpiry = reader.get(2);
92 if (!strExpOptionExpiry.empty()) {
93
94 // Expected option expiry date
95 Date expOptionExpiry = parseDate(strExpOptionExpiry);
96
97 // Calculate the option expiry date using the future expiry calculator
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)
Definition: xmlutils.cpp:150
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
+ Here is the call graph for this function:

Variable Documentation

◆ commodityNames

vector<string> commodityNames
Initial value:
= {
"ice_brent",
"ice_brent_old",
"nymex_cl",
"nymex_ng",
"ice_cig_basis",
"myr_palm_oil",
"ice_wti_midland_basis",
"ice_pmi",
"ice_erh",
"ice_eiw",
"ice_hen_basis",
"ice_his_basis",
"cme_myr_palm_oil"
}

Definition at line 38 of file conventionsbasedfutureexpiry.cpp.