26#include <ql/time/daycounters/actual360.hpp>
35 : auctionFinalPrice_(Null<Real>()) {}
38 const Date& auctionSettlementDate, Real& auctionFinalPrice)
39 : auctionSettlementDate_(auctionSettlementDate), auctionFinalPrice_(auctionFinalPrice) {}
42 return auctionSettlementDate_;
46 return auctionFinalPrice_;
69 const string& strikeType,
72 const boost::optional<AuctionSettlementInformation>& asi)
73 :
Trade(
"CreditDefaultSwapOption", env), option_(option), swap_(swap), strike_(strike),
74 strikeType_(strikeType), knockOut_(knockOut), term_(term), asi_(asi) {}
78 DLOG(
"CreditDefaultSwapOption::build() called for trade " <<
id());
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);
97 ALOG(
"Credit reference data missing for entity " << entity <<
", isdaSubProduct left blank");
105 QL_REQUIRE(ntls.size() == 1,
"CreditDefaultSwapOption requires a single notional.");
151 QL_REQUIRE(cdsOptionData,
"Expected CreditDefaultSwapOptionData node on trade " <<
id() <<
".");
161 asi_->fromXML(asiNode);
164 QL_REQUIRE(cdsData,
"Expected CreditDefaultSwapData node on trade " <<
id() <<
".");
168 QL_REQUIRE(optionData,
"Expected OptionData node on trade " <<
id() <<
".");
201 DLOG(
"CreditDefaultSwapOption: building CDS option trade " <<
id() <<
" given no default.");
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();
214 auto side = legData.isPayer() ? Protection::Side::Buyer : Protection::Side::Seller;
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;
225 BusinessDayConvention payConvention = legData.paymentConvention().empty() ? Following :
230 "Upfront fee on the CDS underlying a CDS option is not supported.");
233 auto cds = QuantLib::ext::make_shared<QuantLib::CreditDefaultSwap>(side,
notional_, runningCoupon, schedule,
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() <<
".");
252 QL_REQUIRE(
option_.
style() ==
"European",
"CreditDefaultSwapOption option style must" <<
255 QL_REQUIRE(
option_.
exerciseFees().empty(),
"CreditDefaultSwapOption cannot handle exercise fees.");
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);
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() <<
".");
283 legs_ = { cds->coupons() };
288 vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
289 vector<Real> additionalMultipliers;
291 addPremium(engineFactory, ccy, marketConfig, additionalInstruments, additionalMultipliers);
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);
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);
314 DLOG(
"CreditDefaultSwapOption: building CDS option trade " <<
id() <<
" given default occurred.");
319 Date paymentDate = engineFactory->market()->asofDate();
322 paymentDate =
asi_->auctionSettlementDate();
325 if (!legData.isPayer())
330 Real indicatorLongShort = positionType == Position::Long ? 1.0 : -1.0;
335 vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
336 vector<Real> additionalMultipliers;
337 Date premiumPayDate =
338 addPremiums(additionalInstruments, additionalMultipliers, indicatorLongShort,
340 DLOG(
"FEP payment (date = " << paymentDate <<
", amount = " << amount <<
") added for CDS option " <<
id() <<
".");
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();
350 addPremium(engineFactory, ccy, marketConfig, additionalInstruments, additionalMultipliers);
353 instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(qlInst, indicatorLongShort,
354 additionalInstruments, additionalMultipliers);
358 const Currency& tradeCurrency,
359 const string& marketConfig,
360 vector<QuantLib::ext::shared_ptr<Instrument>>& additionalInstruments,
361 vector<Real>& additionalMultipliers) {
365 Real indicatorLongShort = positionType == Position::Long ? 1.0 : -1.0;
367 indicatorLongShort, tradeCurrency, ef, marketConfig);
Builder that returns an engine to price a credit default swap option.
QuantLib::Real recoveryRate() const
const boost::optional< CdsReferenceInformation > & referenceInformation() const
QuantLib::Natural cashSettlementDays() const
const LegData & leg() const
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
bool settlesAccrual() const
const QuantLib::Date & tradeDate() const
PPT protectionPaymentTime() const
const string & creditCurveId() const
const Date & protectionStart() const
void buildDefaulted(const QuantLib::ext::shared_ptr< EngineFactory > &ef)
Build instrument given that default has occurred.
const std::string & strikeType() const
CreditDefaultSwapData swap_
void build(const QuantLib::ext::shared_ptr< EngineFactory > &ef) override
const OptionData & option() const
const CreditDefaultSwapData & swap() const
const std::string & term() const
void fromXML(XMLNode *node) override
CreditDefaultSwapOption()
Default constructor.
XMLNode * toXML(XMLDocument &doc) const override
QuantLib::Real strike() const
const boost::optional< AuctionSettlementInformation > & auctionSettlementInformation() const
boost::optional< AuctionSettlementInformation > asi_
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.
void buildNoDefault(const QuantLib::ext::shared_ptr< EngineFactory > &ef)
Build CDS option given that no default.
Serializable object holding generic trade data, reporting dimensions.
const vector< double > & notionals() const
static const string defaultConfiguration
Default configuration label.
Serializable object holding option data.
const string & longShort() const
const string & style() const
const string & settlement() const
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
const bool & payoffAtExpiry() const
const PremiumData & premiumData() const
const vector< double > & exerciseFees() const
const vector< string > & exerciseDates() const
Serializable object holding premium data.
QuantLib::Date latestPremiumDate() const
std::vector< bool > legPayers_
std::vector< string > legCurrencies_
std::vector< QuantLib::Leg > legs_
virtual void fromXML(XMLNode *node) override
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 setSensitivityTemplate(const EngineBuilder &builder)
virtual XMLNode * toXML(XMLDocument &doc) const override
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
std::map< std::string, boost::any > additionalData_
Small XML Document wrapper class.
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
static void checkNode(XMLNode *n, const string &expectedName)
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
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)
credit default swap option trade data model and serialization
CdsOption::StrikeType parseCdsOptionStrikeType(const string &s)
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
Settlement::Type parseSettlementType(const std::string &s)
Convert text to QuantLib::Settlement::Type.
DayCounter parseDayCounter(const string &s)
Convert text to QuantLib::DayCounter.
Classes and functions for log message handling.
#define DLOG(text)
Logging Macro (Level = Debug)
#define ALOG(text)
Logging Macro (Level = Alert)
std::string to_string(const LocationInfo &l)
Schedule makeSchedule(const ScheduleDates &data)
Serializable Credit Default Swap.
Wrapper for option instruments, tracks whether option has been exercised or not.
Map text representations to QuantLib/QuantExt types.
Reference data model and serialization.
string conversion utilities