Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
trsunderlyingbuilder.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
24
30
33
34namespace ore {
35namespace data {
36
37void modifyBondTRSLeg(QuantLib::Leg& leg, QuantLib::Date issueDate) {
38 auto it = leg.begin();
39 while (it != leg.end()) {
40 auto cf = QuantLib::ext::dynamic_pointer_cast<QuantExt::BondTRSCashFlow>(*it);
41 if (cf) {
42 if (cf->fixingEndDate() < issueDate) {
43 it = leg.erase(it);
44 continue;
45 } else if (cf->fixingStartDate() < issueDate)
46 cf->setFixingStartDate(issueDate);
47 }
48 ++it;
49 }
50}
51
52Leg makeBondTRSLeg(const std::vector<Date>& valuationDates, const std::vector<Date>& paymentDates,
53 const BondIndexBuilder& bondIndexBuilder, Real initialPrice,
54 QuantLib::ext::shared_ptr<QuantExt::FxIndex> fxIndex) {
55
56 Leg returnLeg =
57 QuantExt::BondTRSLeg(valuationDates, paymentDates, bondIndexBuilder.bond().bondData().bondNotional(),
58 bondIndexBuilder.bondIndex(), fxIndex).withInitialPrice(initialPrice);
59 modifyBondTRSLeg(returnLeg, parseDate(bondIndexBuilder.bond().bondData().issueDate()));
60 return returnLeg;
61}
62
63QuantLib::ext::shared_ptr<TrsUnderlyingBuilder> TrsUnderlyingBuilderFactory::getBuilder(const std::string& tradeType) const {
64 boost::shared_lock<boost::shared_mutex> lock(mutex_);
65 auto b = builders_.find(tradeType);
66 QL_REQUIRE(b != builders_.end(), "TrsUnderlyingBuilderFactory::getBuilder(" << tradeType << "): no builder found");
67 return b->second;
68}
69
70void TrsUnderlyingBuilderFactory::addBuilder(const std::string& tradeType,
71 const QuantLib::ext::shared_ptr<TrsUnderlyingBuilder>& builder,
72 const bool allowOverwrite) {
73 boost::unique_lock<boost::shared_mutex> locK(mutex_);
74 QL_REQUIRE(builders_.insert(std::make_pair(tradeType, builder)).second || allowOverwrite,
75 "TrsUnderlyingBuidlerFactory::addBuilder(" << tradeType << "): builder for key already exists.");
76}
77
79 const std::string& parentId, const QuantLib::ext::shared_ptr<Trade>& underlying, const std::vector<Date>& valuationDates,
80 const std::vector<Date>& paymentDates, const std::string& fundingCurrency,
81 const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory, QuantLib::ext::shared_ptr<QuantLib::Index>& underlyingIndex,
82 Real& underlyingMultiplier, std::map<std::string, double>& indexQuantities,
83 std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>>& fxIndices, Real& initialPrice,
84 std::string& assetCurrency, std::string& creditRiskCurrency,
85 std::map<std::string, SimmCreditQualifierMapping>& creditQualifierMapping, Date& maturity,
86 const std::function<QuantLib::ext::shared_ptr<QuantExt::FxIndex>(
87 const QuantLib::ext::shared_ptr<Market> market, const std::string& configuration, const std::string& domestic,
88 const std::string& foreign, std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>>& fxIndices)>&
89 getFxIndex,
90 const std::string& underlyingDerivativeId, RequiredFixings& fixings, std::vector<Leg>& returnLegs) const {
91 auto t = QuantLib::ext::dynamic_pointer_cast<ore::data::Bond>(underlying);
92 QL_REQUIRE(t, "could not cast to ore::data::Bond, this is unexpected");
93 auto qlBond = QuantLib::ext::dynamic_pointer_cast<QuantLib::Bond>(underlying->instrument()->qlInstrument());
94 QL_REQUIRE(qlBond, "expected QuantLib::Bond, could not cast");
95 BondIndexBuilder bondIndexBuilder(*t, true, false, NullCalendar(), true, engineFactory);
96 underlyingIndex = bondIndexBuilder.bondIndex();
97
98 underlyingMultiplier = t->bondData().bondNotional();
99 indexQuantities[underlyingIndex->name()] = underlyingMultiplier;
100
101 if (initialPrice != Null<Real>())
102 initialPrice = qlBond->notional(valuationDates.front()) * bondIndexBuilder.priceAdjustment(initialPrice);
103
104 assetCurrency = t->bondData().currency();
105
106 auto fxIndex = getFxIndex(engineFactory->market(), engineFactory->configuration(MarketContext::pricing), assetCurrency,
107 fundingCurrency, fxIndices);
108
109 auto leg = QuantExt::BondTRSLeg(valuationDates, paymentDates, bondIndexBuilder.bond().bondData().bondNotional(),
110 bondIndexBuilder.bondIndex(), fxIndex)
111 .withInitialPrice(initialPrice);
112
113 // add required bond and fx fixings for bondIndex
114 returnLegs.push_back(leg);
115 bondIndexBuilder.addRequiredFixings(fixings, leg);
116
117 if (!t->bondData().creditCurveId().empty())
118 creditRiskCurrency = t->bondData().currency();
119 creditQualifierMapping[securitySpecificCreditCurveName(t->bondData().securityId(), t->bondData().creditCurveId())] =
120 SimmCreditQualifierMapping(t->bondData().securityId(), t->bondData().creditGroup());
121 creditQualifierMapping[t->bondData().creditCurveId()] =
122 SimmCreditQualifierMapping(t->bondData().securityId(), t->bondData().creditGroup());
123 // FIXME shouldn't we leave that empty and let TRS determine the maturity date based on valuation / funding dates?
124 maturity = qlBond->maturityDate();
125}
126
128 const std::string& parentId, const QuantLib::ext::shared_ptr<Trade>& underlying, const std::vector<Date>& valuationDates,
129 const std::vector<Date>& paymentDates, const std::string& fundingCurrency,
130 const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory, QuantLib::ext::shared_ptr<QuantLib::Index>& underlyingIndex,
131 Real& underlyingMultiplier, std::map<std::string, double>& indexQuantities,
132 std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>>& fxIndices, Real& initialPrice,
133 std::string& assetCurrency, std::string& creditRiskCurrency,
134 std::map<std::string, SimmCreditQualifierMapping>& creditQualifierMapping, Date& maturity,
135 const std::function<QuantLib::ext::shared_ptr<QuantExt::FxIndex>(
136 const QuantLib::ext::shared_ptr<Market> market, const std::string& configuration, const std::string& domestic,
137 const std::string& foreign, std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>>& fxIndices)>&
138 getFxIndex,
139 const std::string& underlyingDerivativeId, RequiredFixings& fixings, std::vector<Leg>& returnLegs) const {
140 auto t = QuantLib::ext::dynamic_pointer_cast<ore::data::ForwardBond>(underlying);
141 QL_REQUIRE(t, "could not cast to ore::data::ForwardBond, this is unexpected");
142 auto qlBond = QuantLib::ext::dynamic_pointer_cast<QuantExt::ForwardBond>(underlying->instrument()->qlInstrument());
143 QL_REQUIRE(qlBond, "expected QuantExt::ForwardBond, could not cast");
144 auto futuresIndex = QuantLib::ext::make_shared<QuantExt::BondFuturesIndex>(
145 parseDate(t->fwdMaturityDate()), t->bondData().securityId(), true, false, NullCalendar(), qlBond->underlying());
146 underlyingIndex = futuresIndex;
147 underlyingMultiplier = t->bondData().bondNotional();
148
149 std::ostringstream o;
150 o << "BOND-" + t->bondData().securityId() << "-" << QuantLib::io::iso_date(parseDate(t->fwdMaturityDate()));
151 std::string name = o.str();
152 name.erase(name.length() - 3);
153 indexQuantities[name] = underlyingMultiplier;
154
155 Real adj = t->bondData().priceQuoteMethod() == QuantExt::BondIndex::PriceQuoteMethod::CurrencyPerUnit
156 ? 1.0 / t->bondData().priceQuoteBaseValue()
157 : 1.0;
158 if (initialPrice != Null<Real>())
159 initialPrice = initialPrice * qlBond->underlying()->notional(valuationDates.front()) * adj;
160 assetCurrency = t->bondData().currency();
161
162 auto fxIndex = getFxIndex(engineFactory->market(), engineFactory->configuration(MarketContext::pricing),
163 assetCurrency, fundingCurrency, fxIndices);
164
165 returnLegs.push_back(QuantExt::BondTRSLeg(valuationDates, paymentDates, underlyingMultiplier, futuresIndex, fxIndex)
166 .withInitialPrice(initialPrice));
167
168 if (!t->bondData().creditCurveId().empty())
169 creditRiskCurrency = t->bondData().currency();
170 creditQualifierMapping[securitySpecificCreditCurveName(t->bondData().securityId(), t->bondData().creditCurveId())] =
171 SimmCreditQualifierMapping(t->bondData().securityId(), t->bondData().creditGroup());
172 creditQualifierMapping[t->bondData().creditCurveId()] =
173 SimmCreditQualifierMapping(t->bondData().securityId(), t->bondData().creditGroup());
174}
175
176template <class T>
178 const std::string& parentId, const QuantLib::ext::shared_ptr<Trade>& underlying, const std::vector<Date>& valuationDates,
179 const std::vector<Date>& paymentDates, const std::string& fundingCurrency,
180 const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory, QuantLib::ext::shared_ptr<QuantLib::Index>& underlyingIndex,
181 Real& underlyingMultiplier, std::map<std::string, double>& indexQuantities,
182 std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>>& fxIndices, Real& initialPrice,
183 std::string& assetCurrency, std::string& creditRiskCurrency,
184 std::map<std::string, SimmCreditQualifierMapping>& creditQualifierMapping, Date& maturity,
185 const std::function<QuantLib::ext::shared_ptr<QuantExt::FxIndex>(
186 const QuantLib::ext::shared_ptr<Market> market, const std::string& configuration, const std::string& domestic,
187 const std::string& foreign, std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>>& fxIndices)>&
188 getFxIndex,
189 const std::string& underlyingDerivativeId, RequiredFixings& fixings, std::vector<Leg>& returnLegs) const {
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}
227
228template <>
230 QuantLib::ext::shared_ptr<EquityPosition> position, size_t i) const {
231 return position->indices()[i]->currency().code();
232}
233
234template <>
236 QuantLib::ext::shared_ptr<CommodityPosition> position, size_t i) const {
237 return position->indices()[i]->priceCurve()->currency().code();
238}
239
240template <class T>
242 QuantLib::ext::shared_ptr<T> position, size_t i) const {
243 QL_FAIL("internal error AssetPositionTrsUnderlyingBuilder only support Equity and Commodity positions");
244}
245
246template<>
247void AssetPositionTrsUnderlyingBuilder<ore::data::EquityPosition>::updateQuantities(std::map<std::string, double>& indexQuantities, const std::string& indexName, const double qty) const {
248 indexQuantities["EQ-" + indexName] = qty;
249}
250
251template <>
253 std::map<std::string, double>& indexQuantities, const std::string& indexName, const double qty) const {
254 indexQuantities["COMM-" + indexName] = qty;
255}
256
257template <class T>
258void AssetPositionTrsUnderlyingBuilder<T>::updateQuantities(std::map<std::string, double>& indexQuantities,
259 const std::string& indexName, const double qty) const {
260 QL_FAIL("internal error AssetPositionTrsUnderlyingBuilder only support Equity and Commodity positions");
261}
262
264 const std::string& parentId, const QuantLib::ext::shared_ptr<Trade>& underlying, const std::vector<Date>& valuationDates,
265 const std::vector<Date>& paymentDates, const std::string& fundingCurrency,
266 const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory, QuantLib::ext::shared_ptr<QuantLib::Index>& underlyingIndex,
267 Real& underlyingMultiplier, std::map<std::string, double>& indexQuantities,
268 std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>>& fxIndices, Real& initialPrice,
269 std::string& assetCurrency, std::string& creditRiskCurrency,
270 std::map<std::string, SimmCreditQualifierMapping>& creditQualifierMapping, Date& maturity,
271 const std::function<QuantLib::ext::shared_ptr<QuantExt::FxIndex>(
272 const QuantLib::ext::shared_ptr<Market> market, const std::string& configuration, const std::string& domestic,
273 const std::string& foreign, std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>>& fxIndices)>&
274 getFxIndex,
275 const std::string& underlyingDerivativeId, RequiredFixings& fixings, std::vector<Leg>& returnLegs) const {
276 auto t = QuantLib::ext::dynamic_pointer_cast<ore::data::EquityOptionPosition>(underlying);
277 QL_REQUIRE(t, "could not cast to ore::data::EquityOptionPosition, this is unexpected");
278 if (t->isSingleCurrency()) {
279 assetCurrency = t->npvCurrency();
280 DLOG("underlying equity option position is single-currency, assetCurrency is " << assetCurrency);
281 } else {
282 // asset currency is set to funding currency data currency in trs as a default
283 // we use fxSpot() as opposed to fxRate() here to ensure consistency between NPV() and the fixing of an
284 // equivalent index representing the same basket
285 t->setNpvCurrencyConversion(
286 assetCurrency, engineFactory->market()->fxSpot(t->npvCurrency() + assetCurrency,
287 engineFactory->configuration(MarketContext::pricing)));
288 DLOG("underlying equity option position is multi-currency, set assetCurrency to fundingCurrency = "
289 << assetCurrency);
290 }
291 std::vector<QuantLib::ext::shared_ptr<QuantExt::FxIndex>> fxConversion(t->data().underlyings().size());
292 std::vector<QuantLib::ext::shared_ptr<QuantLib::Index>> indices;
293 for (auto const& i : t->historicalPriceIndices()) {
294 indices.push_back(i);
295 DLOG("underlying historical equity option price index " << i->name() << " added.");
296 }
297 QL_REQUIRE(indices.size() == t->data().underlyings().size(),
298 "underlying historical price indices size (" << indices.size() << ") must match underlyings size ("
299 << t->data().underlyings().size());
300 for (Size i = 0; i < t->data().underlyings().size(); ++i) {
301 fxConversion[i] = getFxIndex(engineFactory->market(), engineFactory->configuration(MarketContext::pricing),
302 assetCurrency, t->currencies()[i], fxIndices);
303 indexQuantities[indices[i]->name()] = t->weights()[i] * t->positions()[i];
304 }
305 std::vector<Real> w;
306 for (Size i = 0; i < t->weights().size(); ++i) {
307 w.push_back(t->weights()[i] * t->positions()[i]);
308 }
309 underlyingIndex =
310 QuantLib::ext::make_shared<QuantExt::CompositeIndex>("Composite Index trade id " + parentId, indices, w, fxConversion);
311 DLOG("underlying equity option historical price index built with " << indices.size() << " constituents.");
312 underlyingMultiplier = t->data().quantity();
313
314 auto fxIndex = getFxIndex(engineFactory->market(), engineFactory->configuration(MarketContext::pricing),
315 assetCurrency, fundingCurrency, fxIndices);
316
317 returnLegs.push_back(QuantExt::TRSLeg(valuationDates, paymentDates, underlyingMultiplier, underlyingIndex, fxIndex)
318 .withInitialPrice(initialPrice));
319}
320
322 const std::string& parentId, const QuantLib::ext::shared_ptr<Trade>& underlying, const std::vector<Date>& valuationDates,
323 const std::vector<Date>& paymentDates, const std::string& fundingCurrency,
324 const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory, QuantLib::ext::shared_ptr<QuantLib::Index>& underlyingIndex,
325 Real& underlyingMultiplier, std::map<std::string, double>& indexQuantities,
326 std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>>& fxIndices, Real& initialPrice,
327 std::string& assetCurrency, std::string& creditRiskCurrency,
328 std::map<std::string, SimmCreditQualifierMapping>& creditQualifierMapping, Date& maturity,
329 const std::function<QuantLib::ext::shared_ptr<QuantExt::FxIndex>(
330 const QuantLib::ext::shared_ptr<Market> market, const std::string& configuration, const std::string& domestic,
331 const std::string& foreign, std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>>& fxIndices)>&
332 getFxIndex,
333 const std::string& underlyingDerivativeId, RequiredFixings& fixings, std::vector<Leg>& returnLegs) const {
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}
395
397 const std::string& parentId, const QuantLib::ext::shared_ptr<Trade>& underlying, const std::vector<Date>& valuationDates,
398 const std::vector<Date>& paymentDates, const std::string& fundingCurrency,
399 const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory, QuantLib::ext::shared_ptr<QuantLib::Index>& underlyingIndex,
400 Real& underlyingMultiplier, std::map<std::string, double>& indexQuantities,
401 std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>>& fxIndices, Real& initialPrice,
402 std::string& assetCurrency, std::string& creditRiskCurrency,
403 std::map<std::string, SimmCreditQualifierMapping>& creditQualifierMapping, Date& maturity,
404 const std::function<QuantLib::ext::shared_ptr<QuantExt::FxIndex>(
405 const QuantLib::ext::shared_ptr<Market> market, const std::string& configuration, const std::string& domestic,
406 const std::string& foreign, std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>>& fxIndices)>&
407 getFxIndex,
408 const std::string& underlyingDerivativeId, RequiredFixings& fixings, std::vector<Leg>& returnLegs) const {
409 assetCurrency = underlying->npvCurrency();
410 auto indexName = "GENERIC-" + underlyingDerivativeId;
411 IndexNameTranslator::instance().add(indexName, indexName);
412 underlyingIndex = QuantLib::ext::make_shared<QuantExt::GenericIndex>(indexName);
413 indexQuantities[indexName] = 1.0;
414 underlyingMultiplier = 1.0;
415 // FIXME same question as for single bond underlying: shouldn't we leave that empty and let TRS determine the
416 // maturity date based on valuation / funding dates?
417 maturity = underlying->maturity();
418
419 auto fxIndex = getFxIndex(engineFactory->market(), engineFactory->configuration(MarketContext::pricing),
420 assetCurrency, fundingCurrency, fxIndices);
421 returnLegs.push_back(QuantExt::TRSLeg(valuationDates, paymentDates, underlyingMultiplier, underlyingIndex, fxIndex)
422 .withInitialPrice(initialPrice));
423}
424
427
428} // namespace data
429} // namespace ore
Bond trade data model and serialization.
Bond Position trade data model and serialization.
BondTRSLeg & withInitialPrice(Real)
const string & currency() const
Definition: bond.hpp:94
const string & issueDate() const
Definition: bond.hpp:90
Real bondNotional() const
Definition: bond.hpp:95
const BondData & bondData() const
inspectors
Definition: bond.hpp:166
QuantLib::Real priceAdjustment(QuantLib::Real price)
QuantLib::ext::shared_ptr< QuantExt::BondIndex > bondIndex() const
void addRequiredFixings(RequiredFixings &requiredFixings, Leg leg={})
map< std::string, QuantLib::ext::shared_ptr< TrsUnderlyingBuilder > > builders_
void addBuilder(const std::string &tradeType, const QuantLib::ext::shared_ptr< TrsUnderlyingBuilder > &builder, const bool allowOverwrite=false)
QuantLib::ext::shared_ptr< TrsUnderlyingBuilder > getBuilder(const std::string &tradeType) const
Equity Option Position trade data model and serialization.
Equity Position trade data model and serialization.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
translates between QuantLib::Index::name() and ORE names
@ data
Definition: log.hpp:77
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
market data related utilties
Time maturity
Definition: utilities.cpp:66
Size size(const ValueType &v)
Definition: value.cpp:145
void modifyBondTRSLeg(QuantLib::Leg &leg, QuantLib::Date issueDate)
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)
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.
void updateQuantities(std::map< std::string, double > &indexQuantities, const std::string &indexName, const double qty) const
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
std::string getIndexCurrencyFromPosition(QuantLib::ext::shared_ptr< T > position, size_t i) const
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 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 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 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 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
string name