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

Serializable Convertible Bond. More...

#include <ored/portfolio/convertiblebond.hpp>

+ Inheritance diagram for ConvertibleBond:
+ Collaboration diagram for ConvertibleBond:

Public Member Functions

 ConvertibleBond ()
 Default constructor. More...
 
 ConvertibleBond (const Envelope &env, const ConvertibleBondData &data)
 Constructor for coupon bonds. More...
 
void build (const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &) override
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (XMLDocument &doc) const override
 
std::map< AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
 Add underlying Bond names. More...
 
const ConvertibleBondDatadata () const
 
const BondDatabondData () 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...
 

Private Attributes

ConvertibleBondData originalData_
 
ConvertibleBondData data_
 

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

Serializable Convertible Bond.

Definition at line 34 of file convertiblebond.hpp.

Constructor & Destructor Documentation

◆ ConvertibleBond() [1/2]

Default constructor.

Definition at line 37 of file convertiblebond.hpp.

37: Trade("ConvertibleBond") {}
Trade()
Default constructor.
Definition: trade.hpp:59

◆ ConvertibleBond() [2/2]

ConvertibleBond ( const Envelope env,
const ConvertibleBondData data 
)

Constructor for coupon bonds.

Definition at line 40 of file convertiblebond.hpp.

41 : Trade("ConvertibleBond", env), originalData_(data), data_(data) {}
ConvertibleBondData data_
ConvertibleBondData originalData_
@ data
Definition: log.hpp:77

Member Function Documentation

◆ build()

void build ( const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &  engineFactory)
override

Definition at line 417 of file convertiblebond.cpp.

