Skip to content

Commit 6517ca3

Browse files
pcaspersjenkins
authored andcommitted
QPR-12156 pass through market configuration to get fx curves
1 parent f8ab1dd commit 6517ca3

3 files changed

Lines changed: 18 additions & 15 deletions

File tree

OREData/ored/marketdata/fxtriangulation.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ std::pair<std::string, std::string> splitPair(const std::string& pair) {
4545
return std::make_pair(pair.substr(0, 3), pair.substr(3));
4646
}
4747

48-
Handle<YieldTermStructure> getMarketDiscountCurve(const Market* market, const std::string& ccy) {
48+
Handle<YieldTermStructure> getMarketDiscountCurve(const Market* market, const std::string& ccy,
49+
const std::string& configuration) {
4950
try {
50-
return market->discountCurve(ccy);
51+
return market->discountCurve(ccy, configuration);
5152
} catch (const std::exception&) {
5253
WLOG("FXTriangulation: could not get market discount curve '"
53-
<< ccy
54-
<< "' - discounted fx spot rates will be replaced by non-discounted rates in future calculations, which "
54+
<< ccy << "' (requested for configuration '" << configuration
55+
<< "') - discounted fx spot rates will be replaced by non-discounted rates in future calculations, which "
5556
"might lead to inaccuracies");
5657
return Handle<YieldTermStructure>();
5758
}
@@ -164,11 +165,12 @@ Handle<Quote> FXTriangulation::getQuote(const std::string& pair) const {
164165
return result;
165166
}
166167

167-
Handle<FxIndex> FXTriangulation::getIndex(const std::string& indexOrPair, const Market* market) const {
168+
Handle<FxIndex> FXTriangulation::getIndex(const std::string& indexOrPair, const Market* market,
169+
const std::string& configuration) const {
168170

169171
// do we have a cached result?
170172

171-
if (auto it = indexCache_.find(indexOrPair); it != indexCache_.end()) {
173+
if (auto it = indexCache_.find(std::make_pair(indexOrPair, configuration)); it != indexCache_.end()) {
172174
return it->second;
173175
}
174176

@@ -196,8 +198,8 @@ Handle<FxIndex> FXTriangulation::getIndex(const std::string& indexOrPair, const
196198

197199
// get the discount curves for the result index
198200

199-
auto sourceYts = getMarketDiscountCurve(market, forCcy);
200-
auto targetYts = getMarketDiscountCurve(market, domCcy);
201+
auto sourceYts = getMarketDiscountCurve(market, forCcy, configuration);
202+
auto targetYts = getMarketDiscountCurve(market, domCcy, configuration);
201203

202204
// get the path from ccy1 to ccy2
203205

@@ -227,8 +229,8 @@ Handle<FxIndex> FXTriangulation::getIndex(const std::string& indexOrPair, const
227229
// we store a quote "as of today" to account for possible spot lag differences
228230

229231
auto [fd, fc, bdc] = getFxIndexConventions(path[i] + path[i + 1]);
230-
auto s_yts = getMarketDiscountCurve(market, path[i]);
231-
auto t_yts = getMarketDiscountCurve(market, path[i + 1]);
232+
auto s_yts = getMarketDiscountCurve(market, path[i], configuration);
233+
auto t_yts = getMarketDiscountCurve(market, path[i + 1], configuration);
232234
quotes.push_back(Handle<Quote>(boost::make_shared<FxRateQuote>(q, s_yts, t_yts, fd, fc)));
233235
}
234236

@@ -253,7 +255,7 @@ Handle<FxIndex> FXTriangulation::getIndex(const std::string& indexOrPair, const
253255

254256
// add the result to the lookup cache and return it
255257

256-
indexCache_[indexOrPair] = result;
258+
indexCache_[std::make_pair(indexOrPair, configuration)] = result;
257259
return result;
258260
}
259261

OREData/ored/marketdata/fxtriangulation.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ class FXTriangulation {
5252
/*! Get fx index, possibly via triangulation. The index name can be of the form FX-TAG-CCY1-CCY2 or also
5353
be just a currency pair CCY1CCY2. In the latter case, the fixing source is set to TAG = GENERIC.
5454
The fx index requires discount curves from a market. The assumption is that the market provides discount
55-
curves consistent with cross-currency discounting under its default configuration. If the triangulation
55+
curves consistent with cross-currency discounting under the specified configuration. If the triangulation
5656
is not possible or required curves are not available an exception is thrown.
5757
*/
58-
QuantLib::Handle<QuantExt::FxIndex> getIndex(const std::string& indexOrPair, const Market* market) const;
58+
QuantLib::Handle<QuantExt::FxIndex> getIndex(const std::string& indexOrPair, const Market* market,
59+
const std::string& configuration) const;
5960

6061
private:
6162
/* get path for conversion forCcy => domCcy, throws if such a path does not exist */
@@ -73,7 +74,7 @@ class FXTriangulation {
7374

7475
// caches to improve perfomance
7576
mutable std::map<std::string, QuantLib::Handle<QuantLib::Quote>> quoteCache_;
76-
mutable std::map<std::string, QuantLib::Handle<QuantExt::FxIndex>> indexCache_;
77+
mutable std::map<std::pair<std::string, std::string>, QuantLib::Handle<QuantExt::FxIndex>> indexCache_;
7778

7879
// internal data structure to represent the undirected graph of currencies
7980
std::vector<std::string> nodeToCcy_;

OREData/ored/marketdata/marketimpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Handle<QuantLib::SwaptionVolatilityStructure> MarketImpl::yieldVol(const string&
199199
Handle<QuantExt::FxIndex> MarketImpl::fxIndexImpl(const string& fxIndex, const string& configuration) const {
200200
QL_REQUIRE(fx_ != nullptr,
201201
"MarketImpl::fxIndex(" << fxIndex << "): fx_ is null. This is an internal error. Contact dev.");
202-
return fx_->getIndex(fxIndex, this);
202+
return fx_->getIndex(fxIndex, this, configuration);
203203
}
204204

205205
Handle<Quote> MarketImpl::fxRateImpl(const string& ccypair, const string& configuration) const {

0 commit comments

Comments
 (0)