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

#include <ored/portfolio/creditdefaultswapoption.hpp>

+ Inheritance diagram for CreditDefaultSwapOption:
+ Collaboration diagram for CreditDefaultSwapOption:

Classes

class  AuctionSettlementInformation
 

Public Member Functions

 CreditDefaultSwapOption ()
 Default constructor. More...
 
 CreditDefaultSwapOption (const Envelope &env, const OptionData &option, const CreditDefaultSwapData &swap, QuantLib::Real strike=QuantLib::Null< QuantLib::Real >(), const std::string &strikeType="Spread", bool knockOut=true, const std::string &term="", const boost::optional< AuctionSettlementInformation > &asi=boost::none)
 Constructor. More...
 
Trade interface
void build (const QuantLib::ext::shared_ptr< EngineFactory > &ef) override
 
Inspectors
const OptionDataoption () const
 
const CreditDefaultSwapDataswap () const
 
QuantLib::Real strike () const
 
const std::string & strikeType () const
 
bool knockOut () const
 
const std::string & term () const
 
const boost::optional< AuctionSettlementInformation > & auctionSettlementInformation () const
 
- 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 QuantLib::Real notional () const
 Return the current notional in npvCurrency. See individual sub-classes for the precise definition. More...
 
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...
 

Serialisation

OptionData option_
 
CreditDefaultSwapData swap_
 
QuantLib::Real strike_
 
std::string strikeType_
 
bool knockOut_
 
std::string term_
 
boost::optional< AuctionSettlementInformationasi_
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (XMLDocument &doc) const override
 
void buildNoDefault (const QuantLib::ext::shared_ptr< EngineFactory > &ef)
 Build CDS option given that no default. More...
 
void buildDefaulted (const QuantLib::ext::shared_ptr< EngineFactory > &ef)
 Build instrument given that default has occurred. More...
 
Date addPremium (const QuantLib::ext::shared_ptr< EngineFactory > &ef, const QuantLib::Currency &tradeCurrency, const std::string &marketConfig, std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > &additionalInstruments, std::vector< QuantLib::Real > &additionalMultipliers)
 Add the premium payment. More...
 

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 creditdefaultswapoption.hpp.

Constructor & Destructor Documentation

◆ CreditDefaultSwapOption() [1/2]

Default constructor.

Definition at line 62 of file creditdefaultswapoption.cpp.

63 : Trade("CreditDefaultSwapOption"), strike_(Null<Real>()), knockOut_(true) {}
Trade()
Default constructor.
Definition: trade.hpp:59

◆ CreditDefaultSwapOption() [2/2]

CreditDefaultSwapOption ( const Envelope env,
const OptionData option,
const CreditDefaultSwapData swap,
QuantLib::Real  strike = QuantLib::Null< QuantLib::Real >(),
const std::string &  strikeType = "Spread",
bool  knockOut = true,
const std::string &  term = "",
const boost::optional< AuctionSettlementInformation > &  asi = boost::none 
)

Constructor.

Member Function Documentation

◆ 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 76 of file creditdefaultswapoption.cpp.

76 {
77
78 DLOG("CreditDefaultSwapOption::build() called for trade " << id());
79
80 // ISDA taxonomy
81 additionalData_["isdaAssetClass"] = string("Credit");
82 additionalData_["isdaBaseProduct"] = string("Swaptions");
83 // set isdaSubProduct to entityType in credit reference data
84 additionalData_["isdaSubProduct"] = string("");
85 string entity =
87 QuantLib::ext::shared_ptr<ReferenceDataManager> refData = engineFactory->referenceData();
88 if (refData && refData->hasData("Credit", entity)) {
89 auto refDatum = refData->getData("Credit", entity);
90 QuantLib::ext::shared_ptr<CreditReferenceDatum> creditRefDatum =
91 QuantLib::ext::dynamic_pointer_cast<CreditReferenceDatum>(refDatum);
92 additionalData_["isdaSubProduct"] = creditRefDatum->creditData().entityType;
93 if (creditRefDatum->creditData().entityType == "") {
94 ALOG("EntityType is blank in credit reference data for entity " << entity);
95 }
96 } else {
97 ALOG("Credit reference data missing for entity " << entity << ", isdaSubProduct left blank");
98 }
99 // Skip the transaction level mapping for now
100 additionalData_["isdaTransaction"] = string("");
101
102 // Notionals
103 const auto& legData = swap_.leg();
104 const auto& ntls = legData.notionals();
105 QL_REQUIRE(ntls.size() == 1, "CreditDefaultSwapOption requires a single notional.");
106 notional_ = ntls.front();
107 notionalCurrency_ = legData.currency();
108
109 // Type of instrument we build depends on whether the reference entity has already defaulted.
110 if (asi_) {
111 buildDefaulted(engineFactory);
112 } else {
113 buildNoDefault(engineFactory);
114 }
115}
const boost::optional< CdsReferenceInformation > & referenceInformation() const
void buildDefaulted(const QuantLib::ext::shared_ptr< EngineFactory > &ef)
Build instrument given that default has occurred.
boost::optional< AuctionSettlementInformation > asi_
void buildNoDefault(const QuantLib::ext::shared_ptr< EngineFactory > &ef)
Build CDS option given that no default.
const vector< double > & notionals() const
Definition: legdata.hpp:875
QuantLib::Real notional_
Definition: trade.hpp:202
string notionalCurrency_
Definition: trade.hpp:203
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
#define ALOG(text)
Logging Macro (Level = Alert)
Definition: log.hpp:544
+ Here is the call graph for this function:

◆ option()

const OptionData & option ( ) const

Definition at line 117 of file creditdefaultswapoption.cpp.

117 {
118 return option_;
119}

◆ swap()

const CreditDefaultSwapData & swap ( ) const

Definition at line 121 of file creditdefaultswapoption.cpp.

121 {
122 return swap_;
123}

◆ strike()

Real strike ( ) const

Definition at line 125 of file creditdefaultswapoption.cpp.

125 {
126 return strike_;
127}
+ Here is the caller graph for this function:

◆ strikeType()

const string & strikeType ( ) const

Definition at line 129 of file creditdefaultswapoption.cpp.

129 {
130 return strikeType_;
131}
+ Here is the caller graph for this function:

◆ knockOut()

bool knockOut ( ) const

Definition at line 133 of file creditdefaultswapoption.cpp.

133 {
134 return knockOut_;
135}

◆ term()

const string & term ( ) const

Definition at line 137 of file creditdefaultswapoption.cpp.

137 {
138 return term_;
139}

◆ auctionSettlementInformation()

const boost::optional< ASI > & auctionSettlementInformation ( ) const

Definition at line 142 of file creditdefaultswapoption.cpp.

142 {
143 return asi_;
144}

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 146 of file creditdefaultswapoption.cpp.

146 {
147
148 Trade::fromXML(node);
149
150 XMLNode* cdsOptionData = XMLUtils::getChildNode(node, "CreditDefaultSwapOptionData");
151 QL_REQUIRE(cdsOptionData, "Expected CreditDefaultSwapOptionData node on trade " << id() << ".");
152 strike_ = XMLUtils::getChildValueAsDouble(cdsOptionData, "Strike", false, Null<Real>());
153 strikeType_ = "Spread";
154 if (auto n = XMLUtils::getChildNode(cdsOptionData, "StrikeType")) {
156 }
157 knockOut_ = XMLUtils::getChildValueAsBool(cdsOptionData, "KnockOut", false, true);
158 term_ = XMLUtils::getChildValue(cdsOptionData, "Term", false);
159
160 if (XMLNode* asiNode = XMLUtils::getChildNode(cdsOptionData, "AuctionSettlementInformation"))
161 asi_->fromXML(asiNode);
162
163 XMLNode* cdsData = XMLUtils::getChildNode(cdsOptionData, "CreditDefaultSwapData");
164 QL_REQUIRE(cdsData, "Expected CreditDefaultSwapData node on trade " << id() << ".");
165 swap_.fromXML(cdsData);
166
167 XMLNode* optionData = XMLUtils::getChildNode(cdsOptionData, "OptionData");
168 QL_REQUIRE(optionData, "Expected OptionData node on trade " << id() << ".");
169 option_.fromXML(optionData);
170}
void fromXML(XMLNode *node) override
virtual void fromXML(XMLNode *node) override
Definition: optiondata.cpp:32
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
Definition: xmlutils.cpp:286
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
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Reimplemented from Trade.

Definition at line 172 of file creditdefaultswapoption.cpp.

172 {
173
174 // Trade node
175 XMLNode* node = Trade::toXML(doc);
176
177 // CreditDefaultSwapOptionData node
178 XMLNode* cdsOptionDataNode = doc.allocNode("CreditDefaultSwapOptionData");
179 if (strike_ != Null<Real>())
180 XMLUtils::addChild(doc, cdsOptionDataNode, "Strike", strike_);
181 if (strikeType_ != "")
182 XMLUtils::addChild(doc, cdsOptionDataNode, "StrikeType", strikeType_);
183 XMLUtils::addChild(doc, cdsOptionDataNode, "KnockOut", knockOut_);
184 if (!term_.empty())
185 XMLUtils::addChild(doc, cdsOptionDataNode, "Term", term_);
186
187 if (asi_)
188 XMLUtils::appendNode(cdsOptionDataNode, asi_->toXML(doc));
189
190 XMLUtils::appendNode(cdsOptionDataNode, swap_.toXML(doc));
191 XMLUtils::appendNode(cdsOptionDataNode, option_.toXML(doc));
192
193 // Add CreditDefaultSwapOptionData node to Trade node
194 XMLUtils::appendNode(node, cdsOptionDataNode);
195
196 return node;
197}
XMLNode * toXML(XMLDocument &doc) const override
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: optiondata.cpp:86
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
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
+ Here is the call graph for this function:

◆ buildNoDefault()

void buildNoDefault ( const QuantLib::ext::shared_ptr< EngineFactory > &  ef)
private

Build CDS option given that no default.

Definition at line 199 of file creditdefaultswapoption.cpp.

199 {
200
201 DLOG("CreditDefaultSwapOption: building CDS option trade " << id() << " given no default.");
202
203 // Need fixed leg data with one rate. This should be the standard running coupon on the CDS e.g.
204 // generally 100bp for IG CDS and 500bp for HY CDS. For single name CDS options, one can use this field to give
205 // the strike spread. It may matter for the resulting valuation depending on the engine that is used - see
206 // "A CDS Option Miscellany, Richard J. Martin, 2019, Section 2.4".
207 const auto& legData = swap_.leg();
208 QL_REQUIRE(legData.legType() == "Fixed", "CDS option " << id() << " requires fixed leg.");
209 auto fixedLegData = QuantLib::ext::dynamic_pointer_cast<FixedLegData>(legData.concreteLegData());
210 QL_REQUIRE(fixedLegData->rates().size() == 1, "Index CDS option " << id() << " requires single fixed rate.");
211 auto runningCoupon = fixedLegData->rates().front();
212
213 // Payer (Receiver) swaption if the leg is paying (receiving).
214 auto side = legData.isPayer() ? Protection::Side::Buyer : Protection::Side::Seller;
215
216 // Day counter. In general for CDS, the standard day counter is Actual/360 and the final
217 // period coupon accrual includes the maturity date.
218 Actual360 standardDayCounter;
219 const std::string& strDc = legData.dayCounter();
220 DayCounter dc = strDc.empty() ? standardDayCounter : parseDayCounter(strDc);
221 DayCounter lastPeriodDayCounter = dc == standardDayCounter ? Actual360(true) : dc;
222
223 // Schedule
224 Schedule schedule = makeSchedule(legData.schedule());
225 BusinessDayConvention payConvention = legData.paymentConvention().empty() ? Following :
226 parseBusinessDayConvention(legData.paymentConvention());
227
228 // Don't support upfront fee on the underlying CDS for the moment.
229 QL_REQUIRE(swap_.upfrontFee() == Null<Real>() || close(swap_.upfrontFee(), 0.0),
230 "Upfront fee on the CDS underlying a CDS option is not supported.");
231
232 // The underlying CDS trade
233 auto cds = QuantLib::ext::make_shared<QuantLib::CreditDefaultSwap>(side, notional_, runningCoupon, schedule,
235 QuantLib::ext::shared_ptr<Claim>(), lastPeriodDayCounter, true, swap_.tradeDate(), swap_.cashSettlementDays());
236
237 // Copying here what is done for the index CDS option. The comment there is:
238 // Align option product maturities with ISDA AANA/GRID guidance as of November 2020.
239 maturity_ = std::max(cds->coupons().back()->date(), option_.premiumData().latestPremiumDate());
240
241 // Set engine on the underlying CDS.
242 auto cdsBuilder = QuantLib::ext::dynamic_pointer_cast<CreditDefaultSwapEngineBuilder>(
243 engineFactory->builder("CreditDefaultSwap"));
244 QL_REQUIRE(cdsBuilder, "CreditDefaultSwapOption expected CDS engine " <<
245 " builder for underlying while building trade " << id() << ".");
246 npvCurrency_ = legData.currency();
247 auto ccy = parseCurrency(npvCurrency_);
248 cds->setPricingEngine(cdsBuilder->engine(ccy, swap_.creditCurveId(), swap_.recoveryRate()));
249 setSensitivityTemplate(*cdsBuilder);
250
251 // Check option data
252 QL_REQUIRE(option_.style() == "European", "CreditDefaultSwapOption option style must" <<
253 " be European but got " << option_.style() << ".");
254 QL_REQUIRE(!option_.payoffAtExpiry(), "CreditDefaultSwapOption payoff must be at exercise.");
255 QL_REQUIRE(option_.exerciseFees().empty(), "CreditDefaultSwapOption cannot handle exercise fees.");
256
257 // Exercise must be European
258 const auto& exerciseDates = option_.exerciseDates();
259 QL_REQUIRE(exerciseDates.size() == 1, "CreditDefaultSwapOption expects one exercise date" <<
260 " but got " << exerciseDates.size() << " exercise dates.");
261 Date exerciseDate = parseDate(exerciseDates.front());
262 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(exerciseDate);
263
264 // Limit strike type to Spread for now.
266 QL_REQUIRE(strikeType == QuantExt::CdsOption::Spread, "CreditDefaultSwapOption strike type must be Spread.");
267
268 // If the strike_ is Null, the strike is taken as the running coupon.
269 Real strike = strike_ == Null<Real>() ? runningCoupon : strike_;
270
271 // Build the option instrument
272 auto cdsOption = QuantLib::ext::make_shared<QuantExt::CdsOption>(cds, exercise, knockOut_, strike, strikeType);
273
274 // Set the option engine
275 auto cdsOptionEngineBuilder = QuantLib::ext::dynamic_pointer_cast<CreditDefaultSwapOptionEngineBuilder>(
276 engineFactory->builder("CreditDefaultSwapOption"));
277 QL_REQUIRE(cdsOptionEngineBuilder, "CreditDefaultSwapOption expected CDS option engine " <<
278 " builder for underlying while building trade " << id() << ".");
279 cdsOption->setPricingEngine(cdsOptionEngineBuilder->engine(ccy, swap_.creditCurveId(), term_));
280 setSensitivityTemplate(*cdsOptionEngineBuilder);
281
282 // Set Trade members.
283 legs_ = { cds->coupons() };
285 legPayers_ = { legData.isPayer() };
286
287 // Include premium if enough information is provided
288 vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
289 vector<Real> additionalMultipliers;
290 string marketConfig = cdsOptionEngineBuilder->configuration(MarketContext::pricing);
291 addPremium(engineFactory, ccy, marketConfig, additionalInstruments, additionalMultipliers);
292
293 // Instrument wrapper depends on the settlement type.
294 Position::Type positionType = parsePositionType(option_.longShort());
295 Settlement::Type settleType = parseSettlementType(option_.settlement());
296 // The instrument build should be indpednent of the evaluation date. However, the general behavior
297 // in ORE (e.g. IR swaptions) for normal pricing runs is that the option is considered expired on
298 // the expiry date with no assumptions on an (automatic) exercise. Therefore we build a vanilla
299 // instrument if the exercise date is <= the eval date at build time.
300 if (settleType == Settlement::Cash || exerciseDate <= Settings::instance().evaluationDate()) {
301 Real indicatorLongShort = positionType == Position::Long ? 1.0 : -1.0;
302 instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(cdsOption, indicatorLongShort,
303 additionalInstruments, additionalMultipliers);
304 } else {
305 bool isLong = positionType == Position::Long;
306 bool isPhysical = settleType == Settlement::Physical;
307 instrument_ = QuantLib::ext::make_shared<EuropeanOptionWrapper>(cdsOption, isLong, exerciseDate,
308 isPhysical, cds, 1.0, 1.0, additionalInstruments, additionalMultipliers);
309 }
310}
QuantLib::Natural cashSettlementDays() const
const QuantLib::Date & tradeDate() const
Date addPremium(const QuantLib::ext::shared_ptr< EngineFactory > &ef, const QuantLib::Currency &tradeCurrency, const std::string &marketConfig, std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > &additionalInstruments, std::vector< QuantLib::Real > &additionalMultipliers)
Add the premium payment.
const string & longShort() const
Definition: optiondata.hpp:70
const string & style() const
Definition: optiondata.hpp:74
const string & settlement() const
Definition: optiondata.hpp:81
const bool & payoffAtExpiry() const
Definition: optiondata.hpp:75
const PremiumData & premiumData() const
Definition: optiondata.hpp:83
const vector< double > & exerciseFees() const
Definition: optiondata.hpp:84
const vector< string > & exerciseDates() const
Definition: optiondata.hpp:76
QuantLib::Date latestPremiumDate() const
Definition: premiumdata.cpp:28
string npvCurrency_
Definition: trade.hpp:201
std::vector< bool > legPayers_
Definition: trade.hpp:200
std::vector< string > legCurrencies_
Definition: trade.hpp:199
std::vector< QuantLib::Leg > legs_
Definition: trade.hpp:198
void setSensitivityTemplate(const EngineBuilder &builder)
Definition: trade.cpp:295
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
Definition: trade.hpp:197
CdsOption::StrikeType parseCdsOptionStrikeType(const string &s)
Definition: parsers.cpp:1240
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:290
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Definition: parsers.cpp:404
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
Definition: parsers.cpp:173
Settlement::Type parseSettlementType(const std::string &s)
Convert text to QuantLib::Settlement::Type.
Definition: parsers.cpp:434
DayCounter parseDayCounter(const string &s)
Convert text to QuantLib::DayCounter.
Definition: parsers.cpp:209
Schedule makeSchedule(const ScheduleDates &data)
Definition: schedule.cpp:263
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildDefaulted()

