Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | List of all members
BondPositionTrsUnderlyingBuilder Struct Reference

#include <ored/portfolio/trsunderlyingbuilder.hpp>

+ Inheritance diagram for BondPositionTrsUnderlyingBuilder:
+ Collaboration diagram for BondPositionTrsUnderlyingBuilder:

Public Member Functions

void build (const std::string &parentId, const QuantLib::ext::shared_ptr< Trade > &underlying, const std::vector< Date > &valuationDates, const std::vector< Date > &paymentDates, const std::string &fundingCurrency, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, QuantLib::ext::shared_ptr< QuantLib::Index > &underlyingIndex, Real &underlyingMultiplier, std::map< std::string, double > &indexQuantities, std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > &fxIndices, Real &initialPrice, std::string &assetCurrency, std::string &creditRiskCurrency, std::map< std::string, SimmCreditQualifierMapping > &creditQualifierMapping, Date &maturity, const std::function< QuantLib::ext::shared_ptr< QuantExt::FxIndex >(const QuantLib::ext::shared_ptr< Market > market, const std::string &configuration, const std::string &domestic, const std::string &foreign, std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > &fxIndices)> &getFxIndex, const std::string &underlyingDerivativeId, RequiredFixings &fixings, std::vector< Leg > &returnLegs) const override
 
- Public Member Functions inherited from TrsUnderlyingBuilder
virtual ~TrsUnderlyingBuilder ()
 
virtual void build (const std::string &parentId, const QuantLib::ext::shared_ptr< Trade > &underlying, const std::vector< Date > &valuationDates, const std::vector< Date > &paymentDates, const std::string &fundingCurrency, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, QuantLib::ext::shared_ptr< QuantLib::Index > &underlyingIndex, Real &underlyingMultiplier, std::map< std::string, double > &indexQuantities, std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > &fxIndices, Real &initialPrice, std::string &assetCurrency, std::string &creditRiskCurrency, std::map< std::string, SimmCreditQualifierMapping > &creditQualifierMapping, Date &maturity, const std::function< QuantLib::ext::shared_ptr< QuantExt::FxIndex >(const QuantLib::ext::shared_ptr< Market > market, const std::string &configuration, const std::string &domestic, const std::string &foreign, std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > &fxIndices)> &getFxIndex, const std::string &underlyingDerivativeId, RequiredFixings &fixings, std::vector< Leg > &returnLegs) const =0
 
virtual void updateUnderlying (const QuantLib::ext::shared_ptr< ReferenceDataManager > &refData, QuantLib::ext::shared_ptr< Trade > &underlying, const std::string &parentId) const
 

Detailed Description

Definition at line 140 of file trsunderlyingbuilder.hpp.

Member Function Documentation

◆ build()

void build ( const std::string &  parentId,
const QuantLib::ext::shared_ptr< Trade > &  underlying,
const std::vector< Date > &  valuationDates,
const std::vector< Date > &  paymentDates,
const std::string &  fundingCurrency,
const QuantLib::ext::shared_ptr< EngineFactory > &  engineFactory,
QuantLib::ext::shared_ptr< QuantLib::Index > &  underlyingIndex,
Real &  underlyingMultiplier,
std::map< std::string, double > &  indexQuantities,
std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > &  fxIndices,
Real &  initialPrice,
std::string &  assetCurrency,
std::string &  creditRiskCurrency,
std::map< std::string, SimmCreditQualifierMapping > &  creditQualifierMapping,
Date &  maturity,
const std::function< QuantLib::ext::shared_ptr< QuantExt::FxIndex >(const QuantLib::ext::shared_ptr< Market > market, const std::string &configuration, const std::string &domestic, const std::string &foreign, std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > &fxIndices)> &  getFxIndex,
const std::string &  underlyingDerivativeId,
RequiredFixings fixings,
std::vector< Leg > &  returnLegs 
) const
overridevirtual

Implements TrsUnderlyingBuilder.

Definition at line 321 of file trsunderlyingbuilder.cpp.

