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

Serializable Bond Option. More...

#include <ored/portfolio/bondoption.hpp>

+ Inheritance diagram for BondOption:
+ Collaboration diagram for BondOption:

Public Member Functions

 BondOption ()
 Default constructor. More...
 
 BondOption (Envelope env, const BondData &bondData, const OptionData &optionData, TradeStrike strike, bool knocksOut)
 Constructor taking trade data. More...
 
virtual void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 
virtual void fromXML (XMLNode *node) override
 
virtual 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 BondDatabondData () const
 
const OptionDataoptionData () const
 
TradeStrike strike () const
 
double redemption () const
 
string priceType () 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

BondData originalBondData_
 
BondData bondData_
 
OptionData optionData_
 
TradeStrike strike_
 
double redemption_
 
string priceType_
 
string currency_
 
bool knocksOut_
 
QuantLib::ext::shared_ptr< ore::data::Bondunderlying_
 

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 Bond Option.

Definition at line 39 of file bondoption.hpp.

Constructor & Destructor Documentation

◆ BondOption() [1/2]

Default constructor.

Definition at line 42 of file bondoption.hpp.

42: Trade("BondOption"), redemption_(0.0), knocksOut_(false) {}
Trade()
Default constructor.
Definition: trade.hpp:59

◆ BondOption() [2/2]

BondOption ( Envelope  env,
const BondData bondData,
const OptionData optionData,
TradeStrike  strike,
bool  knocksOut 
)

Constructor taking trade data.

Definition at line 45 of file bondoption.hpp.

46 : Trade("BondOption", env), bondData_(bondData), optionData_(optionData), strike_(strike),
47 knocksOut_(knocksOut) {}
OptionData optionData_
Definition: bondoption.hpp:67

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 49 of file bondoption.cpp.

