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

#include <ored/portfolio/creditdefaultswapdata.hpp>

+ Inheritance diagram for CreditDefaultSwapData:
+ Collaboration diagram for CreditDefaultSwapData:

Public Types

using PPT = QuantLib::CreditDefaultSwap::ProtectionPaymentTime
 

Public Member Functions

 CreditDefaultSwapData ()
 Default constructor. More...
 
 CreditDefaultSwapData (const string &issuerId, const string &creditCurveId, const LegData &leg, const bool settlesAccrual=true, const PPT protectionPaymentTime=PPT::atDefault, const Date &protectionStart=Date(), const Date &upfrontDate=Date(), const Real upfrontFee=Null< Real >(), QuantLib::Real recoveryRate=QuantLib::Null< QuantLib::Real >(), const std::string &referenceObligation="", const Date &tradeDate=Date(), const std::string &cashSettlementDays="", const bool rebatesAccrual=true)
 Constructor that takes an explicit creditCurveId. More...
 
 CreditDefaultSwapData (const std::string &issuerId, const CdsReferenceInformation &referenceInformation, const LegData &leg, bool settlesAccrual=true, const PPT protectionPaymentTime=PPT::atDefault, const QuantLib::Date &protectionStart=QuantLib::Date(), const QuantLib::Date &upfrontDate=QuantLib::Date(), QuantLib::Real upfrontFee=QuantLib::Null< QuantLib::Real >(), QuantLib::Real recoveryRate=QuantLib::Null< QuantLib::Real >(), const std::string &referenceObligation="", const Date &tradeDate=Date(), const std::string &cashSettlementDays="", const bool rebatesAccrual=true)
 Constructor that takes a referenceInformation object. More...
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (XMLDocument &doc) const override
 
const string & issuerId () const
 
const string & creditCurveId () const
 
const LegDataleg () const
 
bool settlesAccrual () const
 
PPT protectionPaymentTime () const
 
const Date & protectionStart () const
 
const Date & upfrontDate () const
 
Real upfrontFee () const
 
bool rebatesAccrual () const
 
QuantLib::Real recoveryRate () const
 
const std::string & referenceObligation () const
 CDS Reference Obligation. More...
 
const QuantLib::Date & tradeDate () const
 
QuantLib::Natural cashSettlementDays () const
 
const boost::optional< CdsReferenceInformation > & referenceInformation () const
 
- 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...
 

Protected Member Functions

virtual void check (XMLNode *node) const
 
virtual XMLNodealloc (XMLDocument &doc) const
 

Private Attributes

std::string issuerId_
 
std::string creditCurveId_
 
LegData leg_
 
bool settlesAccrual_
 
PPT protectionPaymentTime_
 
QuantLib::Date protectionStart_
 
QuantLib::Date upfrontDate_
 
QuantLib::Real upfrontFee_
 
bool rebatesAccrual_
 
QuantLib::Real recoveryRate_
 Populated if the CDS is a fixed recovery rate CDS, otherwise Null<Real>() More...
 
std::string referenceObligation_
 
QuantLib::Date tradeDate_
 
std::string strCashSettlementDays_
 
QuantLib::Natural cashSettlementDays_
 
boost::optional< CdsReferenceInformationreferenceInformation_
 

Detailed Description

Serializable credit default swap data

Definition at line 133 of file creditdefaultswapdata.hpp.

Member Typedef Documentation

◆ PPT

using PPT = QuantLib::CreditDefaultSwap::ProtectionPaymentTime

Definition at line 138 of file creditdefaultswapdata.hpp.

Constructor & Destructor Documentation

◆ CreditDefaultSwapData() [1/3]

Default constructor.

Definition at line 486 of file creditdefaultswapdata.cpp.

487 : settlesAccrual_(true), protectionPaymentTime_(QuantExt::CreditDefaultSwap::ProtectionPaymentTime::atDefault),
488 upfrontFee_(Null<Real>()), rebatesAccrual_(true), recoveryRate_(Null<Real>()), cashSettlementDays_(3) {}
QuantLib::Real recoveryRate_
Populated if the CDS is a fixed recovery rate CDS, otherwise Null<Real>()

◆ CreditDefaultSwapData() [2/3]

CreditDefaultSwapData ( const string &  issuerId,
const string &  creditCurveId,
const LegData leg,
const bool  settlesAccrual = true,
const PPT  protectionPaymentTime = PPT::atDefault,
const Date &  protectionStart = Date(),
const Date &  upfrontDate = Date(),
const Real  upfrontFee = Null< Real >(),
QuantLib::Real  recoveryRate = QuantLib::Null< QuantLib::Real >(),
const std::string &  referenceObligation = "",
const Date &  tradeDate = Date(),
const std::string &  cashSettlementDays = "",
const bool  rebatesAccrual = true 
)

