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

#include <ored/portfolio/bondposition.hpp>

+ Inheritance diagram for BondPosition:
+ Collaboration diagram for BondPosition:

Public Member Functions

 BondPosition ()
 
 BondPosition (const Envelope &env, const BondPositionData &data)
 
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
 
const BondPositionDatadata () const
 
const std::vector< ore::data::BondBuilder::Result > & bonds () const
 
const std::vector< Real > & weights () const
 
const std::vector< Real > & bidAskAdjustments () const
 
bool isSingleCurrency () const
 
void setNpvCurrencyConversion (const std::string &ccy, const Handle< Quote > &conversion)
 
- 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

BondPositionData originalData_
 
BondPositionData data_
 
std::vector< BondBuilder::Resultbonds_
 
std::vector< Real > weights_
 
std::vector< Real > bidAskAdjustments_
 
std::vector< Handle< Quote > > fxConversion_
 
bool isSingleCurrency_
 

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 56 of file bondposition.hpp.

Constructor & Destructor Documentation

◆ BondPosition() [1/2]

Definition at line 58 of file bondposition.hpp.

58: Trade("BondPosition") {}
Trade()
Default constructor.
Definition: trade.hpp:59

◆ BondPosition() [2/2]

BondPosition ( const Envelope env,
const BondPositionData data 
)

Definition at line 59 of file bondposition.hpp.

60 : Trade("BondPosition", env), originalData_(data), data_(data) {}
BondPositionData originalData_
BondPositionData data_
const BondPositionData & data() const

Member Function Documentation

◆ build()

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

Definition at line 62 of file bondposition.cpp.

62 {
63 DLOG("BondPosition::build() called for " << id());
64
65 // ISDA taxonomy: not a derivative, but define the asset class at least
66 // so that we can determine a TRS asset class that has a Bond position underlying
67 additionalData_["isdaAssetClass"] = string("Credit");
68 additionalData_["isdaBaseProduct"] = string("");
69 additionalData_["isdaSubProduct"] = string("");
70 additionalData_["isdaTransaction"] = string("");
71
72 bonds_.clear();
73 weights_.clear();
74 bidAskAdjustments_.clear();
75 fxConversion_.clear();
76
78 data_.populateFromBondBasketReferenceData(engineFactory->referenceData());
79
80 QL_REQUIRE(!data_.underlyings().empty(), "BondPosition::build(): no underlyings given");
81
82 maturity_ = Date::minDate();
83 for (auto const& u : data_.underlyings()) {
84 try {
85 bonds_.push_back(BondFactory::instance().build(engineFactory, engineFactory->referenceData(), u.name()));
86 } catch (const std::exception& e) {
87 QL_FAIL("Build failed for underlying " << u.type() << " (" << u.name() << "): " << e.what());
88 }
89 weights_.push_back(u.weight());
90 bidAskAdjustments_.push_back(u.bidAskAdjustment());
91 maturity_ = std::max(bonds_.back().bond->maturityDate(), maturity_);
92 }
93
94 // get fx quotes
95
96 isSingleCurrency_ = true;
97 npvCurrency_ = bonds_.front().currency;
98 for (auto const& b : bonds_) {
99 fxConversion_.push_back(engineFactory->market()->fxSpot(b.currency + npvCurrency_,
100 engineFactory->configuration(MarketContext::pricing)));
101 if (npvCurrency_ != b.currency)
102 isSingleCurrency_ = false;
103 }
104
105 // set instrument
106 std::vector<QuantLib::ext::shared_ptr<QuantLib::Bond>> qlbonds;
107 std::transform(bonds_.begin(), bonds_.end(), std::back_inserter(qlbonds),
108 [](const BondBuilder::Result& d) { return d.bond; });
109 instrument_ = QuantLib::ext::make_shared<BondPositionInstrumentWrapper>(data_.quantity(), qlbonds, weights_,
111
112 // leave legs empty, leave notional empty for the time being
113 notional_ = Null<Real>();
115
116 setSensitivityTemplate(std::string());
117}
void populateFromBondBasketReferenceData(const QuantLib::ext::shared_ptr< ReferenceDataManager > &ref)
const std::vector< BondUnderlying > & underlyings() const
std::vector< Handle< Quote > > fxConversion_
std::vector< Real > weights_
void build(const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &) override
std::vector< Real > bidAskAdjustments_
std::vector< BondBuilder::Result > bonds_
string npvCurrency_
Definition: trade.hpp:201
QuantLib::Real notional_
Definition: trade.hpp:202
void setSensitivityTemplate(const EngineBuilder &builder)
Definition: trade.cpp:295
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 124 of file bondposition.cpp.

124 {
125 Trade::fromXML(node);
126 originalData_.fromXML(XMLUtils::getChildNode(node, "BondBasketData"));
128}
void fromXML(XMLNode *node) override
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Reimplemented from Trade.

Definition at line 130 of file bondposition.cpp.

130 {
131 XMLNode* node = Trade::toXML(doc);
133 return node;
134}
XMLNode * toXML(XMLDocument &doc) const override
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ 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

Reimplemented from Trade.

Definition at line 137 of file bondposition.cpp.

137 {
138 std::map<AssetClass, std::set<std::string>> result;
139 for (auto const& u : data_.underlyings()) {
140 result[AssetClass::BOND].insert(u.name());
141 }
142 result[AssetClass::BOND_INDEX].insert(data().identifier());
143 return result;
144}
+ Here is the call graph for this function:

◆ data()

const BondPositionData & data ( ) const

Definition at line 70 of file bondposition.hpp.

70{ return data_; }
+ Here is the caller graph for this function:

◆ bonds()

const std::vector< ore::data::BondBuilder::Result > & bonds ( ) const

Definition at line 71 of file bondposition.hpp.

71{ return bonds_; }

◆ weights()

const std::vector< Real > & weights ( ) const

Definition at line 72 of file bondposition.hpp.

72{ return weights_; }

◆ bidAskAdjustments()

const std::vector< Real > & bidAskAdjustments ( ) const

Definition at line 73 of file bondposition.hpp.

73{ return bidAskAdjustments_; }

◆ isSingleCurrency()

bool isSingleCurrency ( ) const

Definition at line 74 of file bondposition.hpp.

74{ return isSingleCurrency_; }

◆ setNpvCurrencyConversion()

void setNpvCurrencyConversion ( const std::string &  ccy,
const Handle< Quote > &  conversion 
)

we allow to set the npv currency to a different currency than the default npv currency = first asset's currency; in this case a conversion rate from the default to the new currency has to be provided

Definition at line 119 of file bondposition.cpp.

119 {
120 npvCurrency_ = ccy;
121 QuantLib::ext::static_pointer_cast<BondPositionInstrumentWrapper>(instrument_)->setNpvCurrencyConversion(conversion);
122}

Member Data Documentation

◆ originalData_

BondPositionData originalData_
private

Definition at line 81 of file bondposition.hpp.

◆ data_

BondPositionData data_
private

Definition at line 81 of file bondposition.hpp.

◆ bonds_

std::vector<BondBuilder::Result> bonds_
private

Definition at line 83 of file bondposition.hpp.

◆ weights_

std::vector<Real> weights_
private

Definition at line 84 of file bondposition.hpp.

◆ bidAskAdjustments_

std::vector<Real> bidAskAdjustments_
private

Definition at line 85 of file bondposition.hpp.

◆ fxConversion_

std::vector<Handle<Quote> > fxConversion_
private

Definition at line 86 of file bondposition.hpp.

◆ isSingleCurrency_

bool isSingleCurrency_
private

Definition at line 87 of file bondposition.hpp.