Skip to content

Commit bb5b9d0

Browse files
committed
QPR-13666 factor out makeInstrument() and enable different conventions per given par instrument
1 parent b1a5c92 commit bb5b9d0

2 files changed

Lines changed: 70 additions & 94 deletions

File tree

OREAnalytics/orea/engine/parsensitivityinstrumentbuilder.cpp

Lines changed: 61 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,42 @@ using boost::numeric::ublas::element_prod;
8181
namespace ore {
8282
namespace analytics {
8383

84+
std::pair<QuantLib::ext::shared_ptr<Instrument>, Date> ParSensitivityInstrumentBuilder::makeInstrument(
85+
const std::string& instType, const QuantLib::Date& asof, const QuantLib::ext::shared_ptr<Market>& market,
86+
string ccy, string otherCcy, string curveName, string yieldCurveName, string equityForecastCurveName, Period term,
87+
const QuantLib::ext::shared_ptr<Convention>& convention, bool singleCurve,
88+
std::set<ore::analytics::RiskFactorKey>& parHelperDependencies, std::set<std::string>& removeTodaysFixingIndices,
89+
const string& expDiscountCurve, const string& marketConfiguration) const {
90+
string instType3 = instType.substr(0, 3);
91+
if (instType3 == "IRS")
92+
return makeSwap(market, ccy, curveName, yieldCurveName, equityForecastCurveName, term, convention, singleCurve,
93+
parHelperDependencies, removeTodaysFixingIndices, expDiscountCurve, marketConfiguration);
94+
else if (instType3 == "DEP")
95+
return makeDeposit(asof, market, ccy, curveName, yieldCurveName, equityForecastCurveName, term, convention,
96+
marketConfiguration);
97+
else if (instType3 == "FRA")
98+
return makeFRA(asof, market, ccy, curveName, yieldCurveName, equityForecastCurveName, term, convention,
99+
marketConfiguration);
100+
else if (instType3 == "OIS")
101+
return makeOIS(market, ccy, curveName, yieldCurveName, equityForecastCurveName, term, convention, singleCurve,
102+
parHelperDependencies, removeTodaysFixingIndices, expDiscountCurve, marketConfiguration);
103+
else if (instType3 == "XBS")
104+
return makeCrossCcyBasisSwap(market, otherCcy, ccy, term, convention, parHelperDependencies,
105+
removeTodaysFixingIndices, marketConfiguration);
106+
else if (instType3 == "FXF")
107+
return makeFxForward(market, otherCcy, ccy, term, convention, parHelperDependencies, marketConfiguration);
108+
else if (instType3 == "TBS")
109+
return makeTenorBasisSwap(asof, market, ccy, std::string(), std::string(), std::string(), std::string(), term,
110+
convention, singleCurve, parHelperDependencies, removeTodaysFixingIndices,
111+
expDiscountCurve, marketConfiguration);
112+
else if (instType3 == "BMA")
113+
return makeBMABasisSwap(asof, market, ccy, std::string(), std::string(), std::string(), std::string(), term,
114+
convention, singleCurve, parHelperDependencies, removeTodaysFixingIndices,
115+
expDiscountCurve, marketConfiguration);
116+
else
117+
return std::make_pair(nullptr, Date());
118+
}
119+
84120
void ParSensitivityInstrumentBuilder::createParInstruments(
85121
ParSensitivityInstrumentBuilder::Instruments& instruments, const QuantLib::Date& asof,
86122
const QuantLib::ext::shared_ptr<ore::analytics::ScenarioSimMarketParameters>& simMarketParams,
@@ -166,39 +202,13 @@ void ParSensitivityInstrumentBuilder::createParInstruments(
166202
QuantLib::ext::shared_ptr<Convention> convention = conventions->get(conventionsMap[instType]);
167203
QL_REQUIRE(convention != nullptr,
168204
"ParSensitivityInstrumentBuilder::createParInstruments(): convention is empty");
169-
if (instType == "IRS")
170-
ret = makeSwap(simMarket, ccy, indexName, yieldCurveName, equityForecastCurveName, term,
171-
convention, singleCurve, parHelperDependencies[key],
172-
instruments.removeTodaysFixingIndices_, data.discountCurve, marketConfiguration);
173-
else if (instType == "DEP")
174-
ret = makeDeposit(asof, simMarket, ccy, indexName, yieldCurveName, equityForecastCurveName,
175-
term, convention, marketConfiguration);
176-
else if (instType == "FRA")
177-
ret = makeFRA(asof, simMarket, ccy, indexName, yieldCurveName, equityForecastCurveName, term,
178-
convention, marketConfiguration);
179-
else if (instType == "OIS")
180-
ret = makeOIS(simMarket, ccy, indexName, yieldCurveName, equityForecastCurveName, term,
181-
convention, singleCurve, parHelperDependencies[key],
182-
instruments.removeTodaysFixingIndices_, data.discountCurve, marketConfiguration);
183-
else if (instType == "XBS")
184-
ret = makeCrossCcyBasisSwap(
185-
simMarket, data.otherCurrency.empty() ? simMarketParams->baseCcy() : data.otherCurrency,
186-
ccy, term, convention, parHelperDependencies[key], instruments.removeTodaysFixingIndices_,
187-
marketConfiguration);
188-
else if (instType == "FXF")
189-
ret = makeFxForward(
190-
simMarket, data.otherCurrency.empty() ? simMarketParams->baseCcy() : data.otherCurrency,
191-
ccy, term, convention, parHelperDependencies[key], marketConfiguration);
192-
else if (instType == "TBS")
193-
ret = makeTenorBasisSwap(asof, simMarket, ccy, "", "", "", "", term, convention, singleCurve,
194-
parHelperDependencies[key], instruments.removeTodaysFixingIndices_,
195-
data.discountCurve, marketConfiguration);
196-
else if (instType == "BMA")
197-
ret = makeBMABasisSwap(asof, simMarket, ccy, "", "", "", "", term, convention, singleCurve,
198-
parHelperDependencies[key], instruments.removeTodaysFixingIndices_,
199-
data.discountCurve, marketConfiguration);
200-
else
201-
recognised = false;
205+
ret =
206+
makeInstrument(instType, asof, simMarket, ccy,
207+
data.otherCurrency.empty() ? simMarketParams->baseCcy() : data.otherCurrency,
208+
indexName, yieldCurveName, equityForecastCurveName, term, convention,
209+
singleCurve, parHelperDependencies[key], instruments.removeTodaysFixingIndices_,
210+
data.discountCurve, marketConfiguration);
211+
recognised = ret.first != nullptr;
202212
} catch (const std::exception& e) {
203213
skipped = true;
204214
if (continueOnError) {
@@ -268,37 +278,12 @@ void ParSensitivityInstrumentBuilder::createParInstruments(
268278
"ParSensitivityInstrumentBuilder::createParInstruments(): conventions not found for ccy "
269279
<< ccy << " and instrument type " << instType);
270280
QuantLib::ext::shared_ptr<Convention> convention = conventions->get(conventionsMap[instType]);
271-
272-
if (instType == "IRS")
273-
ret = makeSwap(simMarket, ccy, "", curveName, equityForecastCurveName, term, convention,
274-
singleCurve, parHelperDependencies[key], instruments.removeTodaysFixingIndices_,
275-
data.discountCurve, marketConfiguration);
276-
else if (instType == "DEP")
277-
ret = makeDeposit(asof, simMarket, ccy, "", curveName, equityForecastCurveName, term,
278-
convention, marketConfiguration);
279-
else if (instType == "FRA")
280-
ret = makeFRA(asof, simMarket, ccy, "", curveName, equityForecastCurveName, term, convention,
281-
marketConfiguration);
282-
else if (instType == "OIS")
283-
ret = makeOIS(simMarket, ccy, "", curveName, equityForecastCurveName, term, convention,
284-
singleCurve, parHelperDependencies[key], instruments.removeTodaysFixingIndices_,
285-
data.discountCurve, marketConfiguration);
286-
else if (instType == "TBS")
287-
ret = makeTenorBasisSwap(asof, simMarket, ccy, "", "", curveName, "", term, convention,
288-
singleCurve, parHelperDependencies[key],
289-
instruments.removeTodaysFixingIndices_, data.discountCurve,
290-
marketConfiguration);
291-
else if (instType == "XBS")
292-
ret = makeCrossCcyBasisSwap(
293-
simMarket, data.otherCurrency.empty() ? simMarketParams->baseCcy() : data.otherCurrency,
294-
ccy, term, convention, parHelperDependencies[key], instruments.removeTodaysFixingIndices_,
295-
marketConfiguration);
296-
else if (instType == "BMA")
297-
ret = makeBMABasisSwap(asof, simMarket, ccy, "", "", "", "", term, convention, singleCurve,
298-
parHelperDependencies[key], instruments.removeTodaysFixingIndices_,
299-
data.discountCurve, marketConfiguration);
300-
else
301-
recognised = false;
281+
makeInstrument(instType, asof, simMarket, ccy,
282+
data.otherCurrency.empty() ? simMarketParams->baseCcy() : data.otherCurrency,
283+
std::string(), curveName, equityForecastCurveName, term, convention, singleCurve,
284+
parHelperDependencies[key], instruments.removeTodaysFixingIndices_,
285+
data.discountCurve, marketConfiguration);
286+
recognised = ret.first != nullptr;
302287
} catch (const std::exception& e) {
303288
skipped = true;
304289
if (continueOnError) {
@@ -365,31 +350,12 @@ void ParSensitivityInstrumentBuilder::createParInstruments(
365350
"ParSensitivityInstrumentBuilder::createParInstruments(): conventions not found for ccy "
366351
<< ccy << " and instrument type " << instType);
367352
QuantLib::ext::shared_ptr<Convention> convention = conventions->get(conventionsMap[instType]);
368-
369-
if (instType == "IRS")
370-
ret = makeSwap(simMarket, ccy, indexName, yieldCurveName, equityForecastCurveName, term,
371-
convention, singleCurve, parHelperDependencies[key],
372-
instruments.removeTodaysFixingIndices_, data.discountCurve, marketConfiguration);
373-
else if (instType == "DEP")
374-
ret = makeDeposit(asof, simMarket, ccy, indexName, yieldCurveName, equityForecastCurveName,
375-
term, convention, marketConfiguration);
376-
else if (instType == "FRA")
377-
ret = makeFRA(asof, simMarket, ccy, indexName, yieldCurveName, equityForecastCurveName, term,
378-
convention, marketConfiguration);
379-
else if (instType == "OIS")
380-
ret = makeOIS(simMarket, ccy, indexName, yieldCurveName, equityForecastCurveName, term,
381-
convention, singleCurve, parHelperDependencies[key],
382-
instruments.removeTodaysFixingIndices_, data.discountCurve, marketConfiguration);
383-
else if (instType == "TBS")
384-
ret = makeTenorBasisSwap(asof, simMarket, ccy, "", "", "", "", term, convention, singleCurve,
385-
parHelperDependencies[key], instruments.removeTodaysFixingIndices_,
386-
data.discountCurve, marketConfiguration);
387-
else if (instType == "BMA")
388-
ret = makeBMABasisSwap(asof, simMarket, ccy, "", "", "", "", term, convention, singleCurve,
389-
parHelperDependencies[key], instruments.removeTodaysFixingIndices_,
390-
data.discountCurve, marketConfiguration);
391-
else
392-
recognised = false;
353+
makeInstrument(instType, asof, simMarket, ccy,
354+
data.otherCurrency.empty() ? simMarketParams->baseCcy() : data.otherCurrency,
355+
indexName, yieldCurveName, equityForecastCurveName, term, convention, singleCurve,
356+
parHelperDependencies[key], instruments.removeTodaysFixingIndices_,
357+
data.discountCurve, marketConfiguration);
358+
recognised = ret.first != nullptr;
393359
} catch (const std::exception& e) {
394360
skipped = true;
395361
if (continueOnError) {
@@ -615,8 +581,8 @@ void ParSensitivityInstrumentBuilder::createParInstruments(
615581
"zero inflation curve "
616582
<< indexName << " and instrument type " << instType);
617583
QuantLib::ext::shared_ptr<Convention> convention = conventions->get(conventionsMap[instType]);
618-
619-
if (instType == "ZIS") {
584+
string instType3 = instType.substr(0, 3);
585+
if (instType3 == "ZIS") {
620586
auto tmp =
621587
makeYoyInflationSwap(simMarket, indexName, term, convention, singleCurve, true,
622588
parHelperDependencies[key], data.discountCurve, marketConfiguration);
@@ -627,7 +593,7 @@ void ParSensitivityInstrumentBuilder::createParInstruments(
627593
Date latestRelevantDate = std::max(helper->maturityDate(), lastCoupon->fixingDate());
628594
instruments.yoyInflationPillars_[indexName].push_back((latestRelevantDate - asof) * Days);
629595
parHelpers[key] = tmp;
630-
} else if (instType == "YYS") {
596+
} else if (instType3 == "YYS") {
631597
auto tmp =
632598
makeYoyInflationSwap(simMarket, indexName, term, convention, singleCurve, false,
633599
parHelperDependencies[key], data.discountCurve, marketConfiguration);
@@ -690,10 +656,11 @@ void ParSensitivityInstrumentBuilder::createParInstruments(
690656
<< indexName << " and instrument type " << instType);
691657
QuantLib::ext::shared_ptr<Convention> convention = conventions->get(conventionsMap[instType]);
692658
Period term = data.shiftExpiries[k];
693-
if (instType == "ZIS") {
659+
string instType3 = instType.substr(0, 3);
660+
if (instType3 == "ZIS") {
694661
makeYoYCapFloor(instruments, simMarket, indexName, term, strike, convention, singleCurve,
695662
true, data.discountCurve, key, marketConfiguration);
696-
} else if (instType == "YYS") {
663+
} else if (instType3 == "YYS") {
697664
makeYoYCapFloor(instruments, simMarket, indexName, term, strike, convention, singleCurve,
698665
false, data.discountCurve, key, marketConfiguration);
699666
} else

OREAnalytics/orea/engine/parsensitivityinstrumentbuilder.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ class ParSensitivityInstrumentBuilder {
7575
const QuantLib::ext::shared_ptr<ore::analytics::Market>& simMarket = nullptr) const;
7676

7777
private:
78+
//! Dispatcher into the rate curve related makeXXX() methods below
79+
std::pair<QuantLib::ext::shared_ptr<Instrument>, Date>
80+
makeInstrument(const std::string& instType, const QuantLib::Date& asof,
81+
const QuantLib::ext::shared_ptr<Market>& market, string ccy, string otherCcy, string curveName,
82+
string yieldCurveName, string equityForecastCurveName, Period term,
83+
const QuantLib::ext::shared_ptr<Convention>& convention, bool singleCurve,
84+
std::set<ore::analytics::RiskFactorKey>& parHelperDependencies,
85+
std::set<std::string>& removeTodaysFixingIndices, const string& expDiscountCurve,
86+
const string& marketConfiguration) const;
7887
//! Create Deposit for implying par rate sensitivity from zero rate sensitivity
7988
std::pair<QuantLib::ext::shared_ptr<QuantLib::Instrument>, Date>
8089
makeDeposit(const QuantLib::Date& asof, const QuantLib::ext::shared_ptr<ore::data::Market>& market, std::string ccy,

0 commit comments

Comments
 (0)