Constructor that takes an explicit creditCurveId.

◆ CreditDefaultSwapData() [3/3]

CreditDefaultSwapData ( const std::string &  issuerId,
const CdsReferenceInformation referenceInformation,
const LegData leg,
bool  settlesAccrual = true,
const PPT  protectionPaymentTime = PPT::atDefault,
const QuantLib::Date &  protectionStart = QuantLib::Date(),
const QuantLib::Date &  upfrontDate = QuantLib::Date(),
QuantLib::Real  upfrontFee = QuantLib::Null< QuantLib::Real >(),
QuantLib::Real  recoveryRate = QuantLib::Null< QuantLib::Real >(),
const std::string &  referenceObligation = "",
const Date &  tradeDate = Date(),
const std::string &  cashSettlementDays = "",
const bool  rebatesAccrual = true 
)

Constructor that takes a referenceInformation object.

Member Function Documentation

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Implements XMLSerializable.

Reimplemented in IndexCreditDefaultSwapData.

Definition at line 515 of file creditdefaultswapdata.cpp.

515 {
516
517 check(node);
518
519 issuerId_ = XMLUtils::getChildValue(node, "IssuerId", false);
520
521 // May get an explicit CreditCurveId node. If so, we use it. Otherwise, we must have ReferenceInformation node.
522 // XMLNode* tmp = XMLUtils::getChildNode(node, "CreditCurveId");
523 if (auto tmp = XMLUtils::getChildNode(node, "CreditCurveId")) {
525 CdsReferenceInformation ref;
528 } else {
529 tmp = XMLUtils::getChildNode(node, "ReferenceInformation");
530 QL_REQUIRE(tmp, "Need either a CreditCurveId or ReferenceInformation node in CreditDefaultSwapData");
531 CdsReferenceInformation ref;
532 ref.fromXML(tmp);
534 creditCurveId_ = ref.id();
535 }
536
537 settlesAccrual_ = XMLUtils::getChildValueAsBool(node, "SettlesAccrual", false);
538 rebatesAccrual_ = XMLUtils::getChildValueAsBool(node, "RebatesAccrual", false);
539
540 protectionPaymentTime_ = PPT::atDefault;
541
542 // for backwards compatibility only
543 if (auto c = XMLUtils::getChildNode(node, "PaysAtDefaultTime"))
545 protectionPaymentTime_ = PPT::atPeriodEnd;
546
547 // new node overrides deprecated one, if both should be given
548 if (auto c = XMLUtils::getChildNode(node, "ProtectionPaymentTime")) {
549 if (XMLUtils::getNodeValue(c) == "atDefault")
550 protectionPaymentTime_ = PPT::atDefault;
551 else if (XMLUtils::getNodeValue(c) == "atPeriodEnd")
552 protectionPaymentTime_ = PPT::atPeriodEnd;
553 else if (XMLUtils::getNodeValue(c) == "atMaturity")
554 protectionPaymentTime_ = PPT::atMaturity;
555 else {
556 QL_FAIL("protection payment time '" << XMLUtils::getNodeValue(c) <<
557 "' not known, expected atDefault, atPeriodEnd, atMaturity");
558 }
559 }
560
561 protectionStart_ = Date();
562 if (auto tmp = XMLUtils::getChildNode(node, "ProtectionStart"))
564
565 upfrontDate_ = Date();
566 if (auto tmp = XMLUtils::getChildNode(node, "UpfrontDate"))
568
569 // zero if empty or missing
570 upfrontFee_ = Null<Real>();
571 string strUpfrontFee = XMLUtils::getChildValue(node, "UpfrontFee", false);
572 if (!strUpfrontFee.empty()) {
573 upfrontFee_ = parseReal(strUpfrontFee);
574 }
575
576 if (upfrontDate_ == Date()) {
577 QL_REQUIRE(close_enough(upfrontFee_, 0.0) || upfrontFee_ == Null<Real>(),
578 "fromXML(): UpfronFee (" << upfrontFee_ << ") must be empty or zero if no upfront date is given");
579 upfrontFee_ = Null<Real>();
580 }
581
582 // Recovery rate is Null<Real>() on a standard CDS i.e. if "FixedRecoveryRate" field is not populated.
583 recoveryRate_ = Null<Real>();
584 string strRecoveryRate = XMLUtils::getChildValue(node, "FixedRecoveryRate", false);
585 if (!strRecoveryRate.empty()) {
586 recoveryRate_ = parseReal(strRecoveryRate);
587 }
588
589 tradeDate_ = Date();
590 if (auto n = XMLUtils::getChildNode(node, "TradeDate"))
592
593 strCashSettlementDays_ = XMLUtils::getChildValue(node, "CashSettlementDays", false);
595
596 leg_.fromXML(XMLUtils::getChildNode(node, "LegData"));
597}
boost::optional< CdsReferenceInformation > referenceInformation_
virtual void fromXML(XMLNode *node) override
Definition: legdata.cpp:759
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static bool getChildValueAsBool(XMLNode *node, const string &name, bool mandatory=false, bool defaultValue=true)
Definition: xmlutils.cpp:296
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
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
bool tryParseCdsInformation(string strInfo, CdsReferenceInformation &cdsInfo)
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Definition: parsers.cpp:136
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
+ 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 IndexCreditDefaultSwapData.