void buildDefaulted ( const QuantLib::ext::shared_ptr< EngineFactory > &  ef)
private

Build instrument given that default has occurred.

Definition at line 312 of file creditdefaultswapoption.cpp.

312 {
313
314 DLOG("CreditDefaultSwapOption: building CDS option trade " << id() << " given default occurred.");
315
316 // We add a simple payment for CDS options where the reference entity has already defaulted.
317 // If it is a knock-out CDS option, we add a dummy payment of 0.0 with date today instead of throwing.
318 const auto& legData = swap_.leg();
319 Date paymentDate = engineFactory->market()->asofDate();
320 Real amount = 0.0;
321 if (!knockOut_) {
322 paymentDate = asi_->auctionSettlementDate();
323 amount = notional_ * (1 - asi_->auctionFinalPrice());
324 // If it is a receiver option, i.e. selling protection, the FEP is paid out.
325 if (!legData.isPayer())
326 amount *= -1.0;
327 }
328
329 Position::Type positionType = parsePositionType(option_.longShort());
330 Real indicatorLongShort = positionType == Position::Long ? 1.0 : -1.0;
331
332 // Use the add premiums method to add the payment.
333 string marketConfig = Market::defaultConfiguration;
335 vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
336 vector<Real> additionalMultipliers;
337 Date premiumPayDate =
338 addPremiums(additionalInstruments, additionalMultipliers, indicatorLongShort,
339 PremiumData(amount, notionalCurrency_, paymentDate), 1.0, ccy, engineFactory, marketConfig);
340 DLOG("FEP payment (date = " << paymentDate << ", amount = " << amount << ") added for CDS option " << id() << ".");
341
342 // Use the instrument added as the main instrument and clear the vectors
343 auto qlInst = additionalInstruments.back();
344 QL_REQUIRE(qlInst, "Expected a FEP payment to have been added for CDS option " << id() << ".");
345 maturity_ = std::max(paymentDate, premiumPayDate);
346 additionalInstruments.clear();
347 additionalMultipliers.clear();
348
349 // Include premium if enough information is provided
350 addPremium(engineFactory, ccy, marketConfig, additionalInstruments, additionalMultipliers);
351
352 // Instrument wrapper.
353 instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(qlInst, indicatorLongShort,
354 additionalInstruments, additionalMultipliers);
355}
static const string defaultConfiguration
Default configuration label.
Definition: market.hpp:296
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)
Definition: trade.cpp:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addPremium()