333 {
334 auto t = QuantLib::ext::dynamic_pointer_cast<ore::data::BondPosition>(underlying);
335 QL_REQUIRE(t, "could not cast to ore::data::BondPosition, this is unexpected");
336 if (t->isSingleCurrency()) {
337 assetCurrency = t->npvCurrency();
338 DLOG("underlying bond position is single-currency, assetCurrency is " << assetCurrency);
339 } else {
340 // asset currency is set to funding currency data currency in trs as a default
341 t->setNpvCurrencyConversion(
342 assetCurrency, engineFactory->market()->fxSpot(t->npvCurrency() + assetCurrency,
343 engineFactory->configuration(MarketContext::pricing)));
344 DLOG("underlying bond position is multi-currency, set assetCurrency to fundingCurrency = " << assetCurrency);
345 }
346
347 std::vector<QuantLib::ext::shared_ptr<QuantExt::FxIndex>> fxConversion(t->data().underlyings().size());
348 std::vector<QuantLib::ext::shared_ptr<QuantLib::Index>> indices;
349 bool hasCreditRisk = false;
350 for (Size i = 0; i < t->bonds().size(); ++i) {
351 // relative index, because weights are supposed to include any amortization factors
352
353 BondIndexBuilder bondIndexBuilder(t->data().underlyings()[i].name(), true, false,
354 NullCalendar(), true, engineFactory, t->data().underlyings()[i].bidAskAdjustment(), true);
355
356 auto assetCurr = bondIndexBuilder.bond().bondData().currency();
357 auto fxIndex = getFxIndex(engineFactory->market(), engineFactory->configuration(MarketContext::pricing),
358 assetCurr, fundingCurrency, fxIndices);
359
360 Leg bondLeg = makeBondTRSLeg(valuationDates, paymentDates, bondIndexBuilder, Null<Real>(), fxIndex);
361 returnLegs.push_back(bondLeg);
362
363 // add required bond and fx fixings from the index
364 bondIndexBuilder.addRequiredFixings(fixings, bondLeg);
365
366 indices.push_back(bondIndexBuilder.bondIndex());
367 DLOG("underlying bond index " << indices.back()->name() << " added.");
368 indexQuantities[bondIndexBuilder.bondIndex()->name()] = t->weights()[i] * t->data().quantity();
369 creditQualifierMapping[ore::data::securitySpecificCreditCurveName(t->bonds()[i].securityId,
370 t->bonds()[i].creditCurveId)] =
371 SimmCreditQualifierMapping(t->bonds()[i].securityId, t->bonds()[i].creditGroup);
372 creditQualifierMapping[t->bonds()[i].creditCurveId] =
373 SimmCreditQualifierMapping(t->bonds()[i].securityId, t->bonds()[i].creditGroup);
374 hasCreditRisk = hasCreditRisk || t->bonds()[i].hasCreditRisk;
375 }
376 for (Size i = 0; i < t->data().underlyings().size(); ++i) {
377 fxConversion[i] = getFxIndex(engineFactory->market(), engineFactory->configuration(MarketContext::pricing),
378 assetCurrency, t->bonds()[i].currency, fxIndices);
379 }
380 std::vector<Real> w;
381 for (Size i = 0; i < t->weights().size(); ++i) {
382 w.push_back(t->weights()[i]);
383 }
384 underlyingIndex =
385 QuantLib::ext::make_shared<QuantExt::CompositeIndex>("Composite Index trade id " + parentId, indices, w, fxConversion);
386 DLOG("underlying bond position index built with " << indices.size() << " constituents.");
387 underlyingMultiplier = t->data().quantity();
388
389 if (hasCreditRisk)
390 creditRiskCurrency = assetCurrency;
391 // FIXME same question as for single bond underlying: shouldn't we leave that empty and let TRS determine the
392 // maturity date based on valuation / funding dates?
393 maturity = t->maturity();
394}
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
Time maturity
Definition: utilities.cpp:66
Size size(const ValueType &v)
Definition: value.cpp:145
std::string securitySpecificCreditCurveName(const std::string &securityId, const std::string &creditCurveId)
Definition: marketdata.cpp:79
Leg makeBondTRSLeg(const std::vector< Date > &valuationDates, const std::vector< Date > &paymentDates, const BondIndexBuilder &bondIndexBuilder, Real initialPrice, QuantLib::ext::shared_ptr< QuantExt::FxIndex > fxIndex)
+ Here is the call graph for this function: