Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Namespaces | Functions
curveconfig.cpp File Reference
#include <boost/algorithm/string.hpp>
#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <ored/configuration/basecorrelationcurveconfig.hpp>
#include <ored/configuration/capfloorvolcurveconfig.hpp>
#include <ored/configuration/cdsvolcurveconfig.hpp>
#include <ored/configuration/curveconfigurations.hpp>
#include <ored/configuration/defaultcurveconfig.hpp>
#include <ored/configuration/equitycurveconfig.hpp>
#include <ored/configuration/equityvolcurveconfig.hpp>
#include <ored/configuration/fxspotconfig.hpp>
#include <ored/configuration/fxvolcurveconfig.hpp>
#include <ored/configuration/inflationcurveconfig.hpp>
#include <ored/configuration/securityconfig.hpp>
#include <ored/configuration/swaptionvolcurveconfig.hpp>
#include <ored/configuration/yieldcurveconfig.hpp>
#include <ored/utilities/csvfilereader.hpp>
#include <ored/utilities/parsers.hpp>
#include <oret/datapaths.hpp>
#include <oret/fileutilities.hpp>
#include <oret/toplevelfixture.hpp>
#include <ql/time/calendar.hpp>
#include <ql/time/daycounter.hpp>

Go to the source code of this file.

Namespaces

namespace  boost
 
namespace  boost::test_tools
 
namespace  boost::test_tools::tt_detail
 

Functions

 BOOST_AUTO_TEST_CASE (testFromToXml)
 
 BOOST_AUTO_TEST_CASE (testCurveConfigQuotesAll)
 
 BOOST_DATA_TEST_CASE (testCurveConfigQuotesSimpleTodaysMarket, bdata::make(files), filePair)
 
 BOOST_AUTO_TEST_CASE (testCurveConfigQuotesTodaysMarketMultipleConfigs)
 
 BOOST_AUTO_TEST_CASE (testDiscountRatioSegmentFromXml)
 
 BOOST_AUTO_TEST_CASE (testDiscountRatioSegmentToXml)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/5]

BOOST_AUTO_TEST_CASE ( testFromToXml  )

Definition at line 120 of file curveconfig.cpp.

120 {
121
122 // Write the curve configurations to file
123 string outputFile_1 = TEST_OUTPUT_FILE("curve_config_out_1.xml");
124 curveConfigs.toFile(outputFile_1);
125
126 // Read curve configurations from output file
127 CurveConfigurations curveConfigsNew;
128 curveConfigsNew.fromFile(outputFile_1);
129 curveConfigsNew.parseAll();
130
131 // Write curve configurations to file again
132 string outputFile_2 = TEST_OUTPUT_FILE("curve_config_out_2.xml");
133 curveConfigsNew.toFile(outputFile_2);
134
135 // Compare contents of the output files
136 BOOST_CHECK(compareFiles(outputFile_1, outputFile_2));
137}
Container class for all Curve Configurations.
void fromFile(const std::string &filename)
Definition: xmlutils.cpp:150
void toFile(const std::string &filename) const
Definition: xmlutils.cpp:155
vector< string > curveConfigs
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/5]

BOOST_AUTO_TEST_CASE ( testCurveConfigQuotesAll  )

Definition at line 140 of file curveconfig.cpp.

140 {
141
142 // Ask the curve configurations object for all of its quotes
143 set<string> quotes = curveConfigs.quotes();
144
145 // Read the expected set of quotes from the file
146 set<string> expectedQuotes = readQuotes(TEST_INPUT_FILE("expected_quotes_all.csv"));
147
148 // Check that the quotes match the expected quotes
149 BOOST_REQUIRE_EQUAL(quotes.size(), expectedQuotes.size());
150 BOOST_CHECK_EQUAL_COLLECTIONS(quotes.begin(), quotes.end(), expectedQuotes.begin(), expectedQuotes.end());
151}

◆ BOOST_DATA_TEST_CASE()

BOOST_DATA_TEST_CASE ( testCurveConfigQuotesSimpleTodaysMarket  ,
bdata::make(files)  ,
filePair   
)

Definition at line 154 of file curveconfig.cpp.

154 {
155
156 BOOST_TEST_MESSAGE("Testing with todaysmarket file: " << filePair.first);
157
158 // Read the simple, single default configuration, TodaysMarketParameters instance from file
159 QuantLib::ext::shared_ptr<TodaysMarketParameters> tmp = QuantLib::ext::make_shared<TodaysMarketParameters>();
160 tmp->fromFile(TEST_INPUT_FILE(filePair.first));
161
162 // Ask the curve configurations object for its quotes, restricted by the TodaysMarketParameters instance
163 set<string> quotes = curveConfigs.quotes(tmp, {Market::defaultConfiguration});
164
165 // Read the expected set of quotes from the file
166 set<string> expectedQuotes = readQuotes(TEST_INPUT_FILE(filePair.second));
167
168 // Check that the quotes match the expected quotes
169 BOOST_REQUIRE_EQUAL(quotes.size(), expectedQuotes.size());
170 BOOST_CHECK_EQUAL_COLLECTIONS(quotes.begin(), quotes.end(), expectedQuotes.begin(), expectedQuotes.end());
171}
static const string defaultConfiguration
Default configuration label.
Definition: market.hpp:296