Date addPremium ( const QuantLib::ext::shared_ptr< EngineFactory > &  ef,
const QuantLib::Currency &  tradeCurrency,
const std::string &  marketConfig,
std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > &  additionalInstruments,
std::vector< QuantLib::Real > &  additionalMultipliers 
)
private

Add the premium payment.

Definition at line 357 of file creditdefaultswapoption.cpp.

361 {
362 // The premium amount is always provided as a non-negative amount. Assign the correct sign here i.e.
363 // pay the premium if long the option and receive the premium if short the option.
364 Position::Type positionType = parsePositionType(option_.longShort());
365 Real indicatorLongShort = positionType == Position::Long ? 1.0 : -1.0;
366 return addPremiums(additionalInstruments, additionalMultipliers, indicatorLongShort, option_.premiumData(),
367 indicatorLongShort, tradeCurrency, ef, marketConfig);
368}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ option_

OptionData option_
private

Definition at line 108 of file creditdefaultswapoption.hpp.

◆ swap_

CreditDefaultSwapData swap_
private

Definition at line 109 of file creditdefaultswapoption.hpp.

◆ strike_

QuantLib::Real strike_
private

Definition at line 110 of file creditdefaultswapoption.hpp.

◆ strikeType_

std::string strikeType_
private

Definition at line 111 of file creditdefaultswapoption.hpp.

◆ knockOut_

bool knockOut_
private

Definition at line 112 of file creditdefaultswapoption.hpp.

◆ term_

std::string term_
private

Definition at line 113 of file creditdefaultswapoption.hpp.

◆ asi_

boost::optional<AuctionSettlementInformation> asi_
private

Definition at line 114 of file creditdefaultswapoption.hpp.