Skip to content

Commit 3471082

Browse files
pcaspersjenkins
authored andcommitted
QPR-12014 populate sensi template in all trade builders
1 parent b77cf52 commit 3471082

52 files changed

Lines changed: 113 additions & 11 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

OREData/ored/portfolio/ascot.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void Ascot::build(const boost::shared_ptr<ore::data::EngineFactory>& engineFacto
7272
auto qlAscot =
7373
boost::make_shared<QuantExt::Ascot>(type, exercise, bond_.data().bondData().bondNotional(), cb, fundingLeg);
7474
qlAscot->setPricingEngine(builder->engine(id(), bond_.data().bondData().currency()));
75+
setSensitivityTemplate(*builder);
7576

7677
Real multiplier = (parsePositionType(optionData_.longShort()) == Position::Long ? 1.0 : -1.0);
7778
instrument_ =

OREData/ored/portfolio/asianoption.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ void AsianOption::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
158158
string configuration = asianOptionBuilder->configuration(MarketContext::pricing);
159159
if (!asian->isExpired()) {
160160
asian->setPricingEngine(asianOptionBuilder->engine(assetName_, payCcy, expiryDate));
161+
setSensitivityTemplate(*asianOptionBuilder);
161162
} else {
162163
DLOG("No engine attached for option on trade " << id() << " with expiry date " << io::iso_date(expiryDate)
163164
<< " because it is expired.");

OREData/ored/portfolio/bond.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ void Bond::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
268268
QL_REQUIRE(bondBuilder, "No Builder found for Bond: " << id());
269269
bond->setPricingEngine(bondBuilder->engine(currency, bondData_.creditCurveId(), bondData_.hasCreditRisk(),
270270
bondData_.securityId(), bondData_.referenceCurveId()));
271+
setSensitivityTemplate(*bondBuilder);
271272
instrument_.reset(new VanillaInstrument(bond, mult));
272273

273274
npvCurrency_ = bondData_.currency();

OREData/ored/portfolio/bondoption.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ void BondOption::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
113113
bondOptionBuilder->engine(id(), currency, bondData_.creditCurveId(), bondData_.hasCreditRisk(),
114114
bondData_.securityId(), bondData_.referenceCurveId(), bondData_.volatilityCurveId()));
115115
bondoption->setPricingEngine(blackEngine);
116+
setSensitivityTemplate(*bondOptionBuilder);
116117

117118
Real multiplier =
118119
bondData_.bondNotional() * (parsePositionType(optionData_.longShort()) == Position::Long ? 1.0 : -1.0);

OREData/ored/portfolio/bondrepo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ void BondRepo::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
102102

103103
qlInstr->setPricingEngine(builder->engine(securityLegData_.incomeCurveId()));
104104
instrument_ = boost::make_shared<VanillaInstrument>(qlInstr);
105+
setSensitivityTemplate(*builder);
105106

106107
// set additionalData
107108
additionalData_["underlyingSecurityId"] = securityLegData_.securityId();

OREData/ored/portfolio/bondtotalreturnswap.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ void BondTRS::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
186186
boost::dynamic_pointer_cast<BondTRSEngineBuilder>(builder_trs);
187187
QL_REQUIRE(trsBondBuilder, "No Builder found for BondTRS: " << id());
188188
bondTRS->setPricingEngine(trsBondBuilder->engine(fundingLegData_.currency()));
189+
setSensitivityTemplate(*trsBondBuilder);
189190
instrument_.reset(new VanillaInstrument(bondTRS));
190191

191192
npvCurrency_ = fundingLegData_.currency();

OREData/ored/portfolio/capfloor.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ void CapFloor::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
117117
boost::dynamic_pointer_cast<SwapEngineBuilderBase>(builder);
118118
QL_REQUIRE(swapBuilder, "No Builder found for Swap " << id());
119119
qlInstrument->setPricingEngine(swapBuilder->engine(parseCurrency(legData_.currency())));
120+
setSensitivityTemplate(*swapBuilder);
120121
} else {
121122
qlInstrument->setPricingEngine(
122123
boost::make_shared<DiscountingSwapEngine>(engineFactory->market()->discountCurve(legData_.currency())));
@@ -156,6 +157,7 @@ void CapFloor::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
156157
boost::shared_ptr<CapFloorEngineBuilder> capFloorBuilder =
157158
boost::dynamic_pointer_cast<CapFloorEngineBuilder>(builder);
158159
qlInstrument->setPricingEngine(capFloorBuilder->engine(underlyingIndex));
160+
setSensitivityTemplate(*capFloorBuilder);
159161

160162
maturity_ = boost::dynamic_pointer_cast<QuantLib::CapFloor>(qlInstrument)->maturityDate();
161163
}
@@ -186,8 +188,17 @@ void CapFloor::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
186188
// the StrippedCappedFlooredCoupon used to extract the naked options assumes a long floor
187189
// and a short cap while we have documented a collar to be a short floor and long cap
188190
qlInstrument = boost::make_shared<QuantLib::Swap>(legs_, std::vector<bool>{!floors_.empty() && !caps_.empty()});
189-
qlInstrument->setPricingEngine(
190-
boost::make_shared<DiscountingSwapEngine>(engineFactory->market()->discountCurve(legData_.currency())));
191+
if (engineFactory->engineData()->hasProduct("Swap")) {
192+
builder = engineFactory->builder("Swap");
193+
boost::shared_ptr<SwapEngineBuilderBase> swapBuilder =
194+
boost::dynamic_pointer_cast<SwapEngineBuilderBase>(builder);
195+
QL_REQUIRE(swapBuilder, "No Builder found for Swap " << id());
196+
qlInstrument->setPricingEngine(swapBuilder->engine(parseCurrency(legData_.currency())));
197+
setSensitivityTemplate(*swapBuilder);
198+
} else {
199+
qlInstrument->setPricingEngine(
200+
boost::make_shared<DiscountingSwapEngine>(engineFactory->market()->discountCurve(legData_.currency())));
201+
}
191202
maturity_ = CashFlows::maturityDate(legs_.front());
192203

