19#include <boost/test/unit_test.hpp>
20#include <oret/toplevelfixture.hpp>
25using namespace boost::unit_test_framework;
29BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
31BOOST_AUTO_TEST_SUITE(CommodityVolatilityConfigTests)
35 BOOST_TEST_MESSAGE(
"Testing parsing of constant commodity vol curve configuration from XML");
39 configXml.append(
"<CommodityVolatility>");
40 configXml.append(
" <CurveId>GOLD_USD_VOLS</CurveId>");
41 configXml.append(
" <CurveDescription/>");
42 configXml.append(
" <Currency>USD</Currency>");
43 configXml.append(
" <Constant>");
44 configXml.append(
" <Quote>COMMODITY_OPTION/RATE_LNVOL/GOLD/USD/1Y/ATM/AtmFwd</Quote>");
45 configXml.append(
" </Constant>");
46 configXml.append(
"</CommodityVolatility>");
58 BOOST_CHECK_EQUAL(config.
curveID(),
"GOLD_USD_VOLS");
59 BOOST_CHECK_EQUAL(config.
currency(),
"USD");
61 QuantLib::ext::shared_ptr<ConstantVolatilityConfig> vc;
63 if ((vc = QuantLib::ext::dynamic_pointer_cast<ConstantVolatilityConfig>(v)))
67 BOOST_CHECK_EQUAL(config.
quotes().size(), 1);
68 BOOST_CHECK_EQUAL(config.
quotes()[0],
"COMMODITY_OPTION/RATE_LNVOL/GOLD/USD/1Y/ATM/AtmFwd");
71 BOOST_CHECK_EQUAL(config.
dayCounter(),
"A365");
72 BOOST_CHECK_EQUAL(config.
calendar(),
"NullCalendar");
79 BOOST_TEST_MESSAGE(
"Testing parsing of commodity vol curve configuration from XML");
83 configXml.append(
"<CommodityVolatility>");
84 configXml.append(
" <CurveId>GOLD_USD_VOLS</CurveId>");
85 configXml.append(
" <CurveDescription/>");
86 configXml.append(
" <Currency>USD</Currency>");
87 configXml.append(
" <Curve>");
88 configXml.append(
" <Quotes>");
89 configXml.append(
" <Quote>COMMODITY_OPTION/RATE_LNVOL/GOLD/USD/1Y/ATM/AtmFwd</Quote>");
90 configXml.append(
" <Quote>COMMODITY_OPTION/RATE_LNVOL/GOLD/USD/5Y/ATM/AtmFwd</Quote>");
91 configXml.append(
" <Quote>COMMODITY_OPTION/RATE_LNVOL/GOLD/USD/10Y/ATM/AtmFwd</Quote>");
92 configXml.append(
" </Quotes>");
93 configXml.append(
" <Interpolation>Linear</Interpolation>");
94 configXml.append(
" <Extrapolation>Flat</Extrapolation>");
95 configXml.append(
" </Curve>");
96 configXml.append(
"</CommodityVolatility>");
108 vector<string> quotes = {
"COMMODITY_OPTION/RATE_LNVOL/GOLD/USD/1Y/ATM/AtmFwd",
109 "COMMODITY_OPTION/RATE_LNVOL/GOLD/USD/5Y/ATM/AtmFwd",
110 "COMMODITY_OPTION/RATE_LNVOL/GOLD/USD/10Y/ATM/AtmFwd"};
113 BOOST_CHECK_EQUAL(config.
curveID(),
"GOLD_USD_VOLS");
114 BOOST_CHECK_EQUAL(config.
currency(),
"USD");
116 QuantLib::ext::shared_ptr<VolatilityCurveConfig> vc;
118 if ((vc = QuantLib::ext::dynamic_pointer_cast<VolatilityCurveConfig>(v)))
123 BOOST_CHECK_EQUAL(vc->interpolation(),
"Linear");
124 BOOST_CHECK_EQUAL(vc->extrapolation(),
"Flat");
125 BOOST_CHECK_EQUAL(config.
quotes().size(), 3);
126 BOOST_CHECK_EQUAL_COLLECTIONS(quotes.begin(), quotes.end(), config.
quotes().begin(), config.
quotes().end());
129 BOOST_CHECK_EQUAL(config.
dayCounter(),
"A365");
130 BOOST_CHECK_EQUAL(config.
calendar(),
"NullCalendar");
139 BOOST_CHECK_EQUAL(config.
dayCounter(),
"ACT");
144 BOOST_CHECK_EQUAL(config.
calendar(),
"TARGET");
159 BOOST_TEST_MESSAGE(
"Testing parsing of commodity vol surface configuration from XML");
163 configXml.append(
"<CommodityVolatility>");
164 configXml.append(
" <CurveId>WTI_USD_VOLS</CurveId>");
165 configXml.append(
" <CurveDescription/>");
166 configXml.append(
" <Currency>USD</Currency>");
167 configXml.append(
" <StrikeSurface>");
168 configXml.append(
" <Strikes>30.0,40.0,60.0</Strikes>");
169 configXml.append(
" <Expiries>1Y,5Y,10Y</Expiries>");
170 configXml.append(
" <TimeInterpolation>Linear</TimeInterpolation>");
171 configXml.append(
" <StrikeInterpolation>Linear</StrikeInterpolation>");
172 configXml.append(
" <Extrapolation>true</Extrapolation>");
173 configXml.append(
" <TimeExtrapolation>Flat</TimeExtrapolation>");
174 configXml.append(
" <StrikeExtrapolation>Flat</StrikeExtrapolation>");
175 configXml.append(
" </StrikeSurface>");
176 configXml.append(
"</CommodityVolatility>");
188 vector<string> quotes = {
"COMMODITY_OPTION/RATE_LNVOL/WTI_USD_VOLS/USD/1Y/30.0",
189 "COMMODITY_OPTION/RATE_LNVOL/WTI_USD_VOLS/USD/1Y/40.0",
190 "COMMODITY_OPTION/RATE_LNVOL/WTI_USD_VOLS/USD/1Y/60.0",
191 "COMMODITY_OPTION/RATE_LNVOL/WTI_USD_VOLS/USD/5Y/30.0",
192 "COMMODITY_OPTION/RATE_LNVOL/WTI_USD_VOLS/USD/5Y/40.0",
193 "COMMODITY_OPTION/RATE_LNVOL/WTI_USD_VOLS/USD/5Y/60.0",
194 "COMMODITY_OPTION/RATE_LNVOL/WTI_USD_VOLS/USD/10Y/30.0",
195 "COMMODITY_OPTION/RATE_LNVOL/WTI_USD_VOLS/USD/10Y/40.0",
196 "COMMODITY_OPTION/RATE_LNVOL/WTI_USD_VOLS/USD/10Y/60.0"};
199 BOOST_CHECK_EQUAL(config.
curveID(),
"WTI_USD_VOLS");
200 BOOST_CHECK_EQUAL(config.
currency(),
"USD");
202 QuantLib::ext::shared_ptr<VolatilityStrikeSurfaceConfig> vc;
204 if ((vc = QuantLib::ext::dynamic_pointer_cast<VolatilityStrikeSurfaceConfig>(v)))
208 BOOST_CHECK_EQUAL(vc->timeInterpolation(),
"Linear");
209 BOOST_CHECK_EQUAL(vc->strikeInterpolation(),
"Linear");
210 BOOST_CHECK(vc->extrapolation());
211 BOOST_CHECK_EQUAL(vc->timeExtrapolation(),
"Flat");
212 BOOST_CHECK_EQUAL(vc->strikeExtrapolation(),
"Flat");
213 BOOST_CHECK_EQUAL(config.
quotes().size(), 9);
214 BOOST_CHECK_EQUAL_COLLECTIONS(quotes.begin(), quotes.end(), config.
quotes().begin(), config.
quotes().end());
217 BOOST_CHECK_EQUAL(config.
dayCounter(),
"A365");
218 BOOST_CHECK_EQUAL(config.
calendar(),
"NullCalendar");
223BOOST_AUTO_TEST_SUITE_END()
225BOOST_AUTO_TEST_SUITE_END()
Commodity volatility configuration.
const std::string & currency() const
QuantLib::Natural optionExpiryRollDays() const
const std::vector< QuantLib::ext::shared_ptr< VolatilityConfig > > & volatilityConfig() const
void fromXML(XMLNode *node) override
const std::string & futureConventionsId() const
const std::string & dayCounter() const
const std::string & calendar() const
const string & curveID() const
virtual const vector< string > & quotes()
Return all the market quotes required for this config.
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 XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Commodity volatility curve configuration.
BOOST_AUTO_TEST_CASE(testParseConstantVolFromXml)