Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commoditycurveconfig.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19#include <boost/test/unit_test.hpp>
20#include <oret/toplevelfixture.hpp>
21
23
24using namespace std;
25using namespace boost::unit_test_framework;
26using namespace QuantLib;
27using namespace ore::data;
28
29BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
30
31BOOST_AUTO_TEST_SUITE(CommodityCurveConfigTests)
32
33BOOST_AUTO_TEST_CASE(testConstructionQuotes) {
34
35 BOOST_TEST_MESSAGE("Testing commodity curve configuration quote vector construction");
36
37 // Main thing to check here is that the spot quote gets
38 // inserted at the beginning of the vector of quotes
39 string curveId = "GOLD_USD";
40 string curveDescription = "Value of troy ounce of gold in USD";
41 string currency = "USD";
42 string commoditySpotQuote = "COMMODITY/PRICE/GOLD/USD";
43 vector<string> quotes = {"COMMODITY_FWD/PRICE/GOLD/USD/2016-02-29", "COMMODITY_FWD/PRICE/GOLD/USD/2017-02-28"};
44
45 // Create configuration
46 CommodityCurveConfig config(curveId, curveDescription, currency, quotes, commoditySpotQuote);
47
48 // Check quotes vector from config (none of the other members have logic)
49 quotes.insert(quotes.begin(), commoditySpotQuote);
50 BOOST_CHECK_EQUAL_COLLECTIONS(quotes.begin(), quotes.end(), config.quotes().begin(), config.quotes().end());
51}
52
53BOOST_AUTO_TEST_CASE(testParseFromXml) {
54
55 BOOST_TEST_MESSAGE("Testing parsing of commodity curve configuration from XML");
56
57 // Create an XML string representation of the commodity curve configuration
58 string configXml;
59 configXml.append("<CommodityCurve>");
60 configXml.append(" <CurveId>GOLD_USD</CurveId>");
61 configXml.append(" <CurveDescription>Gold USD price curve</CurveDescription>");
62 configXml.append(" <Currency>USD</Currency>");
63 configXml.append(" <SpotQuote>COMMODITY/PRICE/GOLD/USD</SpotQuote>");
64 configXml.append(" <Quotes>");
65 configXml.append(" <Quote>COMMODITY_FWD/PRICE/GOLD/USD/2016-02-29</Quote>");
66 configXml.append(" <Quote>COMMODITY_FWD/PRICE/GOLD/USD/2017-02-28</Quote>");
67 configXml.append(" </Quotes>");
68 configXml.append(" <DayCounter>A365</DayCounter>");
69 configXml.append(" <InterpolationMethod>Linear</InterpolationMethod>");
70 configXml.append(" <Extrapolation>true</Extrapolation>");
71 configXml.append("</CommodityCurve>");
72
73 // Create the XMLNode
74 XMLDocument doc;
75 doc.fromXMLString(configXml);
76 XMLNode* configNode = doc.getFirstNode("CommodityCurve");
77
78 // Parse commodity curve configuration from XML
80 config.fromXML(configNode);
81
82 // Expected vector of quotes
83 vector<string> quotes = {"COMMODITY/PRICE/GOLD/USD", "COMMODITY_FWD/PRICE/GOLD/USD/2016-02-29",
84 "COMMODITY_FWD/PRICE/GOLD/USD/2017-02-28"};
85
86 // Check fields
87 BOOST_CHECK_EQUAL(config.curveID(), "GOLD_USD");
88 BOOST_CHECK_EQUAL(config.curveDescription(), "Gold USD price curve");
89 BOOST_CHECK_EQUAL(config.currency(), "USD");
90 BOOST_CHECK_EQUAL(config.commoditySpotQuoteId(), "COMMODITY/PRICE/GOLD/USD");
91 BOOST_CHECK_EQUAL_COLLECTIONS(quotes.begin(), quotes.end(), config.quotes().begin(), config.quotes().end());
92 BOOST_CHECK_EQUAL(config.dayCountId(), "A365");
93 BOOST_CHECK_EQUAL(config.interpolationMethod(), "Linear");
94 BOOST_CHECK_EQUAL(config.extrapolation(), true);
95}
96
97BOOST_AUTO_TEST_SUITE_END()
98
99BOOST_AUTO_TEST_SUITE_END()
Commodity curve configuration.
const std::string & currency() const
void fromXML(XMLNode *node) override
const std::string & interpolationMethod() const
const std::string & dayCountId() const
const std::string & commoditySpotQuoteId() const
const string & curveDescription() const
Definition: curveconfig.hpp:55
const string & curveID() const
Definition: curveconfig.hpp:54
virtual const vector< string > & quotes()
Return all the market quotes required for this config.
Definition: curveconfig.hpp:69
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
void fromXMLString(const string &xmlString)
load a document from a hard-coded string
Definition: xmlutils.cpp:103
XMLNode * getFirstNode(const string &name) const
Definition: xmlutils.cpp:116
Commodity curve configuration class.
BOOST_AUTO_TEST_CASE(testConstructionQuotes)