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

#include <ored/portfolio/creditlinkedswap.hpp>

+ Inheritance diagram for CreditLinkedSwap:
+ Collaboration diagram for CreditLinkedSwap:

Public Member Functions

 CreditLinkedSwap ()
 
 CreditLinkedSwap (const std::string &creditCurveId, const bool settlesAccrual, const Real fixedRecoveryRate, const QuantExt::CreditDefaultSwap::ProtectionPaymentTime &defaultPaymentTime, const std::vector< LegData > &independentPayments, const std::vector< LegData > &contingentPayments, const std::vector< LegData > &defaultPayments, const std::vector< LegData > &recoveryPayments)
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (ore::data::XMLDocument &doc) const override
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory) override
 
QuantLib::Real notional () const override
 Return the current notional in npvCurrency. See individual sub-classes for the precise definition. More...
 
- Public Member Functions inherited from Trade
 Trade ()
 Default constructor. More...
 
 Trade (const string &tradeType, const Envelope &env=Envelope(), const TradeActions &ta=TradeActions())
 Base class constructor. More...
 
virtual ~Trade ()
 Default destructor. More...
 
virtual void build (const QuantLib::ext::shared_ptr< EngineFactory > &)=0
 
virtual std::map< std::string, RequiredFixings::FixingDatesfixings (const QuantLib::Date &settlementDate=QuantLib::Date()) const
 
const RequiredFixingsrequiredFixings () const
 
virtual std::map< AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const
 
void reset ()
 Reset trade, clear all base class data. This does not reset accumulated timings for this trade. More...
 
void resetPricingStats (const std::size_t numberOfPricings=0, const boost::timer::nanosecond_type cumulativePricingTime=0)
 Reset accumulated timings to given values. More...
 
string & id ()
 Set the trade id. More...
 
void setEnvelope (const Envelope &envelope)
 Set the envelope with counterparty and portfolio info. More...
 
void setAdditionalData (const std::map< std::string, boost::any > &additionalData)
 
TradeActionstradeActions ()
 Set the trade actions. More...
 
const string & id () const
 
const string & tradeType () const
 
const Envelopeenvelope () const
 
const set< string > & portfolioIds () const
 
const TradeActionstradeActions () const
 
const QuantLib::ext::shared_ptr< InstrumentWrapper > & instrument () const
 
const std::vector< QuantLib::Leg > & legs () const
 
const std::vector< string > & legCurrencies () const
 
const std::vector< bool > & legPayers () const
 
const string & npvCurrency () const
 
virtual string notionalCurrency () const
 
const Date & maturity () const
 
virtual bool isExpired (const Date &d)
 
const string & issuer () const
 
template<typename T >
additionalDatum (const std::string &tag) const
 returns any additional datum. More...
 
virtual const std::map< std::string, boost::any > & additionalData () const
 returns all additional data returned by the trade once built More...
 
const std::string & sensitivityTemplate () const
 
void validate () const
 Utility to validate that everything that needs to be set in this base class is actually set. More...
 
virtual bool hasCashflows () const
 
boost::timer::nanosecond_type getCumulativePricingTime () const
 Get cumulative timing spent on pricing. More...
 
std::size_t getNumberOfPricings () const
 Get number of pricings. More...
 
- 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...
 

Private Attributes

std::string creditCurveId_
 
bool settlesAccrual_
 
double fixedRecoveryRate_
 
QuantExt::CreditDefaultSwap::ProtectionPaymentTime defaultPaymentTime_
 
std::vector< LegDataindependentPayments_
 
std::vector< LegDatacontingentPayments_
 
std::vector< LegDatadefaultPayments_
 
std::vector< LegDatarecoveryPayments_
 

Additional Inherited Members

- Protected Member Functions inherited from Trade
Date addPremiums (std::vector< QuantLib::ext::shared_ptr< Instrument > > &instruments, std::vector< Real > &multipliers, const Real tradeMultiplier, const PremiumData &premiumData, const Real premiumMultiplier, const Currency &tradeCurrency, const QuantLib::ext::shared_ptr< EngineFactory > &factory, const string &configuration)
 
void setLegBasedAdditionalData (const Size legNo, Size resultLegId=Null< Size >()) const
 
void setSensitivityTemplate (const EngineBuilder &builder)
 
void setSensitivityTemplate (const std::string &id)
 
- Protected Attributes inherited from Trade
string tradeType_
 
QuantLib::ext::shared_ptr< InstrumentWrapperinstrument_
 
std::vector< QuantLib::Leg > legs_
 
std::vector< string > legCurrencies_
 
std::vector< boollegPayers_
 
string npvCurrency_
 
QuantLib::Real notional_
 