49 {
50 DLOG("Building Bond Option: " << id());
51
52 // ISDA taxonomy
53 additionalData_["isdaAssetClass"] = string("Interest Rate");
54 additionalData_["isdaBaseProduct"] = string("Option");
55 additionalData_["isdaSubProduct"] = string("Debt Option");
56 additionalData_["isdaTransaction"] = string("");
57
58 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
59 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder("BondOption");
61 bondData_.populateFromBondReferenceData(engineFactory->referenceData());
62
64 QuantLib::ext::shared_ptr<QuantExt::BondOption> bondoption;
65
66 // FIXME this won't work for zero bonds (but their implementation is incomplete anyhow, see bond.cpp)
67 underlying_ = QuantLib::ext::make_shared<ore::data::Bond>(Envelope(), bondData_);
68
69 underlying_->build(engineFactory);
70
71 legs_ = underlying_->legs();
72 legCurrencies_ = underlying_->legCurrencies();
73 legPayers_ = std::vector<bool>(legs_.size(), false); // always receive (long option view)
74 npvCurrency_ = underlying_->bondData().currency();
76 notionalCurrency_ = underlying_->bondData().currency();
78
79 auto qlBondInstr = QuantLib::ext::dynamic_pointer_cast<QuantLib::Bond>(underlying_->instrument()->qlInstrument());
80 QL_REQUIRE(qlBondInstr, "BondOption::build(): could not cast to QuantLib::Bond");
81 for (auto const p : underlying_->legPayers()) {
82 QL_REQUIRE(!p, "BondOption::build(): underlying leg must be receiver");
83 }
84
85 boost::variant<QuantLib::Bond::Price, QuantLib::InterestRate> callabilityPrice;
86 if (strike_.type() == TradeStrike::Type::Price) {
87 if (priceType_ == "Dirty") {
88 callabilityPrice = QuantLib::Bond::Price(strike_.value(), QuantLib::Bond::Price::Dirty);
89 } else if (priceType_ == "Clean") {
90 callabilityPrice = QuantLib::Bond::Price(strike_.value(), QuantLib::Bond::Price::Clean);
91 } else {
92 QL_FAIL("BondOption::build(): price type \"" << priceType_ << "\" not recognised.");
93 }
94 } else {
95 // strike is quoted as a yield
96 DayCounter dayCounter = Actual365Fixed();
97 Frequency freq = Annual;
98 // attempt to get the daycounter and frequency from the bond
99 if (bondData_.coupons().size() > 0) {
100 auto cn = bondData_.coupons().front();
101 const string& dc = cn.dayCounter();
102 if (!dc.empty())
103 dayCounter = parseDayCounter(dc);
104 if (cn.schedule().rules().size() > 0)
105 freq = parsePeriod(cn.schedule().rules().front().tenor()).frequency();
106 }
107 callabilityPrice = QuantLib::InterestRate(strike_.value(), dayCounter, strike_.compounding(), freq);
108 }
109
110 Callability::Type callabilityType =
111 parseOptionType(optionData_.callPut()) == Option::Call ? Callability::Call : Callability::Put;
112
113 QL_REQUIRE(optionData_.exerciseDates().size() == 1,
114 "BondOption::build(): exactly one option date required, found " << optionData_.exerciseDates().size());
115 Date exerciseDate = parseDate(optionData_.exerciseDates().back());
116 QuantLib::ext::shared_ptr<Callability> callability;
117 callability.reset(new Callability(callabilityPrice, callabilityType, exerciseDate));
118 CallabilitySchedule callabilitySchedule = std::vector<QuantLib::ext::shared_ptr<Callability>>(1, callability);
119
120 bondoption.reset(new QuantExt::BondOption(qlBondInstr, callabilitySchedule, knocksOut_));
121
122 Currency currency = parseCurrency(underlying_->bondData().currency());
123
124 QuantLib::ext::shared_ptr<BondOptionEngineBuilder> bondOptionBuilder =
125 QuantLib::ext::dynamic_pointer_cast<BondOptionEngineBuilder>(builder);
126 QL_REQUIRE(bondOptionBuilder, "No Builder found for bondOption: " << id());
127
128 QuantLib::ext::shared_ptr<BlackBondOptionEngine> blackEngine = QuantLib::ext::dynamic_pointer_cast<BlackBondOptionEngine>(
129 bondOptionBuilder->engine(id(), currency, bondData_.creditCurveId(), bondData_.hasCreditRisk(),
131 bondoption->setPricingEngine(blackEngine);
132 setSensitivityTemplate(*bondOptionBuilder);
133
134 Real multiplier =
135 bondData_.bondNotional() * (parsePositionType(optionData_.longShort()) == Position::Long ? 1.0 : -1.0);
136
137 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
138 std::vector<Real> additionalMultipliers;
139 addPremiums(additionalInstruments, additionalMultipliers, multiplier, optionData_.premiumData(),
140 multiplier > 0.0 ? -1.0 : 1.0, currency, engineFactory,
141 bondOptionBuilder->configuration(MarketContext::pricing));
142
143 instrument_.reset(new VanillaInstrument(bondoption, multiplier, additionalInstruments, additionalMultipliers));
144
145 // the required fixings are (at most) those of the underlying
146 requiredFixings_ = underlying_->requiredFixings();
147}
const CallabilitySchedule & callability() const
const boost::shared_ptr< QuantLib::Bond > underlying_
const string & securityId() const
Definition: bond.hpp:84
bool hasCreditRisk() const
Definition: bond.hpp:96
const string & volatilityCurveId() const
Definition: bond.hpp:87
const std::vector< LegData > & coupons() const
Definition: bond.hpp:93
void populateFromBondReferenceData(const QuantLib::ext::shared_ptr< BondReferenceDatum > &referenceDatum, const std::string &startDate="", const std::string &endDate="")
populate data from reference datum and check data for completeness
Definition: bond.cpp:175
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
BondData originalBondData_
Definition: bondoption.hpp:66
const string & callPut() const
Definition: optiondata.hpp:71
const string & longShort() const
Definition: optiondata.hpp:70
const PremiumData & premiumData() const
Definition: optiondata.hpp:83
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
QuantLib::Real notional_
Definition: trade.hpp:202
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
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
const QuantLib::Compounding & compounding()
QuantLib::Real value() const
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
Definition: parsers.cpp:157
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
Period parsePeriod(const string &s)
Convert text to QuantLib::Period.
Definition: parsers.cpp:171
DayCounter parseDayCounter(const string &s)
Convert text to QuantLib::DayCounter.
Definition: parsers.cpp:209
Option::Type parseOptionType(const std::string &s)
Convert text to QuantLib::Option::Type.
Definition: parsers.cpp:481
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
Calendar calendar
Definition: utilities.cpp:441
+ Here is the call graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 149 of file bondoption.cpp.

149 {
150 Trade::fromXML(node);
151
152 XMLNode* bondOptionNode = XMLUtils::getChildNode(node, "BondOptionData");
153 QL_REQUIRE(bondOptionNode, "No BondOptionData Node");
154 optionData_.fromXML(XMLUtils::getChildNode(bondOptionNode, "OptionData"));
155 strike_.fromXML(bondOptionNode, true, true);
156 redemption_ = XMLUtils::getChildValueAsDouble(bondOptionNode, "Redemption", false, 100.0);
157 // don't need PriceType id a yield strike is provided
158 if (strike_.type() == TradeStrike::Type::Price)
159 priceType_ = XMLUtils::getChildValue(bondOptionNode, "PriceType", true);
160 if (auto n = XMLUtils::getChildNode(bondOptionNode, "KnocksOut"))
161 knocksOut_ = parseBool(XMLUtils::getNodeValue(n));
162 else
163 knocksOut_ = false;
164
165 originalBondData_.fromXML(XMLUtils::getChildNode(bondOptionNode, "BondData"));
167}
virtual void fromXML(XMLNode *node) override
XMLSerializable interface.
Definition: bond.cpp:59
virtual void fromXML(XMLNode *node) override
Definition: optiondata.cpp:32
void fromXML(XMLNode *node, const bool isRequired=true, const bool allowYieldStrike=false)
Definition: tradestrike.cpp:50
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
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 169 of file bondoption.cpp.

169 {
170 XMLNode* node = Trade::toXML(doc);
171
172 XMLNode* bondOptionNode = doc.allocNode("BondOptionData");
173 XMLUtils::appendNode(node, bondOptionNode);
174 XMLUtils::appendNode(bondOptionNode, optionData_.toXML(doc));
175 XMLUtils::appendNode(bondOptionNode, strike_.toXML(doc));
176 XMLUtils::addChild(doc, bondOptionNode, "Redemption", redemption_);
177 if (!priceType_.empty())
178 XMLUtils::addChild(doc, bondOptionNode, "PriceType", priceType_);
179 XMLUtils::addChild(doc, bondOptionNode, "KnocksOut", knocksOut_);
180
181 XMLUtils::appendNode(bondOptionNode, originalBondData_.toXML(doc));
182 return node;
183}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: bond.cpp:95
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: optiondata.cpp:86
XMLNode * toXML(XMLDocument &doc) const
Definition: tradestrike.cpp:86
+ Here is the call graph for this function:

◆ 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 186 of file bondoption.cpp.

186 {
187 std::map<AssetClass, std::set<std::string>> result;
188 result[AssetClass::BOND] = {bondData_.securityId()};
189 return result;
190}

◆ bondData()

const BondData & bondData ( ) const

Definition at line 59 of file bondoption.hpp.

59{ return bondData_; }

◆ optionData()

const OptionData & optionData ( ) const

Definition at line 60 of file bondoption.hpp.

60{ return optionData_; }

◆ strike()

TradeStrike strike ( ) const

Definition at line 61 of file bondoption.hpp.

61{ return strike_; }

◆ redemption()

double redemption ( ) const

Definition at line 62 of file bondoption.hpp.

62{ return redemption_; }

◆ priceType()

string priceType ( ) const

Definition at line 63 of file bondoption.hpp.

63{ return priceType_; }

Member Data Documentation

◆ originalBondData_

BondData originalBondData_
private

Definition at line 66 of file bondoption.hpp.

◆ bondData_

BondData bondData_
private

Definition at line 66 of file bondoption.hpp.

◆ optionData_

OptionData optionData_
private

Definition at line 67 of file bondoption.hpp.

◆ strike_

TradeStrike strike_
private

Definition at line 69 of file bondoption.hpp.

◆ redemption_

double redemption_
private

Definition at line 70 of file bondoption.hpp.

◆ priceType_

string priceType_
private

Definition at line 71 of file bondoption.hpp.

◆ currency_

string currency_
private

Definition at line 72 of file bondoption.hpp.

◆ knocksOut_

bool knocksOut_
private

Definition at line 73 of file bondoption.hpp.

◆ underlying_

QuantLib::ext::shared_ptr<ore::data::Bond> underlying_
private

Definition at line 75 of file bondoption.hpp.