19#include <boost/test/unit_test.hpp>
24#include <oret/toplevelfixture.hpp>
26#include <boost/algorithm/string.hpp>
27#include <boost/assign/list_of.hpp>
34std::vector<std::string> getMarketDataStrings() {
36 return boost::assign::list_of
38 (
"20160226 EQUITY/PRICE/SP5/USD 1650.17")
39 (
"20160226 EQUITY/PRICE/Lufthansa/EUR 17.56")
40 (
"20160226 EQUITY_FWD/PRICE/SP5/USD/1Y 1678.54")
41 (
"20160226 EQUITY_FWD/PRICE/SP5/USD/2017-02-26 1678.54")
42 (
"20160226 EQUITY_FWD/PRICE/SP5/USD/20170226 1678.54")
43 (
"20160226 EQUITY_FWD/PRICE/SP5/USD/365D 1678.54")
44 (
"20160226 EQUITY_FWD/PRICE/SP5/USD/1678W5D 1900.50")
45 (
"20160226 EQUITY_FWD/PRICE/Lufthansa/EUR/1Y1M 1678.54")
46 (
"20160226 EQUITY_DIVIDEND/RATE/SP5/USD/1Y 0.025")
47 (
"20160226 EQUITY_DIVIDEND/RATE/SP5/USD/2017-02-26 0.025")
48 (
"20160226 EQUITY_DIVIDEND/RATE/SP5/USD/20170226 0.025")
49 (
"20160226 EQUITY_DIVIDEND/RATE/SP5/USD/365D 0.025")
50 (
"20160226 EQUITY_DIVIDEND/RATE/SP5/USD/1678W5D 0.025")
51 (
"20160226 EQUITY_DIVIDEND/RATE/Lufthansa/EUR/1Y1M 0.013")
52 (
"20160226 EQUITY_OPTION/RATE_LNVOL/SP5/USD/12M/ATMF 0.25")
53 (
"20160226 EQUITY_OPTION/RATE_LNVOL/SP5/USD/2017-02-26/ATMF 0.25")
54 (
"20160226 EQUITY_OPTION/RATE_LNVOL/SP5/USD/20170226/ATMF 0.25")
55 (
"20160226 EQUITY_OPTION/RATE_LNVOL/SP5/USD/365D/ATMF 0.25")
56 (
"20160226 EQUITY_OPTION/RATE_LNVOL/SP5/USD/1678W5D/ATMF 0.25")
57 (
"20160226 EQUITY_OPTION/RATE_LNVOL/Lufthansa/EUR/1Y1M/ATMF 0.13");
60std::vector<std::string> getBadMarketDataStrings() {
62 return boost::assign::list_of
64 (
"20160226 EQUITY_SPOT/PRICE/SP5/USD 1650.17")
65 (
"20160226 EQUITY/RATE/Lufthansa/EUR 17.56")
66 (
"20160226 EQUITY_FORWARD/PRICE/SP5/USD/1Y 1678.54")
67 (
"20160226 EQUITY_FWD/SPREAD/SP5/USD/2017-02-26 1678.54")
68 (
"20160226 EQUITY_FWD/PRICE/SP5/USD/zzz 1678.54")
69 (
"20160226 EQUITY_DIV_YIELD/RATE/SP5/USD/1Y 1678.54")
70 (
"20160226 EQUITY_DIVIDEND/PRICE/SP5/USD/2017-02-26 1678.54")
71 (
"20160226 EQUITY_DIVIDEND/RATE/SP5/USD/zzz 1678.54")
72 (
"20160226 EQUITY_OPTION_VOL/RATE_LNVOL/SP5/USD/12M/ATMF 0.25")
73 (
"20160226 EQUITY_OPTION/RATE_NVOL/SP5/USD/2017-02-26/ATMF 0.25")
74 (
"20160226 EQUITY_OPTION/RATE_LNVOL/SP5/USD/zzz/ATMF 0.25");
77std::string divYieldCurveConfigString =
81"<CurveId>SP5</CurveId>"
82"<ForecastingCurve>USD1D</ForecastingCurve>"
83"<CurveDescription>SP 500 equity price projection curve</CurveDescription>"
84"<Currency>USD</Currency> <!--is this really needed ? -->"
85"<Type>DividendYield</Type> <!-- {DividendYield, ForwardPrice} -->"
86"<SpotQuote>EQUITY/PRICE/SP5/USD</SpotQuote> <!--the spot quote from the market data file-->"
88"<Quote>EQUITY_DIVIDEND/RATE/SP5/USD/1M</Quote>"
89"<Quote>EQUITY_DIVIDEND/RATE/SP5/USD/2016-09-15</Quote>"
90"<Quote>EQUITY_DIVIDEND/RATE/SP5/USD/1Y</Quote>"
91"<Quote>EQUITY_DIVIDEND/RATE/SP5/USD/2Y</Quote>"
92"<Quote>EQUITY_DIVIDEND/RATE/SP5/USD/5Y</Quote>"
94"<DayCounter>A365</DayCounter>"
97"</CurveConfiguration>";
99std::string eqBadConfigString =
100"<CurveConfiguration>"
103"<CurveId>SP5Mini</CurveId>"
104"<ForecastCurve>USD1D</ForecastCurve>"
105"<CurveDescription>SP Mini equity price projection curve</CurveDescription>"
106"<Currency>USD</Currency> <!--is this really needed ? -->"
107"<Type>ForwardPrice</Type> <!-- {DividendYield, ForwardPrice} -->"
109"<Quote>EQUITY_FWD/PRICE/SP5Mini/USD/1M</Quote>"
110"<Quote>EQUITY_FWD/PRICE/SP5Mini/USD/2016-09-15</Quote>"
111"<Quote>EQUITY_FWD/PRICE/SP5Mini/USD/1Y</Quote>"
112"<Quote>EQUITY_FWD/PRICE/SP5Mini/USD/2Y</Quote>"
113"<Quote>EQUITY_FWD/PRICE/SP5Mini/USD/5Y</Quote>"
117"</CurveConfiguration>";
121BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
123BOOST_AUTO_TEST_SUITE(EquityMarketDataTests)
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;
132 boost::split(tokens, s, boost::is_any_of(
" "), boost::token_compress_on);
134 const string& key = tokens[1];
140 BOOST_CHECK_EQUAL(md->name(), key);
141 BOOST_CHECK_EQUAL(md->asofDate(), quoteDate);
142 BOOST_CHECK_EQUAL(md->quote()->value(),
value);
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;
153 boost::split(tokens, s, boost::is_any_of(
" "), boost::token_compress_on);
155 const string& key = tokens[1];
163 BOOST_TEST_MESSAGE(
"Testing equity curve config load...");
171 BOOST_CHECK_NO_THROW(cc.
fromXML(node));
172 QuantLib::ext::shared_ptr<ore::data::EquityCurveConfig> ec = cc.
equityCurveConfig(
"SP5");
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());
180 BOOST_CHECK(testType);
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());
197 BOOST_CHECK_NO_THROW(cc.
toXML(testDumpDoc));
203 BOOST_TEST_MESSAGE(
"Testing equity curve config load (bad input)...");
210 BOOST_CHECK_NO_THROW(cc.
fromXML(badNode));
214BOOST_AUTO_TEST_SUITE_END()
216BOOST_AUTO_TEST_SUITE_END()
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.
void fromXMLString(const string &xmlString)
load a document from a hard-coded string
XMLNode * getFirstNode(const string &name) const
static void checkNode(XMLNode *n, const string &expectedName)
SafeStack< ValueType > value
Curve configuration repository.
BOOST_AUTO_TEST_CASE(testMarketDatumParser)
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.
Real parseReal(const string &s)
Convert text to Real.
Map text representations to QuantLib/QuantExt types.