Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions | Variables
commoditycurve.cpp File Reference
#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <oret/datapaths.hpp>
#include <oret/toplevelfixture.hpp>
#include <ql/math/comparison.hpp>
#include <ql/math/interpolations/linearinterpolation.hpp>
#include <ql/math/interpolations/loginterpolation.hpp>
#include <ql/time/daycounters/actualactual.hpp>
#include <ored/configuration/curveconfigurations.hpp>
#include <ored/marketdata/commoditycurve.hpp>
#include <ored/marketdata/csvloader.hpp>
#include <ored/marketdata/curvespec.hpp>
#include <ored/marketdata/loader.hpp>
#include <ored/marketdata/todaysmarket.hpp>
#include <ored/utilities/csvfilereader.hpp>
#include <ored/utilities/to_string.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testCommodityCurveTenorBasedOnTnPoints)
 
 BOOST_AUTO_TEST_CASE (testCommodityCurveFixedDatePoints)
 
 BOOST_DATA_TEST_CASE (testCommodityInterpolations, bdata::make(curveConfigFiles), curveConfigFile)
 
ostream & operator<< (ostream &os, CommodityCurveTestCase testCase)
 
 BOOST_DATA_TEST_CASE (testCommodityCurveBuilding, bdata::make(commodityCurveTestCases), testCase)
 

Variables

vector< CommodityCurveTestCase > commodityCurveTestCases
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

BOOST_AUTO_TEST_CASE ( testCommodityCurveTenorBasedOnTnPoints  )

Definition at line 139 of file commoditycurve.cpp.

139 {
140
141 BOOST_TEST_MESSAGE("Testing commodity curve building with tenor based points quotes including ON and TN");
142
143 QuantLib::ext::shared_ptr<CommodityCurve> curve = createCurve("tenor_based_on_tn_points");
144 checkCurve(curve->commodityPriceCurve(), expectedCurve);
145}

◆ BOOST_AUTO_TEST_CASE() [2/2]

BOOST_AUTO_TEST_CASE ( testCommodityCurveFixedDatePoints  )

Definition at line 147 of file commoditycurve.cpp.

147 {
148
149 BOOST_TEST_MESSAGE("Testing commodity curve building with fixed date quotes");
150
151 QuantLib::ext::shared_ptr<CommodityCurve> curve = createCurve("fixed_date_points");
152 checkCurve(curve->commodityPriceCurve(), expectedCurve);
153}

◆ BOOST_DATA_TEST_CASE() [1/2]

BOOST_DATA_TEST_CASE ( testCommodityInterpolations  ,
bdata::make(curveConfigFiles)  ,
curveConfigFile   
)

Definition at line 156 of file commoditycurve.cpp.

156 {
157
158 BOOST_TEST_MESSAGE("Testing with configuration file: " << curveConfigFile);
159
160 QuantLib::ext::shared_ptr<CommodityCurve> curve = createCurve("different_interpolations", curveConfigFile);
161 checkCurve(curve->commodityPriceCurve(), expectedInterpCurvePillars);
162
163 BOOST_REQUIRE(expectedInterpCurveOffPillars.count(curveConfigFile) == 1);
164 for (Size i = 0; i < offPillarDates.size(); i++) {
165 Real price = curve->commodityPriceCurve()->price(offPillarDates[i]);
166 Real expPrice = expectedInterpCurveOffPillars.at(curveConfigFile)[i];
167 BOOST_CHECK_CLOSE(price, expPrice, 1e-12);
168 }
169}

◆ operator<<()

ostream & operator<< ( ostream &  os,
CommodityCurveTestCase  testCase 
)

Definition at line 196 of file commoditycurve.cpp.

196 {
197 return os << "[" << io::iso_date(testCase.asof) << "," << testCase.name << "," << testCase.curveName << "]";
198}

◆ BOOST_DATA_TEST_CASE() [2/2]

BOOST_DATA_TEST_CASE ( testCommodityCurveBuilding  ,
bdata::make(commodityCurveTestCases ,
testCase   
)

Definition at line 200 of file commoditycurve.cpp.

200 {
201
202 BOOST_TEST_MESSAGE("Testing commodity curve building " << testCase << "...");
203
204 Settings::instance().evaluationDate() = testCase.asof;
205 QuantLib::ext::shared_ptr<TodaysMarket> tm;
206 BOOST_REQUIRE_NO_THROW(tm = createTodaysMarket(testCase.asof, testCase.name));
207
208 auto pts = tm->commodityPriceCurve(testCase.curveName);
209
210 for (const Date& d : pts->pillarDates()) {
211 BOOST_TEST_MESSAGE(io::iso_date(d) << "," << fixed << setprecision(12) << pts->price(d));
212 }
213
214 // Tolerance for float comparison
215 Real tol = 1e-12;
216
217 // Read in the expected pillar results for the given date.
218 vector<Date> expPillarDates;
219 string filename = testCase.name + "/expected_" + to_string(io::iso_date(testCase.asof)) + ".csv";
220 CSVFileReader reader(TEST_INPUT_FILE(filename), true, ",");
221 BOOST_REQUIRE_EQUAL(reader.numberOfColumns(), 2);
222
223 while (reader.next()) {
224 // Get the expected expiry pillar date and price.
225 Date expiry = parseDate(reader.get(0));
226 Real price = parseReal(reader.get(1));
227 expPillarDates.push_back(expiry);
228
229 // Check the surface on the grid point.
230 Real calcPrice = pts->price(expiry);
231 BOOST_TEST_MESSAGE(io::iso_date(expiry) << "," << fixed << setprecision(12) << calcPrice);
232 BOOST_CHECK_SMALL(price - calcPrice, tol);
233 }
234
235 vector<Date> calcPillarDates = pts->pillarDates();
236 BOOST_CHECK_EQUAL_COLLECTIONS(expPillarDates.begin(), expPillarDates.end(),
237 calcPillarDates.begin(), calcPillarDates.end());
238
239 // Set up has flat extrapolation. Check it here.
240 Real lastPrice = pts->price(calcPillarDates.back());
241 Date extrapDate = calcPillarDates.back() + 1 * Years;
242 Real extrapPrice = pts->price(extrapDate);
243 BOOST_CHECK_SMALL(lastPrice - extrapPrice, tol);
244}
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:

Variable Documentation

◆ commodityCurveTestCases

vector<CommodityCurveTestCase> commodityCurveTestCases
Initial value:
= {
{Date(30, Sep, 2019), "basis/wti_midland_cm", "NYMEX:FF"},
{Date(30, Sep, 2019), "basis/wti_midland_tm", "NYMEX:WTT"},
{Date(30, Sep, 2019), "basis/wti_midland_cm_base_ave", "NYMEX:FF"},
{Date(30, Sep, 2019), "basis/houston_ship_channel", "ICE:HXS"},
{Date(23, Jan, 2020), "basis/wti_midland_cm", "NYMEX:FF"},
{Date(23, Jan, 2020), "basis/wti_midland_tm", "NYMEX:WTT"},
{Date(23, Jan, 2020), "basis/wti_midland_cm_base_ave", "NYMEX:FF"},
{Date(23, Jan, 2020), "basis/houston_ship_channel", "ICE:HXS"},
{Date(27, Apr, 2020), "power/pjm_wh_rt_peak_linear_flat", "ICE:PDQ"},
{Date(27, Apr, 2020), "power/pjm_wh_rt_peak_backward_flat", "ICE:PDQ"},
{Date(27, Apr, 2020), "power/pjm_wh_rt_peak_linear_flat_switch_priority", "ICE:PDQ"}
}

Definition at line 181 of file commoditycurve.cpp.