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

#include <ored/portfolio/bondrepo.hpp>

+ Inheritance diagram for BondRepo:
+ Collaboration diagram for BondRepo:

Public Member Functions

 BondRepo ()
 
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 ore::data::BondDatabondData () const
 
const ore::data::LegDatacashLegData () 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

ore::data::BondData originalSecurityLegData_
 
ore::data::BondData securityLegData_
 
ore::data::LegData cashLegData_
 
QuantLib::ext::shared_ptr< ore::data::BondsecurityLeg_
 
Leg cashLeg_
 

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 34 of file bondrepo.hpp.

Constructor & Destructor Documentation

◆ BondRepo()

BondRepo ( )

Definition at line 36 of file bondrepo.hpp.

36: Trade("BondRepo") {}
Trade()
Default constructor.
Definition: trade.hpp:59

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 41 of file bondrepo.cpp.

41 {
42 DLOG("BondRepo::build() called for trade " << id());
43
44 // get bond repo engine builder
45
46 auto builder = QuantLib::ext::dynamic_pointer_cast<BondRepoEngineBuilderBase>(engineFactory->builder("BondRepo"));
47 QL_REQUIRE(builder, "BondRepo::build(): engine builder is null");
48
49 // build security leg (as a bond)
50
52 securityLegData_.populateFromBondReferenceData(engineFactory->referenceData());
53 securityLeg_ = QuantLib::ext::make_shared<ore::data::Bond>(Envelope(), securityLegData_);
54 securityLeg_->id() = id() + "_SecurityLeg";
55 securityLeg_->build(engineFactory);
56 QL_REQUIRE(!securityLeg_->legs().empty(), "BondRepo::build(): security leg has no cashflows");
57
58 // build cash leg
59
60 auto configuration = builder->configuration(MarketContext::pricing);
61 auto legBuilder = engineFactory->legBuilder(cashLegData_.legType());
62 cashLeg_ = legBuilder->buildLeg(cashLegData_, engineFactory, requiredFixings_, configuration);
63
64 // add notional payment
65
66 QL_REQUIRE(!cashLeg_.empty(), "BondRepo::build(): cash leg empty");
67 auto lastCpn = QuantLib::ext::dynamic_pointer_cast<Coupon>(cashLeg_.back());
68 QL_REQUIRE(lastCpn, "BondRepo::build(): expected coupon on cash leg");
69 cashLeg_.push_back(QuantLib::ext::make_shared<QuantLib::SimpleCashFlow>(lastCpn->nominal(), lastCpn->date()));
70
71 // add required fixings from bond
72
73 requiredFixings_.addData(securityLeg_->requiredFixings());
74
75 // set trade members
76
79 maturity_ = CashFlows::maturityDate(cashLeg_);
81
82 // start with the cashleg's legs
83 legs_ = {cashLeg_};
86
87 // add security legs to trade legs (should be 1 leg only, but to be safe we copy all legs in the trade)
88 legs_.insert(legs_.end(), securityLeg_->legs().begin(), securityLeg_->legs().end());
89 legCurrencies_.insert(legCurrencies_.end(), securityLeg_->legCurrencies().begin(),
90 securityLeg_->legCurrencies().end());
91 std::vector<bool> securityLegPayers(securityLeg_->legs().size(), !cashLegData_.isPayer());
92 legPayers_.insert(legPayers_.end(), securityLegPayers.begin(), securityLegPayers.end());
93
94 QL_REQUIRE(cashLegData_.currency() == securityLeg_->bondData().currency(),
95 "BondRepo: cash leg currency (" << cashLegData_.currency() << ") must match security leg currency ("
96 << securityLeg_->bondData().currency() << ")");
97
98 auto qlBondInstr = QuantLib::ext::dynamic_pointer_cast<QuantLib::Bond>(securityLeg_->instrument()->qlInstrument());
99 QL_REQUIRE(qlBondInstr, "BondRepo: could not cast to QuantLib::Bond instrument, this is unexpected");
100 auto qlInstr = QuantLib::ext::make_shared<QuantExt::BondRepo>(cashLeg_, cashLegData_.isPayer(), qlBondInstr,
101 std::abs(securityLeg_->instrument()->multiplier()));
102
103 qlInstr->setPricingEngine(builder->engine(securityLegData_.incomeCurveId()));
104 instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(qlInstr);
105 setSensitivityTemplate(*builder);
106
107 // set additionalData
108 additionalData_["underlyingSecurityId"] = securityLegData_.securityId();
109 additionalData_["legType[1]"] = string("Cash");
110 additionalData_["currentNotional[1]"] = notional_;
111 additionalData_["originalNotional[1]"] = originalNotional(cashLeg_);
112 additionalData_["notionalCurrency[1]"] = notionalCurrency_;
113 additionalData_["legType[2]"] = string("Security");
114 additionalData_["originalNotional[2]"] = securityLegData_.bondNotional();
115 additionalData_["currentNotional[2]"] = currentNotional(qlBondInstr->cashflows()) * securityLegData_.bondNotional();
116 additionalData_["notionalCurrency[2]"] = securityLegData_.currency();
117}
const string & securityId() const
Definition: bond.hpp:84
const string & currency() const
Definition: bond.hpp:94
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 & incomeCurveId() const
Definition: bond.hpp:86
Real bondNotional() const
Definition: bond.hpp:95
ore::data::LegData cashLegData_
Definition: bondrepo.hpp:52
ore::data::BondData securityLegData_
Definition: bondrepo.hpp:51
QuantLib::ext::shared_ptr< ore::data::Bond > securityLeg_
Definition: bondrepo.hpp:54
ore::data::BondData originalSecurityLegData_
Definition: bondrepo.hpp:51
const string & currency() const
Definition: legdata.hpp:873
bool isPayer() const
Definition: legdata.hpp:872
const string & legType() const
Definition: legdata.hpp:890
void addData(const RequiredFixings &requiredFixings)
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
string & id()
Set the trade id.
Definition: trade.hpp:118
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
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
Real currentNotional(const Leg &leg)
Definition: legdata.cpp:2435
Real originalNotional(const Leg &leg)
Definition: legdata.cpp:2449
+ Here is the call graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 119 of file bondrepo.cpp.

119 {
120 Trade::fromXML(node);
121
122 XMLNode* dataNode = XMLUtils::getChildNode(node, "BondRepoData");
123 QL_REQUIRE(dataNode, "BondRepoData node not found");
124 XMLNode* bondNode = XMLUtils::getChildNode(dataNode, "BondData");
125 QL_REQUIRE(bondNode, "BondData node not found");
128
129 XMLNode* repoNode = XMLUtils::getChildNode(dataNode, "RepoData");
130 QL_REQUIRE(repoNode, "RepoData node not found");
131
132 XMLNode* legNode = XMLUtils::getChildNode(repoNode, "LegData");
133 QL_REQUIRE(legNode, "LegData node not found");
134 cashLegData_.fromXML(legNode);
135}
virtual void fromXML(XMLNode *node) override
XMLSerializable interface.
Definition: bond.cpp:59
virtual void fromXML(XMLNode *node) override
Definition: legdata.cpp:759
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Reimplemented from Trade.

Definition at line 137 of file bondrepo.cpp.

137 {
138 XMLNode* node = Trade::toXML(doc);
139 XMLNode* dataNode = doc.allocNode("BondRepoData");
140 XMLUtils::appendNode(node, dataNode);
141
142 XMLUtils::appendNode(dataNode, originalSecurityLegData_.toXML(doc));
143
144 XMLNode* repoNode = doc.allocNode("RepoData");
145 XMLUtils::appendNode(dataNode, repoNode);
146 XMLUtils::appendNode(repoNode, cashLegData_.toXML(doc));
147
148 return node;
149}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: bond.cpp:95
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: legdata.cpp:856
+ 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 152 of file bondrepo.cpp.

152 {
153 std::map<AssetClass, std::set<std::string>> result;
154 result[AssetClass::BOND] = {securityLegData_.securityId()};
155 return result;
156}

◆ bondData()

const ore::data::BondData & bondData ( ) const

Definition at line 47 of file bondrepo.hpp.

47{ return securityLegData_; }

◆ cashLegData()

const ore::data::LegData & cashLegData ( ) const

Definition at line 48 of file bondrepo.hpp.

48{ return cashLegData_; }

Member Data Documentation

◆ originalSecurityLegData_

ore::data::BondData originalSecurityLegData_
private

Definition at line 51 of file bondrepo.hpp.

◆ securityLegData_

ore::data::BondData securityLegData_
private

Definition at line 51 of file bondrepo.hpp.

◆ cashLegData_

ore::data::LegData cashLegData_
private

Definition at line 52 of file bondrepo.hpp.

◆ securityLeg_

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

Definition at line 54 of file bondrepo.hpp.

◆ cashLeg_

Leg cashLeg_
private

Definition at line 55 of file bondrepo.hpp.