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

Serializable Bond. More...

#include <ored/portfolio/bond.hpp>

+ Inheritance diagram for Bond:
+ Collaboration diagram for Bond:

Public Member Functions

 Bond ()
 Default Constructor. More...
 
 Bond (Envelope env, const BondData &bondData)
 Constructor taking an envelope and bond data. More...
 
virtual void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Trade interface. More...
 
const BondDatabondData () const
 inspectors More...
 
std::map< AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
 Add underlying Bond names. More...
 
virtual void fromXML (XMLNode *node) override
 XMLSerializable interface. More...
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 
- 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_
 

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.

Definition at line 153 of file bond.hpp.

Constructor & Destructor Documentation

◆ Bond() [1/2]

Bond ( )
explicit

Default Constructor.

Definition at line 156 of file bond.hpp.

156: Trade("Bond") {}
Trade()
Default constructor.
Definition: trade.hpp:59

◆ Bond() [2/2]

Bond ( Envelope  env,
const BondData bondData 
)

Constructor taking an envelope and bond data.

Definition at line 159 of file bond.hpp.

160 : Trade("Bond", env), originalBondData_(bondData), bondData_(bondData) {}
BondData bondData_
Definition: bond.hpp:177
BondData originalBondData_
Definition: bond.hpp:177

Member Function Documentation

◆ build()

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

Trade interface.

Implements Trade.

Definition at line 228 of file bond.cpp.

228 {
229 DLOG("Bond::build() called for trade " << id());
230
231 // ISDA taxonomy: not a derivative, but define the asset class at least
232 // so that we can determine a TRS asset class that has Bond underlyings
233 additionalData_["isdaAssetClass"] = string("Credit");
234 additionalData_["isdaBaseProduct"] = string("");
235 additionalData_["isdaSubProduct"] = string("");
236 additionalData_["isdaTransaction"] = string("");
237
238 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
239 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder("Bond");
240 QL_REQUIRE(builder, "Bond::build(): internal error, builder is null");
241
243 bondData_.populateFromBondReferenceData(engineFactory->referenceData());
244
245 Date issueDate = parseDate(bondData_.issueDate());
247 QL_REQUIRE(!bondData_.settlementDays().empty(),
248 "no bond settlement days given, if reference data is used, check if securityId '"
249 << bondData_.securityId() << "' is present and of type Bond.");
250 Natural settlementDays = parseInteger(bondData_.settlementDays());
251 QuantLib::ext::shared_ptr<QuantLib::Bond> bond;
252
253 std::string openEndDateStr = builder->modelParameter("OpenEndDateReplacement", {}, false, "");
254 Date openEndDateReplacement = getOpenEndDateReplacement(openEndDateStr, calendar);
255 Real mult = bondData_.bondNotional() * (bondData_.isPayer() ? -1.0 : 1.0);
256 std::vector<Leg> separateLegs;
257 if (bondData_.zeroBond()) { // Zero coupon bond
258 bond.reset(new QuantLib::ZeroCouponBond(settlementDays, calendar, bondData_.faceAmount(),
260 } else { // Coupon bond
261 for (Size i = 0; i < bondData_.coupons().size(); ++i) {
262 Leg leg;
263 auto configuration = builder->configuration(MarketContext::pricing);
264 auto legBuilder = engineFactory->legBuilder(bondData_.coupons()[i].legType());
265 leg = legBuilder->buildLeg(bondData_.coupons()[i], engineFactory, requiredFixings_, configuration,
266 openEndDateReplacement);
267 separateLegs.push_back(leg);
268 } // for coupons_
269 Leg leg = joinLegs(separateLegs);
270 bond.reset(new QuantLib::Bond(settlementDays, calendar, issueDate, leg));
271 }
272
273 Currency currency = parseCurrency(bondData_.currency());
274 QuantLib::ext::shared_ptr<BondEngineBuilder> bondBuilder = QuantLib::ext::dynamic_pointer_cast<BondEngineBuilder>(builder);
275 QL_REQUIRE(bondBuilder, "No Builder found for Bond: " << id());
276 bond->setPricingEngine(bondBuilder->engine(currency, bondData_.creditCurveId(), bondData_.hasCreditRisk(),
278 setSensitivityTemplate(*bondBuilder);
279 instrument_.reset(new VanillaInstrument(bond, mult));
280
282 maturity_ = bond->cashflows().back()->date();
283 notional_ = currentNotional(bond->cashflows());
285
287
288 // Add legs (only 1)
289 legs_ = {bond->cashflows()};
292
293 DLOG("Bond::build() finished for trade " << id());
294}
const string & securityId() const
Definition: bond.hpp:84
bool hasCreditRisk() const
Definition: bond.hpp:96
bool zeroBond() const
Definition: bond.hpp:98
const string & currency() const
Definition: bond.hpp:94
Real faceAmount() const
Definition: bond.hpp:101
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 & issuerId() const
Inspectors.
Definition: bond.hpp:81
bool isPayer() const
Definition: bond.hpp:97
const string & referenceCurveId() const
Definition: bond.hpp:85
const string & issueDate() const
Definition: bond.hpp:90
const string & settlementDays() const
Definition: bond.hpp:88
const string & calendar() const
Definition: bond.hpp:89
const string & maturityDate() const
Definition: bond.hpp:102
const string & creditCurveId() const
Definition: bond.hpp:82
Real bondNotional() const
Definition: bond.hpp:95
string npvCurrency_
Definition: trade.hpp:201
std::vector< bool > legPayers_
Definition: trade.hpp:200
std::vector< string > legCurrencies_
Definition: trade.hpp:199
string issuer_
Definition: trade.hpp:205
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
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
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Definition: parsers.cpp:136
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
Calendar calendar
Definition: utilities.cpp:441
Real currentNotional(const Leg &leg)
Definition: legdata.cpp:2435
Date getOpenEndDateReplacement(const std::string &replacementPeriodStr, const Calendar &calendar)
Definition: bondutils.cpp:118
Leg joinLegs(const std::vector< Leg > &legs)
Definition: legdata.cpp:2703
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bondData()

const BondData & bondData ( ) const

inspectors

Definition at line 166 of file bond.hpp.

166{ return bondData_; }
+ Here is the caller 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 309 of file bond.cpp.

309 {
310 std::map<AssetClass, std::set<std::string>> result;
311 result[AssetClass::BOND] = {bondData_.securityId()};
312 return result;
313}
+ Here is the call graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

XMLSerializable interface.

Reimplemented from Trade.

Definition at line 296 of file bond.cpp.

296 {
297 Trade::fromXML(node);
298 originalBondData_.fromXML(XMLUtils::getChildNode(node, "BondData"));
300}
virtual void fromXML(XMLNode *node) override
XMLSerializable interface.
Definition: bond.cpp:59
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Reimplemented from Trade.

Definition at line 302 of file bond.cpp.

302 {
303 XMLNode* node = Trade::toXML(doc);
304 XMLUtils::appendNode(node, originalBondData_.toXML(doc));
305 return node;
306}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: bond.cpp:95
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ Here is the call graph for this function:

Member Data Documentation

◆ originalBondData_

BondData originalBondData_
private

Definition at line 177 of file bond.hpp.

◆ bondData_

BondData bondData_
private

Definition at line 177 of file bond.hpp.