193204
} else if (legData_.legType() == "DurationAdjustedCMS") {
@@ -227,8 +238,17 @@ void CapFloor::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
227238
// the StrippedCappedFlooredCoupon used to extract the naked options assumes a long floor
228239
// and a short cap while we have documented a collar to be a short floor and long cap
229240
qlInstrument = boost::make_shared<QuantLib::Swap>(legs_, std::vector<bool>{!floors_.empty() && !caps_.empty()});
230-
qlInstrument->setPricingEngine(
231-
boost::make_shared<DiscountingSwapEngine>(engineFactory->market()->discountCurve(legData_.currency())));
241+
if (engineFactory->engineData()->hasProduct("Swap")) {
242+
builder = engineFactory->builder("Swap");
243+
boost::shared_ptr<SwapEngineBuilderBase> swapBuilder =
244+
boost::dynamic_pointer_cast<SwapEngineBuilderBase>(builder);
245+
QL_REQUIRE(swapBuilder, "No Builder found for Swap " << id());
246+
qlInstrument->setPricingEngine(swapBuilder->engine(parseCurrency(legData_.currency())));
247+
setSensitivityTemplate(*swapBuilder);
248+
} else {
249+
qlInstrument->setPricingEngine(
250+
boost::make_shared<DiscountingSwapEngine>(engineFactory->market()->discountCurve(legData_.currency())));
251+
}
232252
maturity_ = CashFlows::maturityDate(legs_.front());
233253
} else if (legData_.legType() == "CPI") {
234254
DLOG("CPI CapFloor Type " << capFloorType << " ID " << id());
@@ -345,6 +365,7 @@ void CapFloor::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
345365
Option::Call, nominal, startDate, baseCPI, paymentDate, cal, conv, cal, conv, caps_[i], zeroIndex,
346366
observationLag, interpolationMethod);
347367
capfloor->setPricingEngine(capFloorBuilder->engine(underlyingIndex));
368+
setSensitivityTemplate(*capFloorBuilder);
348369
boost::dynamic_pointer_cast<QuantLib::CompositeInstrument>(qlInstrument)->add(capfloor, gearing);
349370
maturity_ = std::max(maturity_, capfloor->payDate());
350371
}
@@ -356,6 +377,7 @@ void CapFloor::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
356377
Option::Put, nominal, startDate, baseCPI, paymentDate, cal, conv, cal, conv, floors_[i], zeroIndex,
357378
observationLag, interpolationMethod);
358379
capfloor->setPricingEngine(capFloorBuilder->engine(underlyingIndex));
380+
setSensitivityTemplate(*capFloorBuilder);
359381
boost::dynamic_pointer_cast<QuantLib::CompositeInstrument>(qlInstrument)->add(capfloor, sign * gearing);
360382
maturity_ = std::max(maturity_, capfloor->payDate());
361383
}
@@ -419,6 +441,7 @@ void CapFloor::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
419441
boost::shared_ptr<YoYCapFloorEngineBuilder> capFloorBuilder =
420442
boost::dynamic_pointer_cast<YoYCapFloorEngineBuilder>(builder);
421443
qlInstrument->setPricingEngine(capFloorBuilder->engine(underlyingIndex));
444+
setSensitivityTemplate(*capFloorBuilder);
422445

423446
// Wrap the QL instrument in a vanilla instrument
424447

OREData/ored/portfolio/cbo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ void CBO::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
109109
boost::shared_ptr<CboMCEngineBuilder> cboBuilder = boost::dynamic_pointer_cast<CboMCEngineBuilder>(builder);
110110
QL_REQUIRE(cboBuilder, "No Builder found for CBO: " << id());
111111
cbo->setPricingEngine(cboBuilder->engine(bondbasket_->pool()));
112+
setSensitivityTemplate(*cboBuilder);
112113
instrument_.reset(new VanillaInstrument(cbo, multiplier_));
113114

114115
maturity_ = schedule.endDate();
@@ -467,4 +468,4 @@ void CBO::validateCbo(){
467468
}
468469

469470
} // namespace data
470-
} // namespace ore
471+
} // namespace ore

OREData/ored/portfolio/cdo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ void SyntheticCDO::build(const boost::shared_ptr<EngineFactory>& engineFactory)
548548

549549
cdoDetach->setPricingEngine(
550550
cdoEngineBuilder->engine(ccy, false, {}, calibrationFactor, fixedRecovery));
551+
setSensitivityTemplate(*cdoEngineBuilder);
551552
cdoD = cdoDetach;
552553

553554
DLOG("Detachment tranche [0," << adjDetachPoint << "] built.");
@@ -566,6 +567,7 @@ void SyntheticCDO::build(const boost::shared_ptr<EngineFactory>& engineFactory)
566567

567568
cds->setPricingEngine(
568569
cdoEngineBuilder->engine(ccy, true, creditCurves, calibrationFactor, fixedRecovery));
570+
setSensitivityTemplate(*cdoEngineBuilder);
569571
cdoD = cds;
570572

571573
DLOG("Index CDS for [0,1.0] 'tranche' built.");
@@ -593,6 +595,7 @@ void SyntheticCDO::build(const boost::shared_ptr<EngineFactory>& engineFactory)
593595

594596
cdoA->setPricingEngine(
595597
cdoEngineBuilder->engine(ccy, false, {}, calibrationFactor, fixedRecovery));
598+
setSensitivityTemplate(*cdoEngineBuilder);
596599

597600
DLOG("Attachment tranche [0," << adjAttachPoint << "] built.");
598601

OREData/ored/portfolio/cliquetoption.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void CliquetOption::build(const boost::shared_ptr<EngineFactory>& engineFactory)
7878
boost::dynamic_pointer_cast<CliquetOptionEngineBuilder>(builder);
7979

8080
cliquet->setPricingEngine(cliquetOptionBuilder->engine(name(), ccy));
81+
setSensitivityTemplate(*cliquetOptionBuilder);
8182

8283
instrument_ = boost::shared_ptr<InstrumentWrapper>(new VanillaInstrument(cliquet));
8384

0 commit comments

Comments
 (0)