Definition at line 599 of file creditdefaultswapdata.cpp.

599 {
600
601 XMLNode* node = alloc(doc);
602
603 XMLUtils::addChild(doc, node, "IssuerId", issuerId_);
604
605 // We either have reference information or an explicit credit curve ID
608 } else {
609 XMLUtils::addChild(doc, node, "CreditCurveId", creditCurveId_);
610 }
611
612 XMLUtils::addChild(doc, node, "SettlesAccrual", settlesAccrual_);
613 if (!rebatesAccrual_)
614 XMLUtils::addChild(doc, node, "RebatesAccrual", rebatesAccrual_);
615 if (protectionPaymentTime_ == PPT::atDefault) {
616 XMLUtils::addChild(doc, node, "ProtectionPaymentTime", "atDefault");
617 } else if (protectionPaymentTime_ == PPT::atPeriodEnd) {
618 XMLUtils::addChild(doc, node, "ProtectionPaymentTime", "atPeriodEnd");
619 } else if (protectionPaymentTime_ == PPT::atMaturity) {
620 XMLUtils::addChild(doc, node, "ProtectionPaymentTime", "atMaturity");
621 } else {
622 QL_FAIL("toXML(): unexpected ProtectionPaymentTime");
623 }
624
625 if (protectionStart_ != Date()) {
626 XMLUtils::addChild(doc, node, "ProtectionStart", to_string(protectionStart_));
627 }
628
629 if (upfrontDate_ != Date()) {
630 XMLUtils::addChild(doc, node, "UpfrontDate", to_string(upfrontDate_));
631 }
632
633 if (upfrontFee_ != Null<Real>())
634 XMLUtils::addChild(doc, node, "UpfrontFee", upfrontFee_);
635
636 if (recoveryRate_ != Null<Real>())
637 XMLUtils::addChild(doc, node, "FixedRecoveryRate", recoveryRate_);
638
639 if (tradeDate_ != Date()) {
640 XMLUtils::addChild(doc, node, "TradeDate", to_string(tradeDate_));
641 }
642
643 if (!strCashSettlementDays_.empty()) {
644 XMLUtils::addChild(doc, node, "CashSettlementDays", strCashSettlementDays_);
645 }
646
647 XMLUtils::appendNode(node, leg_.toXML(doc));
648
649 return node;
650}
virtual XMLNode * alloc(XMLDocument &doc) const
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: legdata.cpp:856
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
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
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:

◆ issuerId()

const string & issuerId ( ) const

Definition at line 168 of file creditdefaultswapdata.hpp.

168{ return issuerId_; }
+ Here is the caller graph for this function:

◆ creditCurveId()

const string & creditCurveId ( ) const

Definition at line 652 of file creditdefaultswapdata.cpp.

652 {
654 return referenceInformation_->id();
655 } else {
656 return creditCurveId_;
657 }
658}
+ Here is the caller graph for this function:

◆ leg()

const LegData & leg ( ) const

Definition at line 170 of file creditdefaultswapdata.hpp.

170{ return leg_; }
+ Here is the caller graph for this function:

◆ settlesAccrual()

bool settlesAccrual ( ) const

Definition at line 171 of file creditdefaultswapdata.hpp.

171{ return settlesAccrual_; }
+ Here is the caller graph for this function:

◆ protectionPaymentTime()

PPT protectionPaymentTime ( ) const

Definition at line 172 of file creditdefaultswapdata.hpp.

172{ return protectionPaymentTime_; }
+ Here is the caller graph for this function:

◆ protectionStart()

const Date & protectionStart ( ) const

Definition at line 173 of file creditdefaultswapdata.hpp.

173{ return protectionStart_; }
+ Here is the caller graph for this function:

◆ upfrontDate()

const Date & upfrontDate ( ) const

