Get fx index, possibly via triangulation. The index name can be of the form FX-TAG-CCY1-CCY2 or also be just a currency pair CCY1CCY2. In the latter case, the fixing source is set to TAG = GENERIC. The fx index requires discount curves from a market. The assumption is that the market provides discount curves consistent with cross-currency discounting under the specified configuration. If the triangulation is not possible or required curves are not available an exception is thrown.
169 {
170
171
172
174 return it->second;
175 }
176
177
178
179 Handle<FxIndex> result;
180
181 std::string familyName;
182 std::string forCcy;
183 std::string domCcy;
184
187 familyName = ind->familyName();
188 forCcy = ind->sourceCurrency().code();
189 domCcy = ind->targetCurrency().code();
190 } else {
191 familyName = "GENERIC";
192 std::tie(forCcy, domCcy) = splitPair(indexOrPair);
193 }
194
195
196
198
199
200
201 auto sourceYts = getMarketDiscountCurve(market, forCcy, configuration);
202 auto targetYts = getMarketDiscountCurve(market, domCcy, configuration);
203
204
205
206 auto path =
getPath(forCcy, domCcy);
207
208 if (path.size() == 2) {
209
210
211
212 auto fxSpot =
getQuote(path[0], path[1]);
213 result = Handle<FxIndex>(QuantLib::ext::make_shared<FxIndex>(familyName, fixingDays,
parseCurrency(forCcy),
215 targetYts));
216
217 } else {
218
219
220
221 std::vector<Handle<Quote>> quotes;
222
223
224
225 for (Size i = 0; i < path.size() - 1; ++i) {
226
227 auto q =
getQuote(path[i], path[i + 1]);
228
229
230
232 auto s_yts = getMarketDiscountCurve(market, path[i], configuration);
233 auto t_yts = getMarketDiscountCurve(market, path[i + 1], configuration);
234 quotes.push_back(Handle<Quote>(QuantLib::ext::make_shared<FxRateQuote>(q, s_yts, t_yts, fd, fc)));
235 }
236
237
238
239 auto f = [](const std::vector<Real>& quotes) {
240 return std::accumulate(quotes.begin(), quotes.end(), 1.0, std::multiplies());
241 };
242 Handle<Quote> compQuote(QuantLib::ext::make_shared<
CompositeVectorQuote<
decltype(f)>>(quotes, f));
243
244
245
246 Handle<Quote> spotQuote(
247 QuantLib::ext::make_shared<FxSpotQuote>(compQuote, sourceYts, targetYts, fixingDays, fixingCalendar));
248
249
250
251 result = Handle<FxIndex>(QuantLib::ext::make_shared<FxIndex>(familyName, fixingDays,
parseCurrency(forCcy),
253 sourceYts, targetYts));
254 }
255
256
257
258 indexCache_[std::make_pair(indexOrPair, configuration)] = result;
259 return result;
260}
std::map< std::pair< std::string, std::string >, QuantLib::Handle< QuantExt::FxIndex > > indexCache_
QuantLib::ext::shared_ptr< FxIndex > parseFxIndex(const string &s, const Handle< Quote > &fxSpot, const Handle< YieldTermStructure > &sourceYts, const Handle< YieldTermStructure > &targetYts, const bool useConventions)
Convert std::string to QuantExt::FxIndex.
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
bool isFxIndex(const std::string &indexName)
std::tuple< Natural, Calendar, BusinessDayConvention > getFxIndexConventions(const string &index)