string notionalCurrency_
 
Date maturity_
 
string issuer_
 
string sensitivityTemplate_
 
bool sensitivityTemplateSet_ = false
 
std::size_t savedNumberOfPricings_ = 0
 
boost::timer::nanosecond_type savedCumulativePricingTime_ = 0
 
RequiredFixings requiredFixings_
 
std::map< std::string, boost::any > additionalData_
 

Detailed Description

Definition at line 36 of file creditlinkedswap.hpp.

Constructor & Destructor Documentation

◆ CreditLinkedSwap() [1/2]

Definition at line 38 of file creditlinkedswap.hpp.

38: Trade("CreditLinkedSwap") {}
Trade()
Default constructor.
Definition: trade.hpp:59

◆ CreditLinkedSwap() [2/2]

CreditLinkedSwap ( const std::string &  creditCurveId,
const bool  settlesAccrual,
const Real  fixedRecoveryRate,
const QuantExt::CreditDefaultSwap::ProtectionPaymentTime &  defaultPaymentTime,
const std::vector< LegData > &  independentPayments,
const std::vector< LegData > &  contingentPayments,
const std::vector< LegData > &  defaultPayments,
const std::vector< LegData > &  recoveryPayments 
)

Definition at line 39 of file creditlinkedswap.hpp.

43 : Trade("CreditLinkedSwap"), creditCurveId_(creditCurveId), settlesAccrual_(settlesAccrual),
44 fixedRecoveryRate_(fixedRecoveryRate), defaultPaymentTime_(defaultPaymentTime),
45 independentPayments_(independentPayments), contingentPayments_(contingentPayments),
46 defaultPayments_(defaultPayments), recoveryPayments_(recoveryPayments) {}
QuantExt::CreditDefaultSwap::ProtectionPaymentTime defaultPaymentTime_
std::vector< LegData > contingentPayments_
std::vector< LegData > defaultPayments_
std::vector< LegData > recoveryPayments_
std::vector< LegData > independentPayments_

Member Function Documentation

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 31 of file creditlinkedswap.cpp.

31 {
32 Trade::fromXML(node);
33 XMLNode* n = XMLUtils::getChildNode(node, "CreditLinkedSwapData");
34 creditCurveId_ = XMLUtils::getChildValue(n, "CreditCurveId");
35 settlesAccrual_ = XMLUtils::getChildValueAsBool(n, "SettlesAccrual", false, true);
36 fixedRecoveryRate_ = XMLUtils::getChildValueAsDouble(n, "FixedRecoveryRate", false, Null<Real>());
37 defaultPaymentTime_ = QuantExt::CreditDefaultSwap::ProtectionPaymentTime::atDefault;
38 if (auto c = XMLUtils::getChildNode(n, "DefaultPaymentTime")) {
39 if (XMLUtils::getNodeValue(c) == "atDefault")
40 defaultPaymentTime_ = QuantExt::CreditDefaultSwap::ProtectionPaymentTime::atDefault;
41 else if (XMLUtils::getNodeValue(c) == "atPeriodEnd")
42 defaultPaymentTime_ = QuantExt::CreditDefaultSwap::ProtectionPaymentTime::atPeriodEnd;
43 else if (XMLUtils::getNodeValue(c) == "atMaturity")
44 defaultPaymentTime_ = QuantExt::CreditDefaultSwap::ProtectionPaymentTime::atMaturity;
45 else {
46 QL_FAIL("default payment time '" << XMLUtils::getNodeValue(c)
47 << "' not known, expected atDefault, atPeriodEnd, atMaturity");
48 }
49 }
50 if (auto tmp = XMLUtils::getChildNode(n, "IndependentPayments")) {
51 for (auto const& d : XMLUtils::getChildrenNodes(tmp, "LegData")) {
52 independentPayments_.push_back(LegData());
53 independentPayments_.back().fromXML(d);
54 }
55 }
56 if (auto tmp = XMLUtils::getChildNode(n, "ContingentPayments")) {
57 for (auto const& d : XMLUtils::getChildrenNodes(tmp, "LegData")) {
58 contingentPayments_.push_back(LegData());
59 contingentPayments_.back().fromXML(d);
60 }
61 }
62 if (auto tmp = XMLUtils::getChildNode(n, "DefaultPayments")) {
63 for (auto const& d : XMLUtils::getChildrenNodes(tmp, "LegData")) {
64 defaultPayments_.push_back(LegData());
65 defaultPayments_.back().fromXML(d);
66 }
67 }
68 if (auto tmp = XMLUtils::getChildNode(n, "RecoveryPayments")) {
69 for (auto const& d : XMLUtils::getChildrenNodes(tmp, "LegData")) {
70 recoveryPayments_.push_back(LegData());
71 recoveryPayments_.back().fromXML(d);
72 }
73 }
74}
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60