Definition at line 174 of file creditdefaultswapdata.hpp.

174{ return upfrontDate_; }
+ Here is the caller graph for this function:

◆ upfrontFee()

Real upfrontFee ( ) const

Definition at line 175 of file creditdefaultswapdata.hpp.

175{ return upfrontFee_; }
+ Here is the caller graph for this function:

◆ rebatesAccrual()

bool rebatesAccrual ( ) const

Definition at line 176 of file creditdefaultswapdata.hpp.

176{ return rebatesAccrual_; }
+ Here is the caller graph for this function:

◆ recoveryRate()

QuantLib::Real recoveryRate ( ) const

If the CDS is a fixed recovery CDS, this returns the recovery rate. For a standard CDS, it returns Null<Real>().

Definition at line 181 of file creditdefaultswapdata.hpp.

181{ return recoveryRate_; }
+ Here is the caller graph for this function:

◆ referenceObligation()

const std::string & referenceObligation ( ) const

CDS Reference Obligation.

Definition at line 184 of file creditdefaultswapdata.hpp.

+ Here is the caller graph for this function:

◆ tradeDate()

const QuantLib::Date & tradeDate ( ) const

Definition at line 186 of file creditdefaultswapdata.hpp.

186{ return tradeDate_; }
+ Here is the caller graph for this function:

◆ cashSettlementDays()

QuantLib::Natural cashSettlementDays ( ) const

Definition at line 187 of file creditdefaultswapdata.hpp.

187{ return cashSettlementDays_; }
+ Here is the caller graph for this function:

◆ referenceInformation()

const boost::optional< CdsReferenceInformation > & referenceInformation ( ) const

CDS reference information. This will be empty if an explicit credit curve ID has been used.

Definition at line 191 of file creditdefaultswapdata.hpp.

191{ return referenceInformation_; }
+ Here is the caller graph for this function:

◆ check()

void check ( XMLNode node) const
protectedvirtual

Reimplemented in IndexCreditDefaultSwapData.

Definition at line 660 of file creditdefaultswapdata.cpp.

660 {
661 XMLUtils::checkNode(node, "CreditDefaultSwapData");
662}
static void checkNode(XMLNode *n, const string &expectedName)
Definition: xmlutils.cpp:175
+ Here is the call graph for this function:

◆ alloc()

XMLNode * alloc ( XMLDocument doc) const
protectedvirtual

Reimplemented in IndexCreditDefaultSwapData.

Definition at line 664 of file creditdefaultswapdata.cpp.

664 {
665 return doc.allocNode("CreditDefaultSwapData");
666}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ issuerId_

std::string issuerId_
private

Definition at line 198 of file creditdefaultswapdata.hpp.

◆ creditCurveId_

std::string creditCurveId_
private

Definition at line 199 of file creditdefaultswapdata.hpp.

◆ leg_

LegData leg_
private

Definition at line 200 of file creditdefaultswapdata.hpp.

◆ settlesAccrual_

bool settlesAccrual_
private

Definition at line 201 of file creditdefaultswapdata.hpp.

◆ protectionPaymentTime_

PPT protectionPaymentTime_
private

Definition at line 202 of file creditdefaultswapdata.hpp.

◆ protectionStart_

QuantLib::Date protectionStart_
private

Definition at line 203 of file creditdefaultswapdata.hpp.

◆ upfrontDate_

QuantLib::Date upfrontDate_
private

Definition at line 204 of file creditdefaultswapdata.hpp.

◆ upfrontFee_

QuantLib::Real upfrontFee_
private

Definition at line 205 of file creditdefaultswapdata.hpp.

◆ rebatesAccrual_

bool rebatesAccrual_
private

Definition at line 206 of file creditdefaultswapdata.hpp.

◆ recoveryRate_

QuantLib::Real recoveryRate_
private

Populated if the CDS is a fixed recovery rate CDS, otherwise Null<Real>()

Definition at line 209 of file creditdefaultswapdata.hpp.

◆ referenceObligation_

std::string referenceObligation_
private

Definition at line 211 of file creditdefaultswapdata.hpp.

◆ tradeDate_

QuantLib::Date tradeDate_
private

Definition at line 212 of file creditdefaultswapdata.hpp.

◆ strCashSettlementDays_

std::string strCashSettlementDays_
private

Definition at line 213 of file creditdefaultswapdata.hpp.

◆ cashSettlementDays_

QuantLib::Natural cashSettlementDays_
private

Definition at line 214 of file creditdefaultswapdata.hpp.

◆ referenceInformation_

boost::optional<CdsReferenceInformation> referenceInformation_
private

Definition at line 216 of file creditdefaultswapdata.hpp.