19#include <boost/algorithm/string.hpp>
20#include <boost/make_shared.hpp>
22#include <boost/test/unit_test.hpp>
23#include <boost/test/data/test_case.hpp>
40#include <oret/datapaths.hpp>
41#include <oret/fileutilities.hpp>
42#include <oret/toplevelfixture.hpp>
44#include <ql/time/calendar.hpp>
45#include <ql/time/daycounter.hpp>
49using namespace boost::unit_test_framework;
54using ore::test::TopLevelFixture;
64class F :
public TopLevelFixture {
71 clearOutput(TEST_OUTPUT_PATH);
74 curveConfigs.fromFile(TEST_INPUT_FILE(
"curve_config.xml"));
81set<string> readQuotes(
const string& filename) {
87 while (reader.next()) {
88 quotes.insert(reader.get(0));
95vector<pair<string, string>> files = {
96 make_pair(
"todays_market_only_ir.xml",
"expected_quotes_only_ir.csv"),
97 make_pair(
"todays_market_with_fx_vol_smile.xml",
"expected_quotes_with_fx_vol_smile.csv"),
98 make_pair(
"todays_market_with_fx_vol_smile_delta.xml",
"expected_quotes_with_fx_vol_smile_delta.csv"),
99 make_pair(
"todays_market_with_fx_vol_atm.xml",
"expected_quotes_with_fx_vol_atm.csv"),
100 make_pair(
"todays_market_single_config_gbp.xml",
"expected_quotes_tmp_single_gbp.csv")};
107namespace test_tools {
109template <>
struct print_log_value<pair<string, string>> {
110 void operator()(std::ostream& os,
const pair<string, string>& p) { os <<
"[" << p.first <<
"," << p.second <<
"]"; }
116BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, TopLevelFixture)
118BOOST_FIXTURE_TEST_SUITE(CurveConfigTest, F)
123 string outputFile_1 = TEST_OUTPUT_FILE(
"curve_config_out_1.xml");
128 curveConfigsNew.
fromFile(outputFile_1);
132 string outputFile_2 = TEST_OUTPUT_FILE(
"curve_config_out_2.xml");
133 curveConfigsNew.
toFile(outputFile_2);
136 BOOST_CHECK(compareFiles(outputFile_1, outputFile_2));
146 set<string> expectedQuotes = readQuotes(TEST_INPUT_FILE(
"expected_quotes_all.csv"));
149 BOOST_REQUIRE_EQUAL(quotes.size(), expectedQuotes.size());
150 BOOST_CHECK_EQUAL_COLLECTIONS(quotes.begin(), quotes.end(), expectedQuotes.begin(), expectedQuotes.end());
156 BOOST_TEST_MESSAGE(
"Testing with todaysmarket file: " << filePair.first);
159 QuantLib::ext::shared_ptr<TodaysMarketParameters> tmp = QuantLib::ext::make_shared<TodaysMarketParameters>();
160 tmp->fromFile(TEST_INPUT_FILE(filePair.first));
166 set<string> expectedQuotes = readQuotes(TEST_INPUT_FILE(filePair.second));
169 BOOST_REQUIRE_EQUAL(quotes.size(), expectedQuotes.size());
170 BOOST_CHECK_EQUAL_COLLECTIONS(quotes.begin(), quotes.end(), expectedQuotes.begin(), expectedQuotes.end());
177 QuantLib::ext::shared_ptr<TodaysMarketParameters> tmp = QuantLib::ext::make_shared<TodaysMarketParameters>();
178 tmp->fromFile(TEST_INPUT_FILE(
"todays_market_multiple_configs.xml"));
180 BOOST_REQUIRE_EQUAL(tmp->configurations().size(), 4);
183 for (
const auto& kv : tmp->configurations()) {
185 BOOST_TEST_MESSAGE(
"Checking quotes for configuration: " << kv.first);
189 set<string> quotes =
curveConfigs.quotes(tmp, {kv.first});
192 set<string> expectedQuotes;
193 if (kv.first ==
"collateral_inccy") {
194 expectedQuotes = readQuotes(TEST_INPUT_FILE(
"expected_quotes_tmp_multiple_collateral_inccy.csv"));
196 expectedQuotes = readQuotes(TEST_INPUT_FILE(
"expected_quotes_tmp_multiple.csv"));
200 BOOST_REQUIRE_EQUAL(quotes.size(), expectedQuotes.size());
201 BOOST_CHECK_EQUAL_COLLECTIONS(quotes.begin(), quotes.end(), expectedQuotes.begin(), expectedQuotes.end());
210 xml.append(
"<DiscountRatio>");
211 xml.append(
" <Type>Discount Ratio</Type>");
212 xml.append(
" <BaseCurve currency=\"EUR\">EUR1D</BaseCurve>");
213 xml.append(
" <NumeratorCurve currency=\"BRL\">BRL-IN-USD</NumeratorCurve>");
214 xml.append(
" <DenominatorCurve currency=\"EUR\">EUR-IN-USD</DenominatorCurve>");
215 xml.append(
"</DiscountRatio>");
227 BOOST_CHECK_EQUAL(seg.
typeID(),
"Discount Ratio");
229 BOOST_CHECK(seg.
quotes().empty());
252 BOOST_CHECK_EQUAL(newSeg.
typeID(),
"Discount Ratio");
254 BOOST_CHECK(newSeg.
quotes().empty());
264BOOST_AUTO_TEST_SUITE_END()
266BOOST_AUTO_TEST_SUITE_END()
Base Correlation curve configuration classes.
Cap floor volatility curve configuration class.
CDS and index CDS volatility configuration.
Container class for all Curve Configurations.
Discount ratio yield curve segment.
const string & baseCurveCurrency() const
const string & denominatorCurveCurrency() const
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
const string & numeratorCurveId() const
const string & numeratorCurveCurrency() const
const string & denominatorCurveId() const
const string & baseCurveId() const
static const string defaultConfiguration
Default configuration label.
Small XML Document wrapper class.
void appendNode(XMLNode *)
void fromXMLString(const string &xmlString)
load a document from a hard-coded string
XMLNode * getFirstNode(const string &name) const
void fromFile(const std::string &filename)
void toFile(const std::string &filename) const
const vector< pair< string, bool > > & quotes() const
const string & conventionsID() const
const string & typeID() const
utility class to access CSV files
Curve configuration repository.
Default curve configuration classes.
Equity curve configuration classes.
Equity volatility curve configuration classes.
security spread configuration classes
FX volatility curve configuration classes.
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.
security spread configuration classes
Swaption volatility curve configuration classes.
vector< string > curveConfigs
BOOST_DATA_TEST_CASE(testCurveConfigQuotesSimpleTodaysMarket, bdata::make(files), filePair)
BOOST_AUTO_TEST_CASE(testFromToXml)
Yield curve configuration classes.