◆ BOOST_AUTO_TEST_CASE() [3/5]

BOOST_AUTO_TEST_CASE ( testCurveConfigQuotesTodaysMarketMultipleConfigs  )

Definition at line 174 of file curveconfig.cpp.

174 {
175
176 // Read the TodaysMarketParameters instance, containing multiple configurations, from file
177 QuantLib::ext::shared_ptr<TodaysMarketParameters> tmp = QuantLib::ext::make_shared<TodaysMarketParameters>();
178 tmp->fromFile(TEST_INPUT_FILE("todays_market_multiple_configs.xml"));
179
180 BOOST_REQUIRE_EQUAL(tmp->configurations().size(), 4);
181
182 // Check the quotes for each configuration in turn
183 for (const auto& kv : tmp->configurations()) {
184
185 BOOST_TEST_MESSAGE("Checking quotes for configuration: " << kv.first);
186
187 // Ask the curve configurations object for its quotes, restricted by the TodaysMarketParameters
188 // instance and the configuration
189 set<string> quotes = curveConfigs.quotes(tmp, {kv.first});
190
191 // Read the expected set of quotes from the file
192 set<string> expectedQuotes;
193 if (kv.first == "collateral_inccy") {
194 expectedQuotes = readQuotes(TEST_INPUT_FILE("expected_quotes_tmp_multiple_collateral_inccy.csv"));
195 } else {
196 expectedQuotes = readQuotes(TEST_INPUT_FILE("expected_quotes_tmp_multiple.csv"));
197 }
198
199 // Check that the quotes match the expected quotes
200 BOOST_REQUIRE_EQUAL(quotes.size(), expectedQuotes.size());
201 BOOST_CHECK_EQUAL_COLLECTIONS(quotes.begin(), quotes.end(), expectedQuotes.begin(), expectedQuotes.end());
202 }
203}

◆ BOOST_AUTO_TEST_CASE() [4/5]

BOOST_AUTO_TEST_CASE ( testDiscountRatioSegmentFromXml  )

Definition at line 206 of file curveconfig.cpp.

206 {
207
208 // XML string
209 string xml;
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>");
216
217 // XMLDocument from string
218 XMLDocument doc;
219 doc.fromXMLString(xml);
220
221 // Populate empty segment from XML node
223 seg.fromXML(doc.getFirstNode(""));
224
225 // Perform the checks
226 BOOST_CHECK(seg.type() == YieldCurveSegment::Type::DiscountRatio);
227 BOOST_CHECK_EQUAL(seg.typeID(), "Discount Ratio");
228 BOOST_CHECK_EQUAL(seg.conventionsID(), "");
229 BOOST_CHECK(seg.quotes().empty());
230
231 BOOST_CHECK_EQUAL(seg.baseCurveId(), "EUR1D");
232 BOOST_CHECK_EQUAL(seg.baseCurveCurrency(), "EUR");
233 BOOST_CHECK_EQUAL(seg.numeratorCurveId(), "BRL-IN-USD");
234 BOOST_CHECK_EQUAL(seg.numeratorCurveCurrency(), "BRL");
235 BOOST_CHECK_EQUAL(seg.denominatorCurveId(), "EUR-IN-USD");
236 BOOST_CHECK_EQUAL(seg.denominatorCurveCurrency(), "EUR");
237}
Discount ratio yield curve segment.
virtual void fromXML(XMLNode *node) 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
const vector< pair< string, bool > > & quotes() const
const string & conventionsID() const
const string & typeID() const
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/5]

BOOST_AUTO_TEST_CASE ( testDiscountRatioSegmentToXml  )

Definition at line 240 of file curveconfig.cpp.

240 {
241 // Create a discount ratio segment
242 DiscountRatioYieldCurveSegment seg("Discount Ratio", "EUR1D", "EUR", "BRL-IN-USD", "BRL", "EUR-IN-USD", "EUR");
243
244 // Create an XML document from the segment using toXML
245 XMLDocument doc;
246 doc.appendNode(seg.toXML(doc));
247
248 // Create new segment using fromXML and check entries
250 BOOST_CHECK_NO_THROW(newSeg.fromXML(doc.getFirstNode("")));
251 BOOST_CHECK(newSeg.type() == YieldCurveSegment::Type::DiscountRatio);
252 BOOST_CHECK_EQUAL(newSeg.typeID(), "Discount Ratio");
253 BOOST_CHECK_EQUAL(newSeg.conventionsID(), "");
254 BOOST_CHECK(newSeg.quotes().empty());
255
256 BOOST_CHECK_EQUAL(newSeg.baseCurveId(), "EUR1D");
257 BOOST_CHECK_EQUAL(newSeg.baseCurveCurrency(), "EUR");
258 BOOST_CHECK_EQUAL(newSeg.numeratorCurveId(), "BRL-IN-USD");
259 BOOST_CHECK_EQUAL(newSeg.numeratorCurveCurrency(), "BRL");
260 BOOST_CHECK_EQUAL(newSeg.denominatorCurveId(), "EUR-IN-USD");
261 BOOST_CHECK_EQUAL(newSeg.denominatorCurveCurrency(), "EUR");
262}
void appendNode(XMLNode *)
Definition: xmlutils.cpp:118
+ Here is the call graph for this function: