Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
creditdefaultswapdata.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file portfolio/creditdefaultswapdata.hpp
20 \brief A class to hold credit default swap data
21 \ingroup tradedata
22 */
23
24#pragma once
25
26#include <boost/optional.hpp>
29
30#include <ql/instruments/creditdefaultswap.hpp>
31
32namespace ore {
33namespace data {
34
35//! CDS debt tier enumeration
37CdsTier parseCdsTier(const std::string& s);
38std::ostream& operator<<(std::ostream& out, const CdsTier& cdsTier);
39
40//! CDS documentation clause enumeration
41enum class CdsDocClause { CR, MM, MR, XR, CR14, MM14, MR14, XR14 };
42CdsDocClause parseCdsDocClause(const std::string& s);
43std::ostream& operator<<(std::ostream& out, const CdsDocClause& cdsDocClause);
44
45// TODO refactor to creditevents.hpp
46//! ISDA CDS documentation rules set enumeration
47enum class IsdaRulesDefinitions { y2003 = 2003, y2014 = 2014 };
49std::ostream& operator<<(std::ostream& out, const CdsDocClause& cdsDocClause);
51
52//! ISDA credit event types enumeration
53enum class CreditEventType {
61};
62CreditEventType parseCreditEventType(const std::string& s);
63std::ostream& operator<<(std::ostream& out, const CreditEventType& creditEventType);
64bool isTriggeredDocClause(CdsDocClause contractDocClause, CreditEventType creditEventType);
65
66//! ISDA credit event seniority sets enumeration
68CreditEventTiers parseCreditEventTiers(const std::string& s);
69std::ostream& operator<<(std::ostream& out, const CreditEventTiers& creditEventTiers);
70bool isAuctionedSeniority(CdsTier contractTier, CreditEventTiers creditEventTiers);
71// end TODO refactor to creditevents.hpp
72
73/*! Serializable reference information
74 \ingroup tradedata
75*/
77public:
78 //! Default constructor
80
81 //! Detailed constructor
82 CdsReferenceInformation(const std::string& referenceEntityId, CdsTier tier, const QuantLib::Currency& currency,
83 boost::optional<CdsDocClause> docClause = boost::none);
84
85 //! \name XMLSerializable interface
86 //@{
87 void fromXML(XMLNode* node) override;
88 XMLNode* toXML(XMLDocument& doc) const override;
89 //@}
90
91 //! \name Inspectors
92 //@{
93 const std::string& referenceEntityId() const { return referenceEntityId_; }
94 CdsTier tier() const { return tier_; }
95 const QuantLib::Currency& currency() const { return currency_; }
96 bool hasDocClause() const;
97 CdsDocClause docClause() const;
98 //@}
99
100 /*! Give back the ID for the CdsReferenceInformation object. The id is the concatenation of the string
101 representation of the object's members using the \c | character as a delimiter.
102 */
103 const std::string& id() const { return id_; }
104
105private:
108 QuantLib::Currency currency_;
109 boost::optional<CdsDocClause> docClause_;
110 std::string id_;
111
112 //! Populate the \c id_ member
113 void populateId();
114};
115
116/*! Attempt to parse string to CdsReferenceInformation
117 \param[in] strInfo The string we wish to convert to CdsReferenceInformation
118 \param[out] cdsInfo The resulting CdsReferenceInformation if the parsing was successful.
119
120 \return \c true if the parsing was successful and \c false if not.
121
122 If the function receives a \p strInfo of the form `ID|TIER|CCY|DOCCLAUSE` with `CCY` being a valid ISO currency
123 code, `TIER` being a valid CDS debt tier and `DOCCLAUSE` being a valid CDS documentation clause, the parsing
124 should be successful. Here, DOCCLAUSE is optional.
125
126 \ingroup utilities
127*/
128bool tryParseCdsInformation(std::string strInfo, CdsReferenceInformation& cdsInfo);
129
130/*! Serializable credit default swap data
131 \ingroup tradedata
132*/
134public:
135 //! Default constructor
137
138 using PPT = QuantLib::CreditDefaultSwap::ProtectionPaymentTime;
139
140 //! Constructor that takes an explicit \p creditCurveId
141 CreditDefaultSwapData(const string& issuerId, const string& creditCurveId, const LegData& leg,
142 const bool settlesAccrual = true,
143 const PPT protectionPaymentTime = PPT::atDefault,
144 const Date& protectionStart = Date(), const Date& upfrontDate = Date(),
145 const Real upfrontFee = Null<Real>(),
146 QuantLib::Real recoveryRate = QuantLib::Null<QuantLib::Real>(),
147 const std::string& referenceObligation = "",
148 const Date& tradeDate = Date(),
149 const std::string& cashSettlementDays = "",
150 const bool rebatesAccrual = true);
151
152 //! Constructor that takes a \p referenceInformation object
154 const LegData& leg, bool settlesAccrual = true,
155 const PPT protectionPaymentTime = PPT::atDefault,
156 const QuantLib::Date& protectionStart = QuantLib::Date(),
157 const QuantLib::Date& upfrontDate = QuantLib::Date(),
158 QuantLib::Real upfrontFee = QuantLib::Null<QuantLib::Real>(),
159 QuantLib::Real recoveryRate = QuantLib::Null<QuantLib::Real>(),
160 const std::string& referenceObligation = "",
161 const Date& tradeDate = Date(),
162 const std::string& cashSettlementDays = "",
163 const bool rebatesAccrual = true);
164
165 void fromXML(XMLNode* node) override;
166 XMLNode* toXML(XMLDocument& doc) const override;
167
168 const string& issuerId() const { return issuerId_; }
169 const string& creditCurveId() const;
170 const LegData& leg() const { return leg_; }
171 bool settlesAccrual() const { return settlesAccrual_; }
173 const Date& protectionStart() const { return protectionStart_; }
174 const Date& upfrontDate() const { return upfrontDate_; }
175 Real upfrontFee() const { return upfrontFee_; }
176 bool rebatesAccrual() const { return rebatesAccrual_; }
177
178 /*! If the CDS is a fixed recovery CDS, this returns the recovery rate.
179 For a standard CDS, it returns Null<Real>().
180 */
181 QuantLib::Real recoveryRate() const { return recoveryRate_; }
182
183 //! CDS Reference Obligation
184 const std::string& referenceObligation() const { return referenceObligation_; }
185
186 const QuantLib::Date& tradeDate() const { return tradeDate_; }
187 QuantLib::Natural cashSettlementDays() const { return cashSettlementDays_; }
188
189 /*! CDS reference information. This will be empty if an explicit credit curve ID has been used.
190 */
191 const boost::optional<CdsReferenceInformation>& referenceInformation() const { return referenceInformation_; }
192
193protected:
194 virtual void check(XMLNode* node) const;
195 virtual XMLNode* alloc(XMLDocument& doc) const;
196
197private:
198 std::string issuerId_;
199 std::string creditCurveId_;
203 QuantLib::Date protectionStart_;
204 QuantLib::Date upfrontDate_;
205 QuantLib::Real upfrontFee_;
207
208 //! Populated if the CDS is a fixed recovery rate CDS, otherwise \c Null<Real>()
209 QuantLib::Real recoveryRate_;
210
212 QuantLib::Date tradeDate_;
214 QuantLib::Natural cashSettlementDays_;
215
216 boost::optional<CdsReferenceInformation> referenceInformation_;
217};
218
219} // namespace data
220} // namespace ore
boost::optional< CdsDocClause > docClause_
const std::string & referenceEntityId() const
CdsReferenceInformation(const std::string &referenceEntityId, CdsTier tier, const QuantLib::Currency &currency, boost::optional< CdsDocClause > docClause=boost::none)
Detailed constructor.
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
void populateId()
Populate the id_ member.
const QuantLib::Currency & currency() const
virtual XMLNode * alloc(XMLDocument &doc) const
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.
boost::optional< CdsReferenceInformation > referenceInformation_
const boost::optional< CdsReferenceInformation > & referenceInformation() const
QuantLib::Natural cashSettlementDays() const
QuantLib::Real recoveryRate_
Populated if the CDS is a fixed recovery rate CDS, otherwise Null<Real>()
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
const std::string & referenceObligation() const
CDS Reference Obligation.
const QuantLib::Date & tradeDate() const
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.
QuantLib::CreditDefaultSwap::ProtectionPaymentTime PPT
Serializable object holding leg data.
Definition: legdata.hpp:844
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
Base class for all serializable classes.
Definition: xmlutils.hpp:101
bool tryParseCdsInformation(string strInfo, CdsReferenceInformation &cdsInfo)
leg data model and serialization
@ data
Definition: log.hpp:77
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)
CdsTier parseCdsTier(const string &s)
CreditEventType
ISDA credit event types enumeration.
IsdaRulesDefinitions
ISDA CDS documentation rules set enumeration.
IsdaRulesDefinitions parseIsdaRulesDefinitions(const string &s)
bool isAuctionedSeniority(CdsTier contractTier, CreditEventTiers creditEventTiers)
Serializable Credit Default Swap.
Definition: namespaces.docs:23
base trade data model and serialization