◆ toXML()

XMLNode * toXML ( ore::data::XMLDocument doc) const
overridevirtual

Reimplemented from Trade.

Definition at line 76 of file creditlinkedswap.cpp.

76 {
77 XMLNode* n = Trade::toXML(doc);
78 XMLNode* d = doc.allocNode("CreditLinkedSwapData");
79 XMLUtils::appendNode(n, d);
80 XMLUtils::addChild(doc, d, "CreditCurveId", creditCurveId_);
81 XMLUtils::addChild(doc, d, "SettlesAccrual", settlesAccrual_);
82 XMLUtils::addChild(doc, d, "FixedRecoveryRate", fixedRecoveryRate_);
83 if (defaultPaymentTime_ == QuantExt::CreditDefaultSwap::ProtectionPaymentTime::atDefault) {
84 XMLUtils::addChild(doc, d, "DefaultPaymentTime", "atDefault");
85 } else if (defaultPaymentTime_ == QuantExt::CreditDefaultSwap::ProtectionPaymentTime::atPeriodEnd) {
86 XMLUtils::addChild(doc, d, "DefaultPaymentTime", "atPeriodEnd");
87 } else if (defaultPaymentTime_ == QuantExt::CreditDefaultSwap::ProtectionPaymentTime::atMaturity) {
88 XMLUtils::addChild(doc, d, "DefaultPaymentTime", "atMaturity");
89 } else {
90 QL_FAIL("toXML(): unexpected DefaultPaymentTime");
91 }
92 XMLNode* d1 = doc.allocNode("IndependentPayments");
93 XMLUtils::appendNode(d, d1);
94 for (auto& l : independentPayments_) {
95 XMLUtils::appendNode(d1, l.toXML(doc));
96 }
97 XMLNode* d2 = doc.allocNode("ContingentPayments");
98 XMLUtils::appendNode(d, d2);
99 for (auto& l : contingentPayments_) {
100 XMLUtils::appendNode(d2, l.toXML(doc));
101 }
102 XMLNode* d3 = doc.allocNode("DefaultPayments");
103 XMLUtils::appendNode(d, d3);
104 for (auto& l : defaultPayments_) {
105 XMLUtils::appendNode(d3, l.toXML(doc));
106 }
107 XMLNode* d4 = doc.allocNode("RecoveryPayments");
108 XMLUtils::appendNode(d, d4);
109 for (auto& l : recoveryPayments_) {
110 XMLUtils::appendNode(d4, l.toXML(doc));
111 }
112 return n;
113}
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
+ Here is the call graph for this function:

◆ build()

void build ( const QuantLib::ext::shared_ptr< EngineFactory > &  )
overridevirtual

Build QuantLib/QuantExt instrument, link pricing engine. If build() is called multiple times, reset() should be called between these calls.

Implements Trade.

Definition at line 115 of file creditlinkedswap.cpp.

