Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | List of all members
AssetPositionTrsUnderlyingBuilder< T > Struct Template Reference

#include <ored/portfolio/trsunderlyingbuilder.hpp>

+ Inheritance diagram for AssetPositionTrsUnderlyingBuilder< T >:
+ Collaboration diagram for AssetPositionTrsUnderlyingBuilder< T >:

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
 
void updateQuantities (std::map< std::string, double > &indexQuantities, const std::string &indexName, const double qty) const
 
std::string getIndexCurrencyFromPosition (QuantLib::ext::shared_ptr< T > position, size_t i) const
 
std::string getIndexCurrencyFromPosition (QuantLib::ext::shared_ptr< EquityPosition > position, size_t i) const
 
std::string getIndexCurrencyFromPosition (QuantLib::ext::shared_ptr< CommodityPosition > position, size_t i) const
 
void updateQuantities (std::map< std::string, double > &indexQuantities, const std::string &indexName, const double qty) const
 
void updateQuantities (std::map< std::string, double > &indexQuantities, const std::string &indexName, const double qty) const
 
- 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

template<class T>
struct ore::data::AssetPositionTrsUnderlyingBuilder< T >

Definition at line 99 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 177 of file trsunderlyingbuilder.cpp.

189 {
190 auto t = QuantLib::ext::dynamic_pointer_cast<T>(underlying);
191 QL_REQUIRE(t, "could not cast to ore::data::EquityPosition, this is unexpected");
192 if (t->isSingleCurrency()) {
193 assetCurrency = t->npvCurrency();
194 DLOG("underlying equity position is single-currency, assetCurrency is " << assetCurrency);
195 } else {
196 // asset currency is set to funding currency data currency in trs as a default
197 // we use fxSpot() as opposed to fxRate() here to ensure consistency between NPV() and the fixing of an
198 // equivalent index representing the same basket
199 t->setNpvCurrencyConversion(
200 assetCurrency, engineFactory->market()->fxSpot(t->npvCurrency() + assetCurrency,
201 engineFactory->configuration(MarketContext::pricing)));
202 DLOG("underlying equity position is multi-currency, set assetCurrency to fundingCurrency = " << assetCurrency);
203 }
204 std::vector<QuantLib::ext::shared_ptr<QuantExt::FxIndex>> fxConversion(t->data().underlyings().size());
205 std::vector<QuantLib::ext::shared_ptr<QuantLib::Index>> indices;
206 for (auto const& i : t->indices()) {
207 indices.push_back(i);
208 DLOG("underlying equity index " << i->name() << " added.");
209 }
210 for (Size i = 0; i < t->data().underlyings().size(); ++i) {
211 fxConversion[i] = getFxIndex(engineFactory->market(), engineFactory->configuration(MarketContext::pricing),
212 assetCurrency, getIndexCurrencyFromPosition(t, i), fxIndices);
213 updateQuantities(indexQuantities, t->data().underlyings()[i].name(),
214 t->weights()[i] * t->data().quantity());
215 }
216 underlyingIndex = QuantLib::ext::make_shared<QuantExt::CompositeIndex>("Composite Index trade id " + parentId, indices,
217 t->weights(), fxConversion);
218 DLOG("underlying equity index built with " << indices.size() << " constituents.");
219 underlyingMultiplier = t->data().quantity();
220
221 auto fxIndex = getFxIndex(engineFactory->market(), engineFactory->configuration(MarketContext::pricing),
222 assetCurrency, fundingCurrency, fxIndices);
223 returnLegs.push_back(
224 QuantExt::TRSLeg(valuationDates, paymentDates, underlyingMultiplier, underlyingIndex, fxIndex)
225 .withInitialPrice(initialPrice));
226}
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
Size size(const ValueType &v)
Definition: value.cpp:145
void updateQuantities(std::map< std::string, double > &indexQuantities, const std::string &indexName, const double qty) const
std::string getIndexCurrencyFromPosition(QuantLib::ext::shared_ptr< T > position, size_t i) const
+ Here is the call graph for this function:

◆ updateQuantities() [1/3]

void updateQuantities ( std::map< std::string, double > &  indexQuantities,
const std::string &  indexName,
const double  qty 
) const

Definition at line 258 of file trsunderlyingbuilder.cpp.

259 {
260 QL_FAIL("internal error AssetPositionTrsUnderlyingBuilder only support Equity and Commodity positions");
261}

◆ getIndexCurrencyFromPosition() [1/3]

std::string getIndexCurrencyFromPosition ( QuantLib::ext::shared_ptr< T >  position,
size_t  i 
) const

Definition at line 241 of file trsunderlyingbuilder.cpp.

242 {
243 QL_FAIL("internal error AssetPositionTrsUnderlyingBuilder only support Equity and Commodity positions");
244}

◆ getIndexCurrencyFromPosition() [2/3]

std::string getIndexCurrencyFromPosition ( QuantLib::ext::shared_ptr< EquityPosition position,
size_t  i 
) const

Definition at line 229 of file trsunderlyingbuilder.cpp.

230 {
231 return position->indices()[i]->currency().code();
232}

◆ getIndexCurrencyFromPosition() [3/3]

std::string getIndexCurrencyFromPosition ( QuantLib::ext::shared_ptr< CommodityPosition position,
size_t  i 
) const

Definition at line 235 of file trsunderlyingbuilder.cpp.

236 {
237 return position->indices()[i]->priceCurve()->currency().code();
238}

◆ updateQuantities() [2/3]

void updateQuantities ( std::map< std::string, double > &  indexQuantities,
const std::string &  indexName,
const double  qty 
) const

Definition at line 247 of file trsunderlyingbuilder.cpp.

247 {
248 indexQuantities["EQ-" + indexName] = qty;
249}

◆ updateQuantities() [3/3]

void updateQuantities ( std::map< std::string, double > &  indexQuantities,
const std::string &  indexName,
const double  qty 
) const

Definition at line 252 of file trsunderlyingbuilder.cpp.

253 {
254 indexQuantities["COMM-" + indexName] = qty;
255}