417 {
418 DLOG("ConvertibleBond::build() called for trade " << id());
419
420 // ISDA taxonomy: not a derivative, but define the asset class at least
421 // so that we can determine a TRS asset class that has Convertible Bond underlyings
422 additionalData_["isdaAssetClass"] = string("Credit");
423 additionalData_["isdaBaseProduct"] = string("");
424 additionalData_["isdaSubProduct"] = string("");
425 additionalData_["isdaTransaction"] = string("");
426
427 auto builder = QuantLib::ext::dynamic_pointer_cast<ConvertibleBondEngineBuilder>(engineFactory->builder("ConvertibleBond"));
428 QL_REQUIRE(builder, "ConvertibleBond::build(): could not cast to ConvertibleBondBuilder, this is unexpected");
429
431 data_.populateFromBondReferenceData(engineFactory->referenceData());
432
433 // build converible underlying bond, add to required fixings
434
435 ore::data::Bond underlyingBond(Envelope(), data_.bondData());
436 underlyingBond.build(engineFactory);
437 requiredFixings_.addData(underlyingBond.requiredFixings());
438 auto qlUnderlyingBond = QuantLib::ext::dynamic_pointer_cast<QuantLib::Bond>(underlyingBond.instrument()->qlInstrument());
439 QL_REQUIRE(qlUnderlyingBond,
440 "ConvertibleBond::build(): internal error, could not cast underlying bond to QuantLib::Bond");
441 auto qlUnderlyingBondCoupons = qlUnderlyingBond->cashflows();
442 qlUnderlyingBondCoupons.erase(
443 std::remove_if(qlUnderlyingBondCoupons.begin(), qlUnderlyingBondCoupons.end(),
444 [](QuantLib::ext::shared_ptr<CashFlow> c) { return QuantLib::ext::dynamic_pointer_cast<Coupon>(c) == nullptr; }),
445 qlUnderlyingBondCoupons.end());
446
447 // get open end date replacement from vanilla builder to handle perpetuals
448
449 QuantLib::ext::shared_ptr<EngineBuilder> vanillaBuilder = engineFactory->builder("Bond");
450 QL_REQUIRE(builder, "ConvertibleBond::build(): internal error, vanilla builder is null");
451 std::string openEndDateStr = vanillaBuilder->modelParameter("OpenEndDateReplacement", {}, false, "");
452 Date openEndDateReplacement = getOpenEndDateReplacement(openEndDateStr, parseCalendar(data_.bondData().calendar()));
453
454 // check whether the underlying bond is set up as perpetual (i.e. without maturity date)
455
456 bool isPerpetual = false;
457 for (auto const& d : data_.bondData().coupons()) {
458 for (auto const& r : d.schedule().rules()) {
459 isPerpetual = isPerpetual || r.endDate().empty();
460 }
461 }
462
463 DLOG("isPerpetual=" << std::boolalpha << isPerpetual << ", openEndDateReplacement=" << openEndDateReplacement);
464
465 // get equity index and fx index
466
467 auto config = builder->configuration(MarketContext::pricing);
468
469 QuantLib::ext::shared_ptr<EquityIndex2> equity;
470 if (!data_.conversionData().equityUnderlying().name().empty()) {
471 equity = *engineFactory->market()->equityCurve(data_.conversionData().equityUnderlying().name(), config);
472 }
473
474 QL_REQUIRE((equity == nullptr && data_.conversionData().fixedAmountConversionData().initialised()) ||
475 (equity != nullptr && !data_.conversionData().fixedAmountConversionData().initialised()),
476 "ConvertibleBondEngineBuilder::build(): exactly one of equity underlying or fixed amount conversion "
477 "must be specified");
478
479 QuantLib::ext::shared_ptr<FxIndex> fx;
480 if (equity != nullptr && !equity->currency().empty()) {
481 if (equity->currency().code() != data_.bondData().currency()) {
482 QL_REQUIRE(!data_.conversionData().fxIndex().empty(),
483 "ConvertibleBondEngineBuilder::build(): FXIndex required in conversion data, since eq ccy ("
484 << equity->currency().code() << ") not equal bond ccy (" << data_.bondData().currency()
485 << ")");
486 fx = buildFxIndex(data_.conversionData().fxIndex(), data_.bondData().currency(), equity->currency().code(),
487 engineFactory->market(), config);
488 }
489 } else if (equity == nullptr && data_.conversionData().fixedAmountConversionData().initialised()) {
491 QL_REQUIRE(!data_.conversionData().fxIndex().empty(),
492 "ConvertibleBondEngineBuilder::build(): FXIndex required in conversion data, since fixed amount "
493 "conversion ccy ("
494 << data_.conversionData().fixedAmountConversionData().currency() << ") not equal bond ccy ("
495 << data_.bondData().currency() << ")");
497 data_.conversionData().fixedAmountConversionData().currency(), engineFactory->market(),
498 config);
499 }
500 }
501
502 // for cross currency, add required FX fixings for conversion and dividend history
503
504 if (fx != nullptr) {
505
506 Date d0 = qlUnderlyingBond->startDate();
507 Date d1 = qlUnderlyingBond->maturityDate();
508
509 // FIXME, the following only works, if we have the dividends loaded at this point...
510 if (equity != nullptr) {
511 auto div = equity->dividendFixings();
512 for (auto const& d : div) {
513 if (d.exDate >= d0) {
514 requiredFixings_.addFixingDate(fx->fixingCalendar().adjust(d.exDate, Preceding),
516 }
517 }
518 }
519
520 Date today = Settings::instance().evaluationDate();
521 d0 = std::min(d0, today);
522
523 // ...as a workaround, we add all fx fixings from min(today, bond start date) to maturity
524 // -> this also covers the required fx fixings for conversion, so we don't have to add them separately
525 for (Date d = d0; d <= d1; ++d) {
526 requiredFixings_.addFixingDate(fx->fixingCalendar().adjust(d, Preceding), data_.conversionData().fxIndex(),
527 Date::maxDate(), false, false);
528 }
529 }
530
531 // the multiplier, basically the number of bonds and a sign for long / short positions
532
533 Real multiplier = data_.bondData().bondNotional() * (data_.bondData().isPayer() ? -1.0 : 1.0);
534
535 // build convertible data
536
537 ConvertibleBond2::ExchangeableData exchangeableData = buildExchangeableData(data_.conversionData());
538 std::vector<ConvertibleBond2::CallabilityData> callData =
539 buildCallabilityData(data_.callData(), openEndDateReplacement);
540 ConvertibleBond2::MakeWholeData makeWholeCrIncreaseData = buildMakeWholeData(data_.callData());
541 std::vector<ConvertibleBond2::CallabilityData> putData =
542 buildCallabilityData(data_.putData(), openEndDateReplacement);
543 // for fixed amounts the model will provide an equity with constant unit spot rate, so that
544 // we can treat the amount as a ratio
545 std::vector<ConvertibleBond2::ConversionRatioData> conversionRatioData =
546 equity != nullptr ? buildConversionRatioData(data_.conversionData())
547 : buildConversionFixedAmountData(data_.conversionData());
548 std::vector<ConvertibleBond2::ConversionData> conversionData = buildConversionData(
549 data_.conversionData(), requiredFixings_, equity, fx, data_.conversionData().fxIndex(), openEndDateReplacement);
550 std::vector<ConvertibleBond2::MandatoryConversionData> mandatoryConversionData =
551 buildMandatoryConversionData(data_.conversionData());
552 std::vector<ConvertibleBond2::ConversionResetData> conversionResetData = buildConversionResetData(
553 data_.conversionData(), requiredFixings_, equity, fx, data_.conversionData().fxIndex(), openEndDateReplacement);
554 std::vector<ConvertibleBond2::DividendProtectionData> dividendProtectionData =
555 buildDividendProtectionData(data_.dividendProtectionData(), requiredFixings_, equity, fx,
556 data_.conversionData().fxIndex(), openEndDateReplacement);
557
558 // build convertible bond instrument and attach pricing engine
559
560 // get the last relevant date of the convertible bond, this is used as the last calibration date for the model
561 Date lastDate = qlUnderlyingBond->maturityDate();
562 if (!dividendProtectionData.empty()) {
563 lastDate = std::max(lastDate, dividendProtectionData.back().protectionDate);
564 }
565
566 QL_REQUIRE(data_.conversionData().initialised(), "ConvertibleBond::build(): conversion data required");
567 auto qlConvertible = QuantLib::ext::make_shared<ConvertibleBond2>(
568 qlUnderlyingBond->settlementDays(), qlUnderlyingBond->calendar(), qlUnderlyingBond->issueDate(),
569 qlUnderlyingBondCoupons, exchangeableData, callData, makeWholeCrIncreaseData, putData, conversionRatioData,
570 conversionData, mandatoryConversionData, conversionResetData, dividendProtectionData,
571 data_.detachable().empty() ? false : parseBool(data_.detachable()), isPerpetual);
572 qlConvertible->setPricingEngine(builder->engine(
574 data_.bondData().securityId(), data_.bondData().referenceCurveId(), exchangeableData.isExchangeable, equity, fx,
575 data_.conversionData().exchangeableData().equityCreditCurve(), qlUnderlyingBond->startDate(), lastDate));
576 setSensitivityTemplate(*builder);
577
578 // set up other trade member variables
579
580 instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(qlConvertible, multiplier);
582 maturity_ = qlUnderlyingBond->maturityDate();
583 notional_ = qlUnderlyingBond->notional();
584 legs_ = {qlUnderlyingBond->cashflows()};
587}
const string & securityId() const
Definition: bond.hpp:84
bool hasCreditRisk() const
Definition: bond.hpp:96
const string & currency() const
Definition: bond.hpp:94
const std::vector< LegData > & coupons() const
Definition: bond.hpp:93
bool isPayer() const
Definition: bond.hpp:97
const string & referenceCurveId() const
Definition: bond.hpp:85
const string & calendar() const
Definition: bond.hpp:89
const string & creditCurveId() const
Definition: bond.hpp:82
Real bondNotional() const
Definition: bond.hpp:95
Serializable Bond.
Definition: bond.hpp:153
const ore::data::EquityUnderlying equityUnderlying() const
const ExchangeableData & exchangeableData() const
const FixedAmountConversionData & fixedAmountConversionData() const
const ore::data::BondData & bondData() const
const CallabilityData & putData() const
const CallabilityData & callData() const
const DividendProtectionData & dividendProtectionData() const
const ConversionData & conversionData() const
void populateFromBondReferenceData(const QuantLib::ext::shared_ptr< ore::data::ReferenceDataManager > &referenceData)
const std::string & name() const override
Definition: underlying.hpp:109
void addData(const RequiredFixings &requiredFixings)
void addFixingDate(const QuantLib::Date &fixingDate, const std::string &indexName, const QuantLib::Date &payDate=Date::maxDate(), const bool alwaysAddIfPaysOnSettlement=false, const bool mandatoryFixing=true)
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
QuantLib::Real notional_
Definition: trade.hpp:202
void setSensitivityTemplate(const EngineBuilder &builder)
Definition: trade.cpp:295
RequiredFixings requiredFixings_
Definition: trade.hpp:223
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
Definition: trade.hpp:197
string notionalCurrency_
Definition: trade.hpp:203
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
Definition: parsers.cpp:157
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
Date getOpenEndDateReplacement(const std::string &replacementPeriodStr, const Calendar &calendar)
Definition: bondutils.cpp:118
QuantLib::ext::shared_ptr< QuantExt::FxIndex > buildFxIndex(const string &fxIndex, const string &domestic, const string &foreign, const QuantLib::ext::shared_ptr< Market > &market, const string &configuration, bool useXbsCurves)
Definition: marketdata.cpp:137
+ Here is the call graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 589 of file convertiblebond.cpp.

589 {
590 Trade::fromXML(node);
591 originalData_.fromXML(XMLUtils::getChildNode(node, "ConvertibleBondData"));
593}
void fromXML(ore::data::XMLNode *node) override

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Reimplemented from Trade.

Definition at line 595 of file convertiblebond.cpp.

595 {
596 XMLNode* node = Trade::toXML(doc);
597 XMLUtils::appendNode(node, originalData_.toXML(doc));
598 return node;
599}
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60

◆ underlyingIndices()

std::map< AssetClass, std::set< std::string > > underlyingIndices ( const QuantLib::ext::shared_ptr< ReferenceDataManager > &  referenceDataManager = nullptr) const
overridevirtual

Add underlying Bond names.

Reimplemented from Trade.

Definition at line 44 of file convertiblebond.cpp.

44 {
46 data_.populateFromBondReferenceData(referenceDataManager);
47 std::map<AssetClass, std::set<std::string>> result;
48 result[AssetClass::BOND] = {data_.bondData().securityId()};
49 if (!data_.conversionData().equityUnderlying().name().empty())
50 result[AssetClass::EQ] = {data_.conversionData().equityUnderlying().name()};
51 return result;
52}

◆ data()

const ConvertibleBondData & data ( ) const

Definition at line 51 of file convertiblebond.hpp.

51{ return data_; }

◆ bondData()

const BondData & bondData ( ) const

Definition at line 52 of file convertiblebond.hpp.

52{ return data_.bondData(); }
+ Here is the call graph for this function:

Member Data Documentation

◆ originalData_

ConvertibleBondData originalData_
private

Definition at line 55 of file convertiblebond.hpp.

◆ data_

ConvertibleBondData data_
mutableprivate

Definition at line 56 of file convertiblebond.hpp.