115 {
116
117 DLOG("Building credit linked swap " << id());
118
119 // ISDA taxonomy
120
121 additionalData_["isdaAssetClass"] = string("Interest Rate");
122 additionalData_["isdaBaseProduct"] = string("Exotic");
123 additionalData_["isdaSubProduct"] = string("");
124 additionalData_["isdaTransaction"] = string("");
125
126 // checks, set npv currency (= single currency allowed in all legs)
127
128 npvCurrency_.clear();
129 for (auto const& l : independentPayments_) {
130 QL_REQUIRE(npvCurrency_ == "" || l.currency() == npvCurrency_,
131 "CreditLinkedSwap: all leg currencies must be the same, found " << npvCurrency_ << " and "
132 << l.currency());
133 npvCurrency_ = l.currency();
134 }
135
136 // get engine builder
137
138 auto builder = QuantLib::ext::dynamic_pointer_cast<CreditLinkedSwapEngineBuilder>(engineFactory->builder(tradeType()));
139 QL_REQUIRE(builder, "CreditLinkedSwap: wrong builder, expected CreditLinkedSwapEngineBuilder");
140 auto configuration = builder->configuration(MarketContext::pricing);
141
142 // build underlying legs
143
144 std::vector<QuantExt::CreditLinkedSwap::LegType> legTypes;
145 for (auto const& l : independentPayments_) {
146 auto legBuilder = engineFactory->legBuilder(l.legType());
147 legs_.push_back(legBuilder->buildLeg(l, engineFactory, requiredFixings_, configuration));
148 legPayers_.push_back(l.isPayer());
149 legTypes.push_back(QuantExt::CreditLinkedSwap::LegType::IndependentPayments);
150 }
151 for (auto const& l : contingentPayments_) {
152 auto legBuilder = engineFactory->legBuilder(l.legType());
153 legs_.push_back(legBuilder->buildLeg(l, engineFactory, requiredFixings_, configuration));
154 legPayers_.push_back(l.isPayer());
155 legTypes.push_back(QuantExt::CreditLinkedSwap::LegType::ContingentPayments);
156 }
157 for (auto const& l : defaultPayments_) {
158 auto legBuilder = engineFactory->legBuilder(l.legType());
159 legs_.push_back(legBuilder->buildLeg(l, engineFactory, requiredFixings_, configuration));
160 legPayers_.push_back(l.isPayer());
161 legTypes.push_back(QuantExt::CreditLinkedSwap::LegType::DefaultPayments);
162 }
163 for (auto const& l : recoveryPayments_) {
164 auto legBuilder = engineFactory->legBuilder(l.legType());
165 legs_.push_back(legBuilder->buildLeg(l, engineFactory, requiredFixings_, configuration));
166 legPayers_.push_back(l.isPayer());
167 legTypes.push_back(QuantExt::CreditLinkedSwap::LegType::RecoveryPayments);
168 }
169
170 // build ql instrument
171
172 auto qlInstr =
173 QuantLib::ext::make_shared<QuantExt::CreditLinkedSwap>(legs_, legPayers_, legTypes, settlesAccrual_, fixedRecoveryRate_,
174 defaultPaymentTime_, parseCurrency(npvCurrency_));
175
176 // wrap instrument
177
178 instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(qlInstr);
179
180 // set trade members
181
183 legCurrencies_ = std::vector<std::string>(legs_.size(), npvCurrency_);
184 maturity_ = qlInstr->maturity();
185
186 // set pricing engine
187
188 qlInstr->setPricingEngine(builder->engine(npvCurrency_, creditCurveId_));
189 setSensitivityTemplate(*builder);
190
191 // log
192
193 DLOG("Finished building credit linked swap " << id());
194 DLOG("Currency : " << npvCurrency_);
195 DLOG("IndependentPayments legs: " << independentPayments_.size());
196 DLOG("ContingentPayments legs: " << contingentPayments_.size());
197 DLOG("DefaultPayments legs: " << defaultPayments_.size());
198 DLOG("RecoveryPayments legs: " << recoveryPayments_.size());
199}
std::vector< bool > legPayers_
std::vector< Leg > legs_
string npvCurrency_
Definition: trade.hpp:201
std::vector< string > legCurrencies_
Definition: trade.hpp:199
void setSensitivityTemplate(const EngineBuilder &builder)
Definition: trade.cpp:295
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
Definition: trade.hpp:197
string notionalCurrency_
Definition: trade.hpp:203
const string & tradeType() const
Definition: trade.hpp:133
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:290
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
+ Here is the call graph for this function:

◆ notional()

QuantLib::Real notional ( ) const
overridevirtual

Return the current notional in npvCurrency. See individual sub-classes for the precise definition.

Reimplemented from Trade.

Definition at line 201 of file creditlinkedswap.cpp.

201 {
202 Real notional = 0.0;
203 for (auto const& l : legs_)
204 notional = std::max(notional, currentNotional(l));
205 return notional;
206}
QuantLib::Real notional() const override
Return the current notional in npvCurrency. See individual sub-classes for the precise definition.
Real currentNotional(const Leg &leg)
Definition: legdata.cpp:2435
+ Here is the call graph for this function:

Member Data Documentation

◆ creditCurveId_

std::string creditCurveId_
private

Definition at line 56 of file creditlinkedswap.hpp.

◆ settlesAccrual_

bool settlesAccrual_
private

Definition at line 57 of file creditlinkedswap.hpp.

◆ fixedRecoveryRate_

double fixedRecoveryRate_
private

Definition at line 58 of file creditlinkedswap.hpp.

◆ defaultPaymentTime_

QuantExt::CreditDefaultSwap::ProtectionPaymentTime defaultPaymentTime_
private

Definition at line 59 of file creditlinkedswap.hpp.

◆ independentPayments_

std::vector<LegData> independentPayments_
private

Definition at line 60 of file creditlinkedswap.hpp.

◆ contingentPayments_

std::vector<LegData> contingentPayments_
private

Definition at line 61 of file creditlinkedswap.hpp.

◆ defaultPayments_

std::vector<LegData> defaultPayments_
private

Definition at line 62 of file creditlinkedswap.hpp.

◆ recoveryPayments_

std::vector<LegData> recoveryPayments_
private

Definition at line 63 of file creditlinkedswap.hpp.