Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
equitymarketdata.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <ored/configuration/curveconfigurations.hpp>
#include <ored/marketdata/marketdatumparser.hpp>
#include <ored/utilities/parsers.hpp>
#include <ored/utilities/xmlutils.hpp>
#include <oret/toplevelfixture.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/assign/list_of.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testMarketDatumParser)
 
 BOOST_AUTO_TEST_CASE (testBadMarketDatumStrings)
 
 BOOST_AUTO_TEST_CASE (testEqCurveConfigLoad)
 
 BOOST_AUTO_TEST_CASE (testEqCurveConfigBadLoad)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/4]

BOOST_AUTO_TEST_CASE ( testMarketDatumParser  )

Definition at line 125 of file equitymarketdata.cpp.

125 {
126
127 BOOST_TEST_MESSAGE("Testing equity market data parsing...");
128 std::vector<std::string> marketDataStrings = getMarketDataStrings();
129 for (auto s : marketDataStrings) {
130 std::vector<std::string> tokens;
131 boost::trim(s);
132 boost::split(tokens, s, boost::is_any_of(" "), boost::token_compress_on);
133 Date quoteDate = ore::data::parseDate(tokens[0]);
134 const string& key = tokens[1];
135 Real value = ore::data::parseReal(tokens[2]);
136
137 BOOST_CHECK_NO_THROW(ore::data::parseMarketDatum(quoteDate, key, value));
138 QuantLib::ext::shared_ptr<ore::data::MarketDatum> md = ore::data::parseMarketDatum(quoteDate, key, value);
139 BOOST_CHECK(md);
140 BOOST_CHECK_EQUAL(md->name(), key);
141 BOOST_CHECK_EQUAL(md->asofDate(), quoteDate);
142 BOOST_CHECK_EQUAL(md->quote()->value(), value);
143 }
144}
SafeStack< ValueType > value
QuantLib::ext::shared_ptr< MarketDatum > parseMarketDatum(const Date &asof, const string &datumName, const Real &value)
Function to parse a market datum.
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
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/4]

BOOST_AUTO_TEST_CASE ( testBadMarketDatumStrings  )

Definition at line 146 of file equitymarketdata.cpp.

146 {
147
148 BOOST_TEST_MESSAGE("Testing equity market data parsing (bad strings)...");
149 std::vector<std::string> marketDataStrings = getBadMarketDataStrings();
150 for (auto s : marketDataStrings) {
151 std::vector<std::string> tokens;
152 boost::trim(s);
153 boost::split(tokens, s, boost::is_any_of(" "), boost::token_compress_on);
154 Date quoteDate = ore::data::parseDate(tokens[0]);
155 const string& key = tokens[1];
156 Real value = ore::data::parseReal(tokens[2]);
157 BOOST_CHECK_THROW(ore::data::parseMarketDatum(quoteDate, key, value), QuantLib::Error);
158 }
159}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( testEqCurveConfigLoad  )

Definition at line 161 of file equitymarketdata.cpp.

161 {
162
163 BOOST_TEST_MESSAGE("Testing equity curve config load...");
165 testDoc.fromXMLString(divYieldCurveConfigString);
166 // check that the root node is as expected
167 ore::data::XMLNode* node = testDoc.getFirstNode("CurveConfiguration");
168 BOOST_CHECK_NO_THROW(ore::data::XMLUtils::checkNode(node, "CurveConfiguration"));
169
171 BOOST_CHECK_NO_THROW(cc.fromXML(node));
172 QuantLib::ext::shared_ptr<ore::data::EquityCurveConfig> ec = cc.equityCurveConfig("SP5");
173 BOOST_CHECK(ec);
174 BOOST_CHECK_EQUAL("SP5", ec->curveID());
175 BOOST_CHECK_EQUAL("SP 500 equity price projection curve",
176 ec->curveDescription());
177 BOOST_CHECK_EQUAL("USD", ec->currency());
178 BOOST_CHECK_EQUAL("EQUITY/PRICE/SP5/USD", ec->equitySpotQuoteID());
179 bool testType = (ec->type() == ore::data::EquityCurveConfig::Type::DividendYield);
180 BOOST_CHECK(testType);
181 //BOOST_CHECK_EQUAL(ore::data::EquityCurveConfig::Type::DividendYield, ec->type());
182 BOOST_CHECK_EQUAL("A365", ec->dayCountID());
183 vector<string> anticipatedQuotes = boost::assign::list_of
184 ("EQUITY/PRICE/SP5/USD")
185 ("EQUITY_DIVIDEND/RATE/SP5/USD/1M")
186 ("EQUITY_DIVIDEND/RATE/SP5/USD/2016-09-15")
187 ("EQUITY_DIVIDEND/RATE/SP5/USD/1Y")
188 ("EQUITY_DIVIDEND/RATE/SP5/USD/2Y")
189 ("EQUITY_DIVIDEND/RATE/SP5/USD/5Y");
190 vector<string> actualQuotes = ec->quotes();
191 BOOST_CHECK_EQUAL_COLLECTIONS(anticipatedQuotes.begin(), anticipatedQuotes.end(),
192 actualQuotes.begin(), actualQuotes.end());
193 BOOST_CHECK(!ec->extrapolation());
194
195 // now test the toXML member function
196 ore::data::XMLDocument testDumpDoc;
197 BOOST_CHECK_NO_THROW(cc.toXML(testDumpDoc));
198 // TODO - query the XML to ensure that the curve configuration objects have been dumped correctly
199}
Container class for all Curve Configurations.
QuantLib::ext::shared_ptr< EquityCurveConfig > equityCurveConfig(const string &curveID) const
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
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
static void checkNode(XMLNode *n, const string &expectedName)
Definition: xmlutils.cpp:175
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( testEqCurveConfigBadLoad  )

Definition at line 201 of file equitymarketdata.cpp.

201 {
202
203 BOOST_TEST_MESSAGE("Testing equity curve config load (bad input)...");
204 ore::data::XMLDocument testBadDoc;
205 testBadDoc.fromXMLString(eqBadConfigString);
206 // check that the root node is as expected
207 ore::data::XMLNode* badNode = testBadDoc.getFirstNode("CurveConfiguration");
208 BOOST_CHECK_NO_THROW(ore::data::XMLUtils::checkNode(badNode, "CurveConfiguration"));
210 BOOST_CHECK_NO_THROW(cc.fromXML(badNode)); // the spot price is missing, but the correct behaviour is to log error and move on
211 BOOST_CHECK_THROW(cc.equityCurveConfig("SP5Mini"), QuantLib::Error); // this checks that the XML throws when we try to load
212}
+ Here is the call graph for this function: