Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
YieldCurveSegment Class Reference

Base class for yield curve segments. More...

#include <ored/configuration/yieldcurveconfig.hpp>

+ Inheritance diagram for YieldCurveSegment:
+ Collaboration diagram for YieldCurveSegment:

Public Types

enum class  Type {
  Zero , ZeroSpread , Discount , Deposit ,
  FRA , Future , OIS , Swap ,
  AverageOIS , TenorBasis , TenorBasisTwo , BMABasis ,
  FXForward , CrossCcyBasis , CrossCcyFixFloat , DiscountRatio ,
  FittedBond , WeightedAverage , YieldPlusDefault , IborFallback ,
  BondYieldShifted
}
 supported segment types More...
 

Public Member Functions

virtual ~YieldCurveSegment ()
 Default destructor. More...
 
Serialisation
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 
Inspectors
Type type () const
 
const string & typeID () const
 
const string & conventionsID () const
 
const QuantLib::Pillar::Choice pillarChoice () const
 
Size priority () const
 
Size minDistance () const
 
const vector< pair< string, bool > > & quotes () const
 
Visitability
virtual void accept (AcyclicVisitor &)
 
- Public Member Functions inherited from XMLSerializable
virtual ~XMLSerializable ()
 
virtual void fromXML (XMLNode *node)=0
 
virtual XMLNodetoXML (XMLDocument &doc) const =0
 
void fromFile (const std::string &filename)
 
void toFile (const std::string &filename) const
 
void fromXMLString (const std::string &xml)
 Parse from XML string. More...
 
std::string toXMLString () const
 Parse from XML string. More...
 

Constructors

vector< pair< string, bool > > quotes_
 Quote and optional flag pair. More...
 
Type type_
 
string typeID_
 
string conventionsID_
 
QuantLib::Pillar::Choice pillarChoice_ = QuantLib::Pillar::LastRelevantDate
 
Size priority_ = 0
 
Size minDistance_ = 1
 
 YieldCurveSegment ()
 Default constructor. More...
 
 YieldCurveSegment (const string &typeID, const string &conventionsID, const vector< string > &quotes)
 Detailed constructor - assumes all quotes are mandatory. More...
 
pair< string, boolquote (const string &name, bool opt=false)
 Utility to build a quote, optional flag defaults to false. More...
 

Detailed Description

Base class for yield curve segments.

Definition at line 58 of file yieldcurveconfig.hpp.

Member Enumeration Documentation

◆ Type

enum class Type
strong

supported segment types

Enumerator
Zero 
ZeroSpread 
Discount 
Deposit 
FRA 
Future 
OIS 
Swap 
AverageOIS 
TenorBasis 
TenorBasisTwo 
BMABasis 
FXForward 
CrossCcyBasis 
CrossCcyFixFloat 
DiscountRatio 
FittedBond 
WeightedAverage 
YieldPlusDefault 
IborFallback 
BondYieldShifted 

Definition at line 61 of file yieldcurveconfig.hpp.

61 {
62 Zero,
65 Deposit,
66 FRA,
67 Future,
68 OIS,
69 Swap,
83 };

Constructor & Destructor Documentation

◆ ~YieldCurveSegment()

virtual ~YieldCurveSegment ( )
virtual

Default destructor.

Definition at line 85 of file yieldcurveconfig.hpp.

85{}

◆ YieldCurveSegment() [1/2]

YieldCurveSegment ( )
protected

Default constructor.

Definition at line 114 of file yieldcurveconfig.hpp.

114{}

◆ YieldCurveSegment() [2/2]

YieldCurveSegment ( const string &  typeID,
const string &  conventionsID,
const vector< string > &  quotes 
)
protected

Detailed constructor - assumes all quotes are mandatory.

Definition at line 378 of file yieldcurveconfig.cpp.

381 for (auto q : quoteNames)
382 quotes_.emplace_back(quote(q));
383}
const string & conventionsID() const
vector< pair< string, bool > > quotes_
Quote and optional flag pair.
const string & typeID() const
pair< string, bool > quote(const string &name, bool opt=false)
Utility to build a quote, optional flag defaults to false.
YieldCurveSegment::Type parseYieldCurveSegment(const string &s)
+ Here is the call graph for this function:

Member Function Documentation

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Implements XMLSerializable.

Reimplemented in DirectYieldCurveSegment, SimpleYieldCurveSegment, AverageOISYieldCurveSegment, TenorBasisYieldCurveSegment, CrossCcyYieldCurveSegment, ZeroSpreadedYieldCurveSegment, WeightedAverageYieldCurveSegment, YieldPlusDefaultYieldCurveSegment, DiscountRatioYieldCurveSegment, FittedBondYieldCurveSegment, IborFallbackCurveSegment, and BondYieldShiftedYieldCurveSegment.

Definition at line 385 of file yieldcurveconfig.cpp.

385 {
386 typeID_ = XMLUtils::getChildValue(node, "Type", true);
387 string name = XMLUtils::getNodeName(node);
388
389 // Check if curve type is valid for the given segment name
390 std::map<std::string, std::list<std::string>> validSegmentTypes = {
391 {"Direct", {"Zero", "Discount"}},
392 {"Simple", {"Deposit", "FRA", "Future", "OIS", "Swap", "BMA Basis Swap"}},
393 {"AverageOIS", {"Average OIS"}},
394 {"TenorBasis", {"Tenor Basis Swap", "Tenor Basis Two Swaps"}},
395 {"CrossCurrency", {"FX Forward", "Cross Currency Basis Swap", "Cross Currency Fix Float Swap"}},
396 {"ZeroSpread", {"Zero Spread"}},
397 {"FittedBond", {"FittedBond"}},
398 {"YieldPlusDefault", {"Yield Plus Default"}},
399 {"WeightedAverage", {"Weighted Average"}},
400 {"DiscountRatio", {"Discount Ratio"}},
401 {"IborFallback", {"Ibor Fallback"}},
402 {"BondYieldShifted", {"Bond Yield Shifted"}}
403 };
404
405 std::list<std::string> validTypes = validSegmentTypes.at(name);
406 QL_REQUIRE(std::find(validTypes.begin(), validTypes.end(), typeID_) != validTypes.end(),
407 "The curve type " << typeID_ << " is not a valid " << name << " curve segment type");
408
409 quotes_.clear();
410 if (name == "AverageOIS") {
411 XMLNode* quotesNode = XMLUtils::getChildNode(node, "Quotes");
412 if (quotesNode) {
413 for (XMLNode* child = XMLUtils::getChildNode(quotesNode, "CompositeQuote"); child;
414 child = XMLUtils::getNextSibling(child)) {
415 quotes_.push_back(quote(XMLUtils::getChildValue(child, "RateQuote", true)));
416 quotes_.push_back(quote(XMLUtils::getChildValue(child, "SpreadQuote", true)));
417 }
418 } else {
419 QL_FAIL("No Quotes in segment. Remove segment or add quotes.");
420 }
421 } else {
422 XMLNode* quotesNode = XMLUtils::getChildNode(node, "Quotes");
423 if (quotesNode) {
424 for (auto n : XMLUtils::getChildrenNodes(quotesNode, "Quote")) {
425 string attr = XMLUtils::getAttribute(n, "optional"); // return "" if not present
426 bool opt = (!attr.empty() && parseBool(attr));
427 quotes_.emplace_back(quote(XMLUtils::getNodeValue(n), opt));
428 }
429 }
430 }
432 conventionsID_ = XMLUtils::getChildValue(node, "Conventions", false);
433 pillarChoice_ = parsePillarChoice(XMLUtils::getChildValue(node, "PillarChoice", false, "LastRelevantDate"));
434 QL_REQUIRE(pillarChoice_ == QuantLib::Pillar::MaturityDate || pillarChoice_ == QuantLib::Pillar::LastRelevantDate,
435 "PillarChoice " << pillarChoice_ << " not supported, expected MaturityDate, LastRelevantDate");
436 priority_ = XMLUtils::getChildValueAsInt(node, "Priority", false, 0);
437 minDistance_ = XMLUtils::getChildValueAsInt(node, "MinDistance", false, 1);
438}
static string getAttribute(XMLNode *node, const string &attrName)
Definition: xmlutils.cpp:419
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
static string getNodeName(XMLNode *n)
Get and set a node's name.
Definition: xmlutils.cpp:473
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static string getNodeValue(XMLNode *node)
Get a node's value.
Definition: xmlutils.cpp:489
static int getChildValueAsInt(XMLNode *node, const string &name, bool mandatory=false, int defaultValue=0)
Definition: xmlutils.cpp:291
static XMLNode * getNextSibling(XMLNode *node, const string &name="")
Get a node's next sibling node.
Definition: xmlutils.cpp:484
QuantLib::Pillar::Choice pillarChoice_
QuantLib::Pillar::Choice parsePillarChoice(const std::string &s)
Convert text to QuantLib::Pillar::Choice.
Definition: parsers.cpp:1403
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
string name
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Implements XMLSerializable.

Reimplemented in DirectYieldCurveSegment, SimpleYieldCurveSegment, AverageOISYieldCurveSegment, TenorBasisYieldCurveSegment, CrossCcyYieldCurveSegment, ZeroSpreadedYieldCurveSegment, WeightedAverageYieldCurveSegment, YieldPlusDefaultYieldCurveSegment, DiscountRatioYieldCurveSegment, FittedBondYieldCurveSegment, IborFallbackCurveSegment, and BondYieldShiftedYieldCurveSegment.

Definition at line 440 of file yieldcurveconfig.cpp.

440 {
441 XMLNode* node = doc.allocNode("Segment");
442 XMLUtils::addChild(doc, node, "Type", typeID_);
443 if (!quotes_.empty()) {
444 XMLNode* quotesNode = doc.allocNode("Quotes");
445 // Special case handling for AverageOIS where the quotes are stored as pairs
446 // Spread and Rate.
448 QL_REQUIRE(quotes_.size() % 2 == 0, "Invalid quotes vector should be even");
449 for (Size i = 0; i < quotes_.size(); i = i + 2) {
450 string rateQuote = quotes_[i].first;
451 string spreadQuote = quotes_[i + 1].first;
452
453 XMLNode* compositeQuoteNode = doc.allocNode("CompositeQuote");
454 XMLUtils::addChild(doc, compositeQuoteNode, "SpreadQuote", spreadQuote);
455 XMLUtils::addChild(doc, compositeQuoteNode, "RateQuote", rateQuote);
456 XMLUtils::appendNode(quotesNode, compositeQuoteNode);
457 }
458 } else {
459 for (auto q : quotes_) {
460 XMLNode* qNode = doc.allocNode("Quote", q.first);
461 if (q.second)
462 XMLUtils::addAttribute(doc, qNode, "optional", "true");
463 XMLUtils::appendNode(quotesNode, qNode);
464 }
465 }
466 XMLUtils::appendNode(node, quotesNode);
467 }
468
469 if (!conventionsID_.empty())
470 XMLUtils::addChild(doc, node, "Conventions", conventionsID_);
471 XMLUtils::addChild(doc, node, "PillarChoice", ore::data::to_string(pillarChoice_));
472 XMLUtils::addChild(doc, node, "Priority", (int)priority_);
473 XMLUtils::addChild(doc, node, "MinDistance", (int)minDistance_);
474 return node;
475}
static void addAttribute(XMLDocument &doc, XMLNode *node, const string &attrName, const string &attrValue)
Definition: xmlutils.cpp:412
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ type()

Type type ( ) const

Definition at line 95 of file yieldcurveconfig.hpp.

95{ return type_; }
+ Here is the caller graph for this function:

◆ typeID()

const string & typeID ( ) const

Definition at line 97 of file yieldcurveconfig.hpp.

97{ return typeID_; }
+ Here is the caller graph for this function:

◆ conventionsID()

const string & conventionsID ( ) const

Definition at line 98 of file yieldcurveconfig.hpp.

98{ return conventionsID_; }
+ Here is the caller graph for this function:

◆ pillarChoice()

const QuantLib::Pillar::Choice pillarChoice ( ) const

Definition at line 99 of file yieldcurveconfig.hpp.

99{ return pillarChoice_; }

◆ priority()

Size priority ( ) const

Definition at line 100 of file yieldcurveconfig.hpp.

100{ return priority_; }

◆ minDistance()

Size minDistance ( ) const

Definition at line 101 of file yieldcurveconfig.hpp.

101{ return minDistance_; }

◆ quotes()

const vector< pair< string, bool > > & quotes ( ) const

Definition at line 102 of file yieldcurveconfig.hpp.

102{ return quotes_; }
+ Here is the caller graph for this function:

◆ accept()

void accept ( AcyclicVisitor &  v)
virtual

Reimplemented in DirectYieldCurveSegment, SimpleYieldCurveSegment, AverageOISYieldCurveSegment, TenorBasisYieldCurveSegment, CrossCcyYieldCurveSegment, ZeroSpreadedYieldCurveSegment, WeightedAverageYieldCurveSegment, YieldPlusDefaultYieldCurveSegment, FittedBondYieldCurveSegment, IborFallbackCurveSegment, and BondYieldShiftedYieldCurveSegment.

Definition at line 477 of file yieldcurveconfig.cpp.

477 {
478 Visitor<YieldCurveSegment>* v1 = dynamic_cast<Visitor<YieldCurveSegment>*>(&v);
479 if (v1 != 0)
480 v1->visit(*this);
481 else
482 QL_FAIL("Not a YieldCurveSegment visitor.");
483}
+ Here is the caller graph for this function:

◆ quote()

pair< string, bool > quote ( const string &  name,
bool  opt = false 
)
protected

Utility to build a quote, optional flag defaults to false.

Definition at line 123 of file yieldcurveconfig.hpp.

123{ return make_pair(name, opt); }
+ Here is the caller graph for this function:

Member Data Documentation

◆ quotes_

vector<pair<string, bool> > quotes_
protected

Quote and optional flag pair.

Definition at line 120 of file yieldcurveconfig.hpp.

◆ type_

Type type_
private

Definition at line 127 of file yieldcurveconfig.hpp.

◆ typeID_

string typeID_
private

Definition at line 128 of file yieldcurveconfig.hpp.

◆ conventionsID_

string conventionsID_
private

Definition at line 129 of file yieldcurveconfig.hpp.

◆ pillarChoice_

QuantLib::Pillar::Choice pillarChoice_ = QuantLib::Pillar::LastRelevantDate
private

Definition at line 130 of file yieldcurveconfig.hpp.

◆ priority_

Size priority_ = 0
private

Definition at line 131 of file yieldcurveconfig.hpp.

◆ minDistance_

Size minDistance_ = 1
private

Definition at line 132 of file yieldcurveconfig.hpp.