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

#include <ored/utilities/bondindexbuilder.hpp>

+ Collaboration diagram for BondIndexBuilder:

Public Member Functions

 BondIndexBuilder (BondData bondData, const bool dirty, const bool relative, const Calendar &fixingCalendar, const bool conditionalOnSurvival, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, QuantLib::Real bidAskAdjustment=0.0, const bool bondIssueDateFallback=false)
 
 BondIndexBuilder (const Bond &bond, const bool dirty, const bool relative, const Calendar &fixingCalendar, const bool conditionalOnSurvival, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, QuantLib::Real bidAskAdjustment=0.0, const bool bondIssueDateFallback=false)
 
 BondIndexBuilder (const std::string &securityId, const bool dirty, const bool relative, const Calendar &fixingCalendar, const bool conditionalOnSurvival, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, QuantLib::Real bidAskAdjustment=0.0, const bool bondIssueDateFallback=false)
 
QuantLib::ext::shared_ptr< QuantExt::BondIndexbondIndex () const
 
void addRequiredFixings (RequiredFixings &requiredFixings, Leg leg={})
 
const Bondbond () const
 
QuantLib::Real priceAdjustment (QuantLib::Real price)
 

Private Member Functions

void buildIndex (const bool relative, const Calendar &fixingCalendar, const bool conditionalOnSurvival, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, QuantLib::Real bidAskAdjustment, const bool bondIssueDateFallback)
 

Private Attributes

Bond bond_
 
QuantLib::ext::shared_ptr< QuantExt::BondIndexbondIndex_
 
RequiredFixings fixings_
 
const bool dirty_
 

Detailed Description

Definition at line 31 of file bondindexbuilder.hpp.

Constructor & Destructor Documentation

◆ BondIndexBuilder() [1/3]

BondIndexBuilder ( BondData  bondData,
const bool  dirty,
const bool  relative,
const Calendar &  fixingCalendar,
const bool  conditionalOnSurvival,
const QuantLib::ext::shared_ptr< EngineFactory > &  engineFactory,
QuantLib::Real  bidAskAdjustment = 0.0,
const bool  bondIssueDateFallback = false 
)

◆ BondIndexBuilder() [2/3]

BondIndexBuilder ( const Bond bond,
const bool  dirty,
const bool  relative,
const Calendar &  fixingCalendar,
const bool  conditionalOnSurvival,
const QuantLib::ext::shared_ptr< EngineFactory > &  engineFactory,
QuantLib::Real  bidAskAdjustment = 0.0,
const bool  bondIssueDateFallback = false 
)

◆ BondIndexBuilder() [3/3]

BondIndexBuilder ( const std::string &  securityId,
const bool  dirty,
const bool  relative,
const Calendar &  fixingCalendar,
const bool  conditionalOnSurvival,
const QuantLib::ext::shared_ptr< EngineFactory > &  engineFactory,
QuantLib::Real  bidAskAdjustment = 0.0,
const bool  bondIssueDateFallback = false 
)

Member Function Documentation

◆ bondIndex()

QuantLib::ext::shared_ptr< QuantExt::BondIndex > bondIndex ( ) const

Definition at line 112 of file bondindexbuilder.cpp.

112{ return bondIndex_; }
QuantLib::ext::shared_ptr< QuantExt::BondIndex > bondIndex_
+ Here is the caller graph for this function:

◆ addRequiredFixings()

void addRequiredFixings ( RequiredFixings requiredFixings,
Leg  leg = {} 
)

Definition at line 114 of file bondindexbuilder.cpp.

114 {
115 requiredFixings.addData(fixings_.filteredFixingDates());
116 if (dirty_) {
117 QL_REQUIRE(leg.size() > 0, "BondIndexBuild: Leg is required if dirty flag set to true");
118 RequiredFixings legFixings;
119 auto fixingGetter = QuantLib::ext::make_shared<FixingDateGetter>(legFixings);
120 fixingGetter->setRequireFixingStartDates(true);
121 addToRequiredFixings(leg, fixingGetter);
122
123 set<Date> fixingDates;
124
125 auto fixingMap = legFixings.fixingDatesIndices();
126 if (fixingMap.size() > 0) {
127 std::map<std::string, std::set<Date>> indexFixings;
128 for (const auto& [_, dates] : fixingMap) {
129 for (const auto& [d, mandatory] : dates) {
130 auto tmp = fixings_.filteredFixingDates(d);
131 requiredFixings.addData(tmp);
132 }
133 }
134 }
135 }
136}
void addData(const RequiredFixings &requiredFixings)
RequiredFixings filteredFixingDates(const QuantLib::Date &settlementDate=QuantLib::Date())
void addToRequiredFixings(const QuantLib::Leg &leg, const QuantLib::ext::shared_ptr< FixingDateGetter > &fixingDateGetter)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bond()

const Bond & bond ( ) const

Definition at line 50 of file bondindexbuilder.hpp.

