19#include <boost/lexical_cast.hpp>
36 }
else if (s ==
"SUBLT2") {
38 }
else if (s ==
"SNRLAC") {
40 }
else if (s ==
"SECDOM") {
42 }
else if (s ==
"JRSUBUT2") {
44 }
else if (s ==
"PREFT1") {
46 }
else if (s ==
"LIEN1") {
48 }
else if (s ==
"LIEN2") {
50 }
else if (s ==
"LIEN3") {
53 QL_FAIL(
"Could not parse \"" << s <<
"\" to CdsTier");
59 return out <<
"SNRFOR";
61 return out <<
"SUBLT2";
63 return out <<
"SNRLAC";
65 return out <<
"SECDOM";
67 return out <<
"JRSUBUT2";
69 return out <<
"PREFT1";
71 return out <<
"LIEN1";
73 return out <<
"LIEN2";
75 return out <<
"LIEN3";
77 QL_FAIL(
"Do not recognise CdsTier " <<
static_cast<int>(cdsTier));
84 }
else if (s ==
"MM") {
86 }
else if (s ==
"MR") {
88 }
else if (s ==
"XR") {
90 }
else if (s ==
"CR14") {
92 }
else if (s ==
"MM14") {
94 }
else if (s ==
"MR14") {
96 }
else if (s ==
"XR14") {
99 QL_FAIL(
"Could not parse \"" << s <<
"\" to CdsDocClause");
104 switch (cdsDocClause) {
114 return out <<
"CR14";
116 return out <<
"MM14";
118 return out <<
"MR14";
120 return out <<
"XR14";
122 QL_FAIL(
"Do not recognise CdsDocClause " <<
static_cast<int>(cdsDocClause));
130 }
else if (s ==
"2014") {
133 QL_FAIL(
"Could not parse \"" << s <<
"\" to isdaRulesDefinitions");
138 switch (isdaRulesDefinitions) {
140 return out <<
"2003";
142 return out <<
"2014";
144 QL_FAIL(
"Do not recognise IsdaRulesDefinitions " <<
static_cast<int>(isdaRulesDefinitions));
149 switch (cdsDocClause) {
165 if (s ==
"BANKRUPTCY") {
167 }
else if (s ==
"FAILURE TO PAY") {
169 }
else if (s ==
"RESTRUCTURING") {
171 }
else if (s ==
"OBLIGATION ACCELERATION") {
173 }
else if (s ==
"OBLIGATION DEFAULT") {
175 }
else if (s ==
"REPUDIATION/MORATORIUM") {
177 }
else if (s ==
"GOVERNMENTAL INTERVENTION") {
180 QL_FAIL(
"Could not parse \"" << s <<
"\" to a credit event.");
185 switch (creditEventType) {
187 return out <<
"BANKRUPTCY";
189 return out <<
"FAILURE TO PAY";
191 return out <<
"RESTRUCTURING";
193 return out <<
"OBLIGATION ACCELERATION";
195 return out <<
"OBLIGATION DEFAULT";
197 return out <<
"REPUDIATION/MORATORIUM";
199 return out <<
"GOVERNMENTAL INTERVENTION";
201 QL_FAIL(
"Do not recognise CreditEventType " <<
static_cast<int>(creditEventType));
206 switch (creditEventType) {
211 switch (contractDocClause) {
229 switch (contractDocClause) {
251 QL_FAIL(
"Could not recognize CreditEventType "
252 <<
static_cast<int>(creditEventType) <<
" or CdsDocClause " <<
static_cast<int>(contractDocClause)
253 <<
" when identifying whether a doc clause is triggrered for a given credit event type.");
260 }
else if (s ==
"SUB") {
262 }
else if (s ==
"SNRLAC") {
264 }
else if (s ==
"SNR/SUB") {
266 }
else if (s ==
"SNR/SNRLAC") {
268 }
else if (s ==
"SUB/SNRLAC") {
270 }
else if (s ==
"SNR/SUB/SNRLAC") {
273 QL_FAIL(
"Could not parse \"" << s <<
"\" to a credit event tiers set.");
278 switch (creditEventTiers) {
284 return out <<
"SNRLAC";
286 return out <<
"SNR/SUB";
288 return out <<
"SNR/SNRLAC";
290 return out <<
"SUB/SNRLAC";
292 return out <<
"SNR/SUB/SNRLAC";
294 QL_FAIL(
"Do not recognise CreditEventTiers " <<
static_cast<int>(creditEventTiers));
299 switch (creditEventTiers) {
301 switch (contractTier) {
315 switch (contractTier) {
329 switch (contractTier) {
343 switch (contractTier) {
357 switch (contractTier) {
371 switch (contractTier) {
385 switch (contractTier) {
400 QL_FAIL(
"Could not recognize CreditEventTiers "
401 <<
static_cast<int>(creditEventTiers) <<
" or CdsTier " <<
static_cast<int>(contractTier)
402 <<
" when identifying the applicability if an event for a given contract tier.");
410 const Currency& currency, boost::optional<CdsDocClause> docClause)
411 : referenceEntityId_(referenceEntityId), tier_(tier), currency_(currency), docClause_(docClause) {
443 QL_REQUIRE(
docClause_,
"CdsReferenceInforamtion::docClause(): docClause not set.");
451 DLOG(
"tryParseCdsInformation: attempting to parse " << strInfo);
454 vector<string> tokens;
455 boost::split(tokens, strInfo, boost::is_any_of(
"|"));
457 if (tokens.size() != 4 && tokens.size() != 3) {
458 TLOG(
"String " << strInfo <<
" not of form ID|TIER|CCY(|DOCCLAUSE) so parsing failed");
463 if (!tryParse<CdsTier>(tokens[1], cdsTier, &
parseCdsTier)) {
472 boost::optional<CdsDocClause> cdsDocClause;
473 if (tokens.size() == 4) {
488 upfrontFee_(Null<Real>()), rebatesAccrual_(true), recoveryRate_(Null<Real>()), cashSettlementDays_(3) {}
491 const bool settlesAccrual,
const PPT protectionPaymentTime,
492 const Date& protectionStart,
const Date& upfrontDate,
const Real upfrontFee, Real recoveryRate,
493 const string& referenceObligation,
const Date& tradeDate,
const string& cashSettlementDays,
494 const bool rebatesAccrual)
495 : issuerId_(issuerId), creditCurveId_(creditCurveId), leg_(leg), settlesAccrual_(settlesAccrual),
496 protectionPaymentTime_(protectionPaymentTime), protectionStart_(protectionStart), upfrontDate_(upfrontDate),
497 upfrontFee_(upfrontFee), rebatesAccrual_(rebatesAccrual), recoveryRate_(recoveryRate),
498 referenceObligation_(referenceObligation),
499 tradeDate_(tradeDate), strCashSettlementDays_(cashSettlementDays),
500 cashSettlementDays_(strCashSettlementDays_.empty() ? 3 :
parseInteger(strCashSettlementDays_)) {}
504 bool settlesAccrual,
const PPT protectionPaymentTime,
505 const Date& protectionStart,
const Date& upfrontDate, Real upfrontFee, Real recoveryRate,
506 const std::string& referenceObligation,
const Date& tradeDate,
const string& cashSettlementDays,
507 const bool rebatesAccrual)
508 : issuerId_(issuerId), leg_(leg), settlesAccrual_(settlesAccrual), protectionPaymentTime_(protectionPaymentTime),
509 protectionStart_(protectionStart), upfrontDate_(upfrontDate), upfrontFee_(upfrontFee), rebatesAccrual_(rebatesAccrual),
510 recoveryRate_(recoveryRate), referenceObligation_(referenceObligation),
511 tradeDate_(tradeDate), strCashSettlementDays_(cashSettlementDays),
512 cashSettlementDays_(strCashSettlementDays_.empty() ? 3 :
parseInteger(strCashSettlementDays_)),
513 referenceInformation_(referenceInformation) {}
530 QL_REQUIRE(tmp,
"Need either a CreditCurveId or ReferenceInformation node in CreditDefaultSwapData");
557 "' not known, expected atDefault, atPeriodEnd, atMaturity");
572 if (!strUpfrontFee.empty()) {
578 "fromXML(): UpfronFee (" <<
upfrontFee_ <<
") must be empty or zero if no upfront date is given");
585 if (!strRecoveryRate.empty()) {
622 QL_FAIL(
"toXML(): unexpected ProtectionPaymentTime");
665 return doc.
allocNode(
"CreditDefaultSwapData");
QuantLib::Real upfrontFee_
QuantLib::Date protectionStart_
virtual XMLNode * alloc(XMLDocument &doc) const
boost::optional< CdsReferenceInformation > referenceInformation_
std::string creditCurveId_
QuantLib::Real recoveryRate_
Populated if the CDS is a fixed recovery rate CDS, otherwise Null<Real>()
void fromXML(XMLNode *node) override
PPT protectionPaymentTime_
std::string strCashSettlementDays_
XMLNode * toXML(XMLDocument &doc) const override
QuantLib::Natural cashSettlementDays_
CreditDefaultSwapData()
Default constructor.
QuantLib::Date upfrontDate_
QuantLib::Date tradeDate_
virtual void check(XMLNode *node) const
const string & creditCurveId() const
Serializable object holding leg data.
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
Small XML Document wrapper class.
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
static void checkNode(XMLNode *n, const string &expectedName)
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
static bool getChildValueAsBool(XMLNode *node, const string &name, bool mandatory=false, bool defaultValue=true)
static XMLNode * getChildNode(XMLNode *n, const string &name="")
static string getNodeValue(XMLNode *node)
Get a node's value.
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
static void appendNode(XMLNode *parent, XMLNode *child)
A class to hold credit default swap data.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
bool parseBool(const string &s)
Convert text to bool.
Real parseReal(const string &s)
Convert text to Real.
bool tryParseCdsInformation(string strInfo, CdsReferenceInformation &cdsInfo)
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
leg data model and serialization
Classes and functions for log message handling.
#define DLOG(text)
Logging Macro (Level = Debug)
#define TLOG(text)
Logging Macro (Level = Data)
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
CreditEventTiers parseCreditEventTiers(const string &s)
CdsDocClause
CDS documentation clause enumeration.
CreditEventType parseCreditEventType(const string &s)
bool isTriggeredDocClause(CdsDocClause contractDocClause, CreditEventType creditEventType)
CreditEventTiers
ISDA credit event seniority sets enumeration.
IsdaRulesDefinitions isdaRulesDefinitionsFromDocClause(const CdsDocClause &cdsDocClause)
CdsTier
CDS debt tier enumeration.
CdsDocClause parseCdsDocClause(const string &s)
bool tryParseCurrency(const std::string &str, Currency &obj)
CdsTier parseCdsTier(const string &s)
std::string to_string(const LocationInfo &l)
CreditEventType
ISDA credit event types enumeration.
@ OBLIGATION_ACCELERATION
@ GOVERNMENTAL_INTERVENTION
IsdaRulesDefinitions
ISDA CDS documentation rules set enumeration.
IsdaRulesDefinitions parseIsdaRulesDefinitions(const string &s)
bool isAuctionedSeniority(CdsTier contractTier, CreditEventTiers creditEventTiers)
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.
string conversion utilities