+ Here is the caller graph for this function:

◆ priceAdjustment()

Real priceAdjustment ( QuantLib::Real  price)

Definition at line 138 of file bondindexbuilder.cpp.

138 {
139 if (price == Null<Real>())
140 return price;
141
142 Real adj = bond_.bondData().priceQuoteMethod() == QuantExt::BondIndex::PriceQuoteMethod::CurrencyPerUnit
144 : 1.0;
145 return price * adj;
146}
Real priceQuoteBaseValue() const
Definition: bond.cpp:50
QuantExt::BondIndex::PriceQuoteMethod priceQuoteMethod() const
Definition: bond.cpp:45
const BondData & bondData() const
inspectors
Definition: bond.hpp:166
+ Here is the caller graph for this function:

◆ buildIndex()

void buildIndex ( const bool  relative,
const Calendar &  fixingCalendar,
const bool  conditionalOnSurvival,
const QuantLib::ext::shared_ptr< EngineFactory > &  engineFactory,
QuantLib::Real  bidAskAdjustment,
const bool  bondIssueDateFallback 
)
private

Definition at line 57 of file bondindexbuilder.cpp.

59 {
60
62
63 auto qlBond = QuantLib::ext::dynamic_pointer_cast<QuantLib::Bond>(bond_.instrument()->qlInstrument());
64 QL_REQUIRE(qlBond, "buildBondIndex(): could not cast to QuantLib::Bond, this is unexpected");
65
66 // get the curves
67 auto bondData = bond_.bondData();
68 string securityId = bondData.securityId();
69
70 Handle<YieldTermStructure> discountCurve = engineFactory->market()->yieldCurve(
71 bondData.referenceCurveId(), engineFactory->configuration(MarketContext::pricing));
72
73 Handle<DefaultProbabilityTermStructure> defaultCurve;
74 if (!bondData.creditCurveId().empty())
75 defaultCurve = securitySpecificCreditCurve(engineFactory->market(), securityId, bondData.creditCurveId(),
76 engineFactory->configuration(MarketContext::pricing))
77 ->curve();
78
79 Handle<YieldTermStructure> incomeCurve;
80 if (!bondData.incomeCurveId().empty())
81 incomeCurve = engineFactory->market()->yieldCurve(bondData.incomeCurveId(),
82 engineFactory->configuration(MarketContext::pricing));
83
84 Handle<Quote> recovery;
85 try {
86 recovery =
87 engineFactory->market()->recoveryRate(securityId, engineFactory->configuration(MarketContext::pricing));
88 } catch (...) {
89 WLOG("security specific recovery rate not found for security ID "
90 << securityId << ", falling back on the recovery rate for credit curve Id " << bondData.creditCurveId());
91 if (!bondData.creditCurveId().empty())
92 recovery = engineFactory->market()->recoveryRate(bondData.creditCurveId(),
93 engineFactory->configuration(MarketContext::pricing));
94 }
95
96 Handle<Quote> spread(QuantLib::ext::make_shared<SimpleQuote>(0.0));
97 try {
98 spread =
99 engineFactory->market()->securitySpread(securityId, engineFactory->configuration(MarketContext::pricing));
100 } catch (...) {
101 }
102
103 if (!bondData.hasCreditRisk())
104 defaultCurve = Handle<DefaultProbabilityTermStructure>();
105
106 // build and return the index
107 bondIndex_ = QuantLib::ext::make_shared<QuantExt::BondIndex>(securityId, dirty_, relative, fixingCalendar, qlBond,
108 discountCurve, defaultCurve, recovery, spread, incomeCurve, conditionalOnSurvival, parseDate(bondData.issueDate()), bondData.priceQuoteMethod(),
109 bondData.priceQuoteBaseValue(), bondData.isInflationLinked(), bidAskAdjustment, bondIssueDateFallback);
110}
const string & securityId() const
Definition: bond.hpp:84
const RequiredFixings & requiredFixings() const
Definition: trade.hpp:90
const QuantLib::ext::shared_ptr< InstrumentWrapper > & instrument() const
Definition: trade.hpp:141
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
QuantLib::Handle< QuantExt::CreditCurve > securitySpecificCreditCurve(const QuantLib::ext::shared_ptr< Market > &market, const std::string &securityId, const std::string &creditCurveId, const std::string &configuration)
Definition: marketdata.cpp:98
+ Here is the call graph for this function:

Member Data Documentation

◆ bond_

Bond bond_
private

Definition at line 54 of file bondindexbuilder.hpp.

◆ bondIndex_

QuantLib::ext::shared_ptr<QuantExt::BondIndex> bondIndex_
private

Definition at line 55 of file bondindexbuilder.hpp.

◆ fixings_

RequiredFixings fixings_
private

Definition at line 56 of file bondindexbuilder.hpp.

◆ dirty_

const bool dirty_
private

Definition at line 57 of file bondindexbuilder.hpp.