Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
marketimpl.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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
19#include <boost/algorithm/string.hpp>
20#include <boost/make_shared.hpp>
27
28using namespace std;
29using std::make_pair;
30using std::map;
31using std::string;
32
33using namespace QuantLib;
34
38
39namespace ore {
40namespace data {
41
42namespace {
43
44template <class A, class B, class C>
45A lookup(const B& map, const C& key, const string& configuration, const string& type, bool continueOnError = false) {
46 auto it = map.find(make_pair(configuration, key));
47 if (it == map.end()) {
48 // fall back to default configuration
49 it = map.find(make_pair(Market::defaultConfiguration, key));
50 if (it == map.end()) {
51 if (!continueOnError)
52 QL_FAIL("did not find object '" << key << "' of type " << type
53 << " under configuration '" << configuration << "' or 'default'");
54 else
55 return A();
56 }
57 }
58 return it->second;
59}
60
61template <class A, class B, class C>
62A lookup(const B& map, const C& key, const YieldCurveType y, const string& configuration, const string& type) {
63 auto it = map.find(make_tuple(configuration, y, key));
64 if (it == map.end()) {
65 // fall back to default configuration
66 it = map.find(make_tuple(Market::defaultConfiguration, y, key));
67 QL_REQUIRE(it != map.end(), "did not find object " << key << " of type " << type << " under configuration '"
68 << configuration << "' or 'default' in YieldCurves");
69 }
70 return it->second;
71}
72} // anonymous namespace
73
74Handle<YieldTermStructure> MarketImpl::yieldCurve(const YieldCurveType& type, const string& key,
75 const string& configuration) const {
76 // we allow for standard (i.e. not convention based) ibor index names as keys and return the index forward curve in
77 // case of a match
78 QuantLib::ext::shared_ptr<IborIndex> notUsed;
79 if (tryParseIborIndex(key, notUsed)) {
80 return iborIndex(key, configuration)->forwardingTermStructure();
81 }
82 // no ibor index found under key => look for a genuine yield curve
83 DLOG("no ibor index found under '" << key << "' - look for a genuine yield curve");
84 if (type == YieldCurveType::Discount)
85 require(MarketObject::DiscountCurve, key, configuration);
86 else if (type == YieldCurveType::Yield)
87 require(MarketObject::YieldCurve, key, configuration);
88 else if (type == YieldCurveType::EquityDividend)
89 require(MarketObject::EquityCurve, key, configuration);
90 else {
91 QL_FAIL("yield curve type not handled");
92 }
93 return lookup<Handle<YieldTermStructure>>(yieldCurves_, key, type, configuration, "yield curve / ibor index");
94}
95
96Handle<YieldTermStructure> MarketImpl::discountCurveImpl(const string& key, const string& configuration) const {
97 require(MarketObject::DiscountCurve, key, configuration);
98 return lookup<Handle<YieldTermStructure>>(yieldCurves_, key, YieldCurveType::Discount, configuration,
99 "discount curve");
100}
101
102Handle<YieldTermStructure> MarketImpl::yieldCurve(const string& key, const string& configuration) const {
103 require(MarketObject::YieldCurve, key, configuration);
104 return yieldCurve(YieldCurveType::Yield, key, configuration);
105}
106
107Handle<IborIndex> MarketImpl::iborIndex(const string& key, const string& configuration) const {
108 require(MarketObject::IndexCurve, key, configuration);
109 return lookup<Handle<IborIndex>>(iborIndices_, key, configuration, "ibor index");
110}
111
112Handle<SwapIndex> MarketImpl::swapIndex(const string& key, const string& configuration) const {
113 require(MarketObject::SwapIndexCurve, key, configuration);
114 return lookup<Handle<SwapIndex>>(swapIndices_, key, configuration, "swap index");
115}
116
117Handle<QuantLib::SwaptionVolatilityStructure> MarketImpl::swaptionVol(const string& key,
118 const string& configuration) const {
119 require(MarketObject::SwaptionVol, key, configuration);
120 auto it = swaptionCurves_.find(make_pair(configuration, key));
121 if (it != swaptionCurves_.end())
122 return it->second;
123 // try the default config with the same key
124 if (configuration != Market::defaultConfiguration) {
126 auto it2 = swaptionCurves_.find(make_pair(Market::defaultConfiguration, key));
127 if (it2 != swaptionCurves_.end())
128 return it2->second;
129 }
130 // if key is an index name and we have a swaption curve for its ccy, we return that
131 QuantLib::ext::shared_ptr<IborIndex> index;
132 if (!tryParseIborIndex(key, index)) {
133 QL_FAIL("did not find swaption curve for key '" << key << "'");
134 }
135 auto ccy = index->currency().code();
136 require(MarketObject::SwaptionVol, ccy, configuration);
137 auto it3 = swaptionCurves_.find(make_pair(configuration, ccy));
138 if (it3 != swaptionCurves_.end()) {
139 return it3->second;
140 }
141 // check if we have a curve for the ccy in the default config
142 if (configuration != Market::defaultConfiguration) {
143 require(MarketObject::SwaptionVol, ccy, configuration);
144 auto it4 = swaptionCurves_.find(make_pair(Market::defaultConfiguration, ccy));
145 if (it4 != swaptionCurves_.end())
146 return it4->second;
147 }
148 QL_FAIL("did not find swaption curve for key '" << key << "'");
149}
150
151pair<string, string> MarketImpl::swapIndexBases(const string& key, const string& configuration) const {
152 require(MarketObject::SwaptionVol, key, configuration);
153 auto it = swaptionIndexBases_.find(make_pair(configuration, key));
154 if (it != swaptionIndexBases_.end())
155 return it->second;
156 // try the default config with the same key
157 if (configuration != Market::defaultConfiguration) {
159 auto it2 = swaptionIndexBases_.find(make_pair(Market::defaultConfiguration, key));
160 if (it2 != swaptionIndexBases_.end())
161 return it2->second;
162 }
163 // if key is an index name and we have a swaption curve for its ccy, we return that
164 QuantLib::ext::shared_ptr<IborIndex> index;
165 if (!tryParseIborIndex(key, index)) {
166 QL_FAIL("did not find swaption index bases for key '" << key << "'");
167 }
168 auto ccy = index->currency().code();
169 require(MarketObject::SwaptionVol, ccy, configuration);
170 auto it3 = swaptionIndexBases_.find(make_pair(configuration, ccy));
171 if (it3 != swaptionIndexBases_.end()) {
172 return it3->second;
173 }
174 // check if we have a curve for the ccy in the default config
175 if (configuration != Market::defaultConfiguration) {
176 require(MarketObject::SwaptionVol, ccy, configuration);
177 auto it4 = swaptionIndexBases_.find(make_pair(Market::defaultConfiguration, ccy));
178 if (it4 != swaptionIndexBases_.end())
179 return it4->second;
180 }
181 QL_FAIL("did not find swaption index bases for key '" << key << "'");
182}
183
184string MarketImpl::shortSwapIndexBase(const string& key, const string& configuration) const {
185 return swapIndexBases(key, configuration).first;
186}
187
188string MarketImpl::swapIndexBase(const string& key, const string& configuration) const {
189 return swapIndexBases(key, configuration).second;
190}
191
192Handle<QuantLib::SwaptionVolatilityStructure> MarketImpl::yieldVol(const string& key,
193 const string& configuration) const {
194 require(MarketObject::YieldVol, key, configuration);
195 return lookup<Handle<QuantLib::SwaptionVolatilityStructure>>(yieldVolCurves_, key, configuration,
196 "yield volatility curve");
197}
198
199Handle<QuantExt::FxIndex> MarketImpl::fxIndexImpl(const string& fxIndex, const string& configuration) const {
200 QL_REQUIRE(fx_ != nullptr,
201 "MarketImpl::fxIndex(" << fxIndex << "): fx_ is null. This is an internal error. Contact dev.");
202 return fx_->getIndex(fxIndex, this, configuration);
203}
204
205Handle<Quote> MarketImpl::fxRateImpl(const string& ccypair, const string& configuration) const {
206 // if rate requested for a currency against itself, return 1.0
207 if (ccypair.substr(0,3) == ccypair.substr(3))
208 return Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(1.0));
209 return fxIndex(ccypair, configuration)->fxQuote();
210}
211
212Handle<Quote> MarketImpl::fxSpotImpl(const string& ccypair, const string& configuration) const {
213 if (ccypair.substr(0, 3) == ccypair.substr(3))
214 return Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(1.0));
215 return fxIndex(ccypair, configuration)->fxQuote(true);
216}
217
218Handle<BlackVolTermStructure> MarketImpl::fxVolImpl(const string& ccypair, const string& configuration) const {
219 require(MarketObject::FXVol, ccypair, configuration);
220 auto it = fxVols_.find(make_pair(configuration, ccypair));
221 if (it != fxVols_.end())
222 return it->second;
223 else {
224 // check for reverse EURUSD or USDEUR and add to the map
225 QL_REQUIRE(ccypair.length() == 6, "invalid ccy pair length");
226 std::string ccypairInverted = ccypair.substr(3, 3) + ccypair.substr(0, 3);
227 require(MarketObject::FXVol, ccypairInverted, configuration);
228 it = fxVols_.find(make_pair(configuration, ccypairInverted));
229 if (it != fxVols_.end()) {
230 Handle<BlackVolTermStructure> h(QuantLib::ext::make_shared<QuantExt::BlackInvertedVolTermStructure>(it->second));
231 h->enableExtrapolation();
232 // we have found a surface for the inverted pair.
233 // so we can invert the surface and store that under the original pair.
234 fxVols_[make_pair(configuration, ccypair)] = h;
235 return h;
236 } else {
237 if (configuration == Market::defaultConfiguration)
238 QL_FAIL("did not find fx vol object " << ccypair);
239 else
240 return fxVol(ccypair, Market::defaultConfiguration);
241 }
242 }
243}
244
245Handle<QuantExt::CreditCurve> MarketImpl::defaultCurve(const string& key, const string& configuration) const {
246 require(MarketObject::DefaultCurve, key, configuration);
247 return lookup<Handle<QuantExt::CreditCurve>>(defaultCurves_, key, configuration, "default curve");
248}
249
250Handle<Quote> MarketImpl::recoveryRate(const string& key, const string& configuration) const {
251 // recovery rates can be built together with default curve or securities
252 require(MarketObject::DefaultCurve, key, configuration);
253 require(MarketObject::Security, key, configuration);
254 return lookup<Handle<Quote>>(recoveryRates_, key, configuration, "recovery rate");
255}
256
257Handle<QuantExt::CreditVolCurve> MarketImpl::cdsVol(const string& key, const string& configuration) const {
258 require(MarketObject::CDSVol, key, configuration);
259 return lookup<Handle<QuantExt::CreditVolCurve>>(cdsVols_, key, configuration, "cds vol curve");
260}
261
262Handle<QuantExt::BaseCorrelationTermStructure>
263MarketImpl::baseCorrelation(const string& key, const string& configuration) const {
264 require(MarketObject::BaseCorrelation, key, configuration);
265 return lookup<Handle<QuantExt::BaseCorrelationTermStructure>>(baseCorrelations_, key, configuration,
266 "base correlation curve");
267}
268
269Handle<OptionletVolatilityStructure> MarketImpl::capFloorVol(const string& key, const string& configuration) const {
270 require(MarketObject::CapFloorVol, key, configuration);
271 auto it = capFloorCurves_.find(make_pair(configuration, key));
272 if (it != capFloorCurves_.end())
273 return it->second;
274 // first try the default config with the same key
275 if (configuration != Market::defaultConfiguration) {
277 auto it2 = capFloorCurves_.find(make_pair(Market::defaultConfiguration, key));
278 if (it2 != capFloorCurves_.end())
279 return it2->second;
280 }
281 // if key is an index name and we have a cap floor surface for its ccy, we return that
282 QuantLib::ext::shared_ptr<IborIndex> index;
283 if (!tryParseIborIndex(key, index)) {
284 QL_FAIL("did not find capfloor curve for key '" << key << "'");
285 }
286 auto ccy = index->currency().code();
287 require(MarketObject::CapFloorVol, ccy, configuration);
288 auto it3 = capFloorCurves_.find(make_pair(configuration, ccy));
289 if (it3 != capFloorCurves_.end()) {
290 return it3->second;
291 }
292 // check if we have a curve for the ccy in the default config
293 if (configuration != Market::defaultConfiguration) {
294 require(MarketObject::CapFloorVol, ccy, configuration);
295 auto it4 = capFloorCurves_.find(make_pair(Market::defaultConfiguration, ccy));
296 if (it4 != capFloorCurves_.end())
297 return it4->second;
298 }
299 QL_FAIL("did not find capfloor curve for key '" << key << "'");
300}
301
302std::pair<string, QuantLib::Period> MarketImpl::capFloorVolIndexBase(const string& key,
303 const string& configuration) const {
304 require(MarketObject::CapFloorVol, key, configuration);
305 auto it = capFloorIndexBase_.find(make_pair(configuration, key));
306 if (it != capFloorIndexBase_.end())
307 return it->second;
308 // first try the default config with the same key
309 if (configuration != Market::defaultConfiguration) {
311 auto it2 = capFloorIndexBase_.find(make_pair(Market::defaultConfiguration, key));
312 if (it2 != capFloorIndexBase_.end())
313 return it2->second;
314 }
315 // if key is an index name and we have a cap floor surface for its ccy, we return that
316 QuantLib::ext::shared_ptr<IborIndex> index;
317 if (!tryParseIborIndex(key, index)) {
318 return std::make_pair(string(),0*Days);
319 }
320 auto ccy = index->currency().code();
321 require(MarketObject::CapFloorVol, ccy, configuration);
322 auto it3 = capFloorIndexBase_.find(make_pair(configuration, ccy));
323 if (it3 != capFloorIndexBase_.end()) {
324 return it3->second;
325 }
326 // check if we have a curve for the ccy in the default config
327 if (configuration != Market::defaultConfiguration) {
328 require(MarketObject::CapFloorVol, ccy, configuration);
329 auto it4 = capFloorIndexBase_.find(make_pair(Market::defaultConfiguration, ccy));
330 if (it4 != capFloorIndexBase_.end())
331 return it4->second;
332 }
333 return std::make_pair(string(), 0 * Days);
334}
335
336Handle<YoYOptionletVolatilitySurface> MarketImpl::yoyCapFloorVol(const string& key, const string& configuration) const {
338 return lookup<Handle<YoYOptionletVolatilitySurface>>(yoyCapFloorVolSurfaces_, key, configuration,
339 "yoy inflation capfloor curve");
340}
341
342Handle<ZeroInflationIndex> MarketImpl::zeroInflationIndex(const string& indexName, const string& configuration) const {
343 require(MarketObject::ZeroInflationCurve, indexName, configuration);
344 return lookup<Handle<ZeroInflationIndex>>(zeroInflationIndices_, indexName, configuration, "zero inflation index");
345}
346
347Handle<YoYInflationIndex> MarketImpl::yoyInflationIndex(const string& indexName, const string& configuration) const {
348 require(MarketObject::YoYInflationCurve, indexName, configuration);
349 return lookup<Handle<YoYInflationIndex>>(yoyInflationIndices_, indexName, configuration, "yoy inflation index");
350}
351
352Handle<CPIVolatilitySurface> MarketImpl::cpiInflationCapFloorVolatilitySurface(const string& indexName,
353 const string& configuration) const {
354 require(MarketObject::ZeroInflationCapFloorVol, indexName, configuration);
355 return lookup<Handle<CPIVolatilitySurface>>(cpiInflationCapFloorVolatilitySurfaces_, indexName, configuration,
356 "cpi cap floor volatility surface");
357}
358
359Handle<Quote> MarketImpl::equitySpot(const string& key, const string& configuration) const {
360 require(MarketObject::EquityCurve, key, configuration);
361 return lookup<Handle<Quote>>(equitySpots_, key, configuration, "equity spot");
362}
363
364Handle<QuantExt::EquityIndex2> MarketImpl::equityCurve(const string& key, const string& configuration) const {
365 require(MarketObject::EquityCurve, key, configuration);
366 return lookup<Handle<QuantExt::EquityIndex2>>(equityCurves_, key, configuration, "equity curve");
367};
368
369Handle<YieldTermStructure> MarketImpl::equityDividendCurve(const string& key, const string& configuration) const {
370 require(MarketObject::EquityCurve, key, configuration);
371 return lookup<Handle<YieldTermStructure>>(yieldCurves_, key, YieldCurveType::EquityDividend, configuration,
372 "dividend yield curve");
373}
374
375Handle<BlackVolTermStructure> MarketImpl::equityVol(const string& key, const string& configuration) const {
376 require(MarketObject::EquityVol, key, configuration);
377 return lookup<Handle<BlackVolTermStructure>>(equityVols_, key, configuration, "equity vol curve");
378}
379
380Handle<YieldTermStructure> MarketImpl::equityForecastCurve(const string& eqName, const string& configuration) const {
381 require(MarketObject::EquityCurve, eqName, configuration);
382 return equityCurve(eqName, configuration)->equityForecastCurve();
383}
384
385Handle<Quote> MarketImpl::securitySpread(const string& key, const string& configuration) const {
386 require(MarketObject::Security, key, configuration);
387 return lookup<Handle<Quote>>(securitySpreads_, key, configuration, "security spread");
388}
389
390Handle<QuantExt::InflationIndexObserver> MarketImpl::baseCpis(const string& key, const string& configuration) const {
391 require(MarketObject::ZeroInflationCurve, key, configuration);
392 return lookup<Handle<QuantExt::InflationIndexObserver>>(baseCpis_, key, configuration, "base CPI");
393}
394
395Handle<PriceTermStructure> MarketImpl::commodityPriceCurve(const string& commodityName,
396 const string& configuration) const {
397 return commodityIndex(commodityName, configuration)->priceCurve();
398}
399
400Handle<CommodityIndex> MarketImpl::commodityIndex(const string& commodityName, const string& configuration) const {
401 require(MarketObject::CommodityCurve, commodityName, configuration);
402 return lookup<Handle<CommodityIndex>>(commodityIndices_, commodityName, configuration, "commodity indices");
403}
404
405Handle<BlackVolTermStructure> MarketImpl::commodityVolatility(const string& commodityName,
406 const string& configuration) const {
407 require(MarketObject::CommodityVolatility, commodityName, configuration);
408 return lookup<Handle<BlackVolTermStructure>>(commodityVols_, commodityName, configuration, "commodity volatility");
409}
410
411Handle<QuantExt::CorrelationTermStructure> MarketImpl::correlationCurve(const string& index1, const string& index2,
412 const string& configuration) const {
413 // straight pair
414 require(MarketObject::Correlation, index1 + "&" + index2, configuration);
415 auto it = correlationCurves_.find(make_tuple(configuration, index1, index2));
416 if (it != correlationCurves_.end())
417 return it->second;
418 // inverse pair
419 require(MarketObject::Correlation, index2 + "&" + index1, configuration);
420 it = correlationCurves_.find(make_tuple(configuration, index2, index1));
421 if (it != correlationCurves_.end())
422 return it->second;
423 // inverse fx index1
424 if (isFxIndex(index1)) {
425 require(MarketObject::Correlation, inverseFxIndex(index1) + "&" + index2, configuration);
426 it = correlationCurves_.find(make_tuple(configuration, inverseFxIndex(index1), index2));
427 if (it != correlationCurves_.end())
428 return Handle<QuantExt::CorrelationTermStructure>(
429 QuantLib::ext::make_shared<QuantExt::NegativeCorrelationTermStructure>(it->second));
430 require(MarketObject::Correlation, index2 + "&" + inverseFxIndex(index1), configuration);
431 it = correlationCurves_.find(make_tuple(configuration, index2, inverseFxIndex(index1)));
432 if (it != correlationCurves_.end())
433 return Handle<QuantExt::CorrelationTermStructure>(
434 QuantLib::ext::make_shared<QuantExt::NegativeCorrelationTermStructure>(it->second));
435 }
436 // inverse fx index2
437 if (isFxIndex(index2)) {
438 require(MarketObject::Correlation, index1 + "&" + inverseFxIndex(index2), configuration);
439 it = correlationCurves_.find(make_tuple(configuration, index1, inverseFxIndex(index2)));
440 if (it != correlationCurves_.end())
441 return Handle<QuantExt::CorrelationTermStructure>(
442 QuantLib::ext::make_shared<QuantExt::NegativeCorrelationTermStructure>(it->second));
443 require(MarketObject::Correlation, inverseFxIndex(index2) + "&" + index1, configuration);
444 it = correlationCurves_.find(make_tuple(configuration, inverseFxIndex(index2), index1));
445 if (it != correlationCurves_.end())
446 return Handle<QuantExt::CorrelationTermStructure>(
447 QuantLib::ext::make_shared<QuantExt::NegativeCorrelationTermStructure>(it->second));
448 }
449 // both fx indices inverted
450 if (isFxIndex(index1) && isFxIndex(index2)) {
451 require(MarketObject::Correlation, inverseFxIndex(index1) + "&" + inverseFxIndex(index2), configuration);
452 it = correlationCurves_.find(make_tuple(configuration, inverseFxIndex(index1), inverseFxIndex(index2)));
453 if (it != correlationCurves_.end())
454 return it->second;
455 require(MarketObject::Correlation, inverseFxIndex(index2) + "&" + inverseFxIndex(index1), configuration);
456 it = correlationCurves_.find(make_tuple(configuration, inverseFxIndex(index2), inverseFxIndex(index1)));
457 if (it != correlationCurves_.end())
458 return it->second;
459 }
460 // if not found, fall back to default configuration
461 if (configuration == Market::defaultConfiguration) {
462 QL_FAIL("did not find object " << index1 << "/" << index2 << " in CorrelationCurves");
463 } else {
464 return correlationCurve(index1, index2, Market::defaultConfiguration);
465 }
466}
467
468Handle<Quote> MarketImpl::cpr(const string& securityID, const string& configuration) const {
469 require(MarketObject::Security, securityID, configuration);
470 return lookup<Handle<Quote>>(cprs_, securityID, configuration, "cpr");
471}
472
473void MarketImpl::addSwapIndex(const string& swapIndex, const string& discountIndex, const string& configuration) const {
474 if (swapIndices_.find(make_pair(configuration, swapIndex)) != swapIndices_.end())
475 return;
476 try {
477 std::vector<string> tokens;
478 split(tokens, swapIndex, boost::is_any_of("-"));
479 QL_REQUIRE(tokens.size() == 3 || tokens.size() == 4,
480 "three or four tokens required in " << swapIndex << ": CCY-CMS-TENOR or CCY-CMS-TAG-TENOR");
481 QL_REQUIRE(tokens[0].size() == 3, "invalid currency code in " << swapIndex);
482 QL_REQUIRE(tokens[1] == "CMS", "expected CMS as second token in " << swapIndex);
483
484 Handle<YieldTermStructure> discounting, forwarding;
485 QuantLib::ext::shared_ptr<IborIndex> dummeyIndex;
486 if (tryParseIborIndex(discountIndex, dummeyIndex))
487 discounting = iborIndex(discountIndex, configuration)->forwardingTermStructure();
488 else
489 discounting = yieldCurve(discountIndex, configuration);
490
491 const QuantLib::ext::shared_ptr<Conventions>& conventions = InstrumentConventions::instance().conventions();
492 auto swapCon = QuantLib::ext::dynamic_pointer_cast<data::SwapIndexConvention>(conventions->get(swapIndex));
493 QL_REQUIRE(swapCon, "expected SwapIndexConvention for " << swapIndex);
494 auto conIbor = QuantLib::ext::dynamic_pointer_cast<data::IRSwapConvention>(conventions->get(swapCon->conventions()));
495 auto conOisComp = QuantLib::ext::dynamic_pointer_cast<data::OisConvention>(conventions->get(swapCon->conventions()));
496 auto conOisAvg = QuantLib::ext::dynamic_pointer_cast<data::AverageOisConvention>(conventions->get(swapCon->conventions()));
497 QL_REQUIRE(conIbor || conOisComp || conOisAvg,
498 "expected IRSwapConvention, OisConvention, AverageOisConvention for " << swapCon->conventions());
499
500 string fi = conIbor ? conIbor->indexName() : (conOisComp ? conOisComp->indexName() : conOisAvg->indexName());
501 if (isGenericIborIndex(fi))
502 forwarding = discounting;
503 else
504 forwarding = iborIndex(fi, configuration)->forwardingTermStructure();
505
506 QuantLib::ext::shared_ptr<SwapIndex> si = data::parseSwapIndex(swapIndex, forwarding, discounting);
507 swapIndices_[make_pair(configuration, swapIndex)] = Handle<SwapIndex>(si);
508 } catch (std::exception& e) {
509 QL_FAIL("Failure in MarketImpl::addSwapIndex() with index " << swapIndex << " : " << e.what());
510 }
511}
512
513void MarketImpl::refresh(const string& configuration) {
514
515 auto it = refreshTs_.find(configuration);
516 if (it == refreshTs_.end()) {
517 it = refreshTs_.insert(make_pair(configuration, std::set<QuantLib::ext::shared_ptr<TermStructure>>())).first;
518 }
519
520 if (it->second.empty()) {
521 for (auto& x : yieldCurves_) {
522 if (get<0>(x.first) == configuration || get<0>(x.first) == Market::defaultConfiguration)
523 it->second.insert(*x.second);
524 }
525 for (auto& x : iborIndices_) {
526 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration) {
527 Handle<YieldTermStructure> y = x.second->forwardingTermStructure();
528 if (!y.empty())
529 it->second.insert(*y);
530 }
531 }
532 for (auto& x : swapIndices_) {
533 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration) {
534 Handle<YieldTermStructure> y = x.second->forwardingTermStructure();
535 if (!y.empty())
536 it->second.insert(*y);
537 y = x.second->discountingTermStructure();
538 if (!y.empty())
539 it->second.insert(*y);
540 }
541 }
542 for (auto& x : swaptionCurves_) {
543 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration)
544 it->second.insert(*x.second);
545 }
546 for (auto& x : capFloorCurves_) {
547 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration)
548 it->second.insert(*x.second);
549 }
550 for (auto& x : yoyCapFloorVolSurfaces_) {
551 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration)
552 it->second.insert(*x.second);
553 }
554 for (auto& x : fxVols_) {
555 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration)
556 it->second.insert(*x.second);
557 }
558 for (auto& x : defaultCurves_) {
559 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration)
560 it->second.insert(*x.second->curve());
561 }
562 for (auto& x : cdsVols_) {
563 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration)
564 it->second.insert(*x.second);
565 }
566 for (auto& x : baseCorrelations_) {
567 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration)
568 it->second.insert(*x.second);
569 }
570 for (auto& x : zeroInflationIndices_) {
571 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration) {
572 it->second.insert(*x.second->zeroInflationTermStructure());
573 }
574 }
575 for (auto& x : yoyInflationIndices_) {
576 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration) {
577 it->second.insert(*x.second->yoyInflationTermStructure());
578 }
579 }
581 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration)
582 it->second.insert(*x.second);
583 }
584 for (auto& x : yoyCapFloorVolSurfaces_) {
585 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration)
586 it->second.insert(*x.second);
587 }
588 for (auto& x : equityVols_) {
589 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration)
590 it->second.insert(*x.second);
591 }
592 for (auto& x : equityCurves_) {
593 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration) {
594 Handle<YieldTermStructure> y = x.second->equityForecastCurve();
595 if (!y.empty())
596 it->second.insert(*y);
597 y = x.second->equityDividendCurve();
598 if (!y.empty())
599 it->second.insert(*y);
600 }
601 }
602 for (auto& x : commodityIndices_) {
603 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration) {
604 const auto& pts = x.second->priceCurve();
605 if (!pts.empty())
606 it->second.insert(*pts);
607 }
608 }
609 for (auto& x : commodityVols_) {
610 if (x.first.first == configuration || x.first.first == Market::defaultConfiguration)
611 it->second.insert(*x.second);
612 }
613
614 for (auto& x : correlationCurves_) {
615 if (get<0>(x.first) == configuration || get<0>(x.first) == Market::defaultConfiguration)
616 it->second.insert(*x.second);
617 }
618 }
619
620 // term structures might be wrappers around nested termstructures that need to be updated as well,
621 // therefore we need to call deepUpdate() (=update() if no such nesting is present)
622 for (auto& x : it->second)
623 x->deepUpdate();
624
625} // refresh
626
627} // namespace data
628} // namespace ore
Handle< BlackVolTermStructure > fxVol(const string &ccypair, const string &configuration=Market::defaultConfiguration) const
Definition: market.cpp:287
QuantLib::Handle< QuantExt::FxIndex > fxIndex(const string &fxIndex, const string &configuration=Market::defaultConfiguration) const
Definition: market.cpp:151
static const string defaultConfiguration
Default configuration label.
Definition: market.hpp:296
QuantLib::Handle< QuantExt::CommodityIndex > commodityIndex(const std::string &commodityName, const std::string &configuration=Market::defaultConfiguration) const override
Commodity index.
Definition: marketimpl.cpp:400
map< pair< string, string >, Handle< OptionletVolatilityStructure > > capFloorCurves_
Definition: marketimpl.hpp:219
string shortSwapIndexBase(const string &key, const string &configuration=Market::defaultConfiguration) const override
Definition: marketimpl.cpp:184
string swapIndexBase(const string &key, const string &configuration=Market::defaultConfiguration) const override
Definition: marketimpl.cpp:188
Handle< Quote > securitySpread(const string &securityID, const string &configuration=Market::defaultConfiguration) const override
Bond Spreads.
Definition: marketimpl.cpp:385
Handle< QuantExt::BaseCorrelationTermStructure > baseCorrelation(const string &name, const string &configuration=Market::defaultConfiguration) const override
Base correlation structures.
Definition: marketimpl.cpp:263
Handle< QuantLib::SwaptionVolatilityStructure > swaptionVol(const string &key, const string &configuration=Market::defaultConfiguration) const override
Swaptions.
Definition: marketimpl.cpp:117
virtual Handle< ZeroInflationIndex > zeroInflationIndex(const string &indexName, const string &configuration=Market::defaultConfiguration) const override
Inflation Indexes.
Definition: marketimpl.cpp:342
Handle< QuantExt::EquityIndex2 > equityCurve(const string &eqName, const string &configuration=Market::defaultConfiguration) const override
Definition: marketimpl.cpp:364
map< tuple< string, string, string >, Handle< QuantExt::CorrelationTermStructure > > correlationCurves_
Definition: marketimpl.hpp:229
Handle< BlackVolTermStructure > equityVol(const string &eqName, const string &configuration=Market::defaultConfiguration) const override
Equity volatilities.
Definition: marketimpl.cpp:375
map< string, std::set< QuantLib::ext::shared_ptr< TermStructure > > > refreshTs_
Definition: marketimpl.hpp:240
Handle< QuantExt::InflationIndexObserver > baseCpis(const string &index, const string &configuration=Market::defaultConfiguration) const
Cpi Base Quotes.
Definition: marketimpl.cpp:390
Handle< YieldTermStructure > discountCurveImpl(const string &ccy, const string &configuration=Market::defaultConfiguration) const override
Definition: marketimpl.cpp:96
map< pair< string, string >, QuantLib::Handle< QuantExt::EquityIndex2 > > equityCurves_
Definition: marketimpl.hpp:232
Handle< Quote > fxSpotImpl(const string &ccypair, const string &configuration=Market::defaultConfiguration) const override
Definition: marketimpl.cpp:212
Handle< BlackVolTermStructure > fxVolImpl(const string &ccypair, const string &configuration=Market::defaultConfiguration) const override
Definition: marketimpl.cpp:218
map< pair< string, string >, Handle< CPIVolatilitySurface > > cpiInflationCapFloorVolatilitySurfaces_
Definition: marketimpl.hpp:224
map< pair< string, string >, Handle< QuantExt::InflationIndexObserver > > baseCpis_
Definition: marketimpl.hpp:228
virtual Handle< CPIVolatilitySurface > cpiInflationCapFloorVolatilitySurface(const string &indexName, const string &configuration=Market::defaultConfiguration) const override
Inflation Cap Floor Volatility Surfaces.
Definition: marketimpl.cpp:352
Handle< QuantExt::CreditVolCurve > cdsVol(const string &name, const string &configuration=Market::defaultConfiguration) const override
CDS volatilities.
Definition: marketimpl.cpp:257
map< pair< string, string >, Handle< BlackVolTermStructure > > fxVols_
Definition: marketimpl.hpp:214
QuantLib::ext::shared_ptr< FXTriangulation > fx_
Definition: marketimpl.hpp:206
map< tuple< string, YieldCurveType, string >, Handle< YieldTermStructure > > yieldCurves_
Definition: marketimpl.hpp:208
map< pair< string, string >, QuantLib::Handle< QuantExt::CommodityIndex > > commodityIndices_
Definition: marketimpl.hpp:230
map< pair< string, string >, Handle< QuantExt::CreditCurve > > defaultCurves_
Definition: marketimpl.hpp:215
Handle< YieldTermStructure > equityDividendCurve(const string &eqName, const string &configuration=Market::defaultConfiguration) const override
Definition: marketimpl.cpp:369
map< pair< string, string >, Handle< IborIndex > > iborIndices_
Definition: marketimpl.hpp:209
QuantLib::Handle< QuantExt::FxIndex > fxIndexImpl(const string &fxIndex, const string &configuration=Market::defaultConfiguration) const override
FX.
Definition: marketimpl.cpp:199
map< pair< string, string >, Handle< YoYOptionletVolatilitySurface > > yoyCapFloorVolSurfaces_
Definition: marketimpl.hpp:221
Handle< QuantExt::CreditCurve > defaultCurve(const string &, const string &configuration=Market::defaultConfiguration) const override
Default Curves and Recovery Rates.
Definition: marketimpl.cpp:245
map< pair< string, string >, Handle< YoYInflationIndex > > yoyInflationIndices_
Definition: marketimpl.hpp:223
map< pair< string, string >, Handle< QuantExt::CreditVolCurve > > cdsVols_
Definition: marketimpl.hpp:216
Handle< QuantExt::YoYOptionletVolatilitySurface > yoyCapFloorVol(const string &name, const string &configuration=Market::defaultConfiguration) const override
YoY Inflation CapFloor volatilities.
Definition: marketimpl.cpp:336
map< pair< string, string >, Handle< Quote > > equitySpots_
Definition: marketimpl.hpp:225
pair< string, string > swapIndexBases(const string &key, const string &configuration=Market::defaultConfiguration) const
Definition: marketimpl.cpp:151
map< pair< string, string >, Handle< QuantLib::SwaptionVolatilityStructure > > swaptionCurves_
Definition: marketimpl.hpp:211
map< pair< string, string >, Handle< QuantExt::BaseCorrelationTermStructure > > baseCorrelations_
Definition: marketimpl.hpp:217
QuantLib::Handle< Quote > cpr(const string &securityID, const string &configuration=Market::defaultConfiguration) const override
Definition: marketimpl.cpp:468
map< pair< string, string >, Handle< Quote > > cprs_
Definition: marketimpl.hpp:233
Handle< Quote > fxRateImpl(const string &ccypair, const string &configuration=Market::defaultConfiguration) const override
Definition: marketimpl.cpp:205
Handle< Quote > recoveryRate(const string &, const string &configuration=Market::defaultConfiguration) const override
Definition: marketimpl.cpp:250
map< pair< string, string >, Handle< Quote > > recoveryRates_
Definition: marketimpl.hpp:218
QuantLib::Handle< QuantExt::PriceTermStructure > commodityPriceCurve(const string &commodityName, const string &configuration=Market::defaultConfiguration) const override
Commodity curves.
Definition: marketimpl.cpp:395
Handle< Quote > equitySpot(const string &eqName, const string &configuration=Market::defaultConfiguration) const override
Equity curves.
Definition: marketimpl.cpp:359
void refresh(const string &configuration=Market::defaultConfiguration) override
Send an explicit update() call to all term structures.
Definition: marketimpl.cpp:513
map< pair< string, string >, Handle< ZeroInflationIndex > > zeroInflationIndices_
Definition: marketimpl.hpp:222
Handle< SwapIndex > swapIndex(const string &indexName, const string &configuration=Market::defaultConfiguration) const override
Definition: marketimpl.cpp:112
map< pair< string, string >, pair< string, string > > swaptionIndexBases_
Definition: marketimpl.hpp:212
std::pair< string, QuantLib::Period > capFloorVolIndexBase(const string &key, const string &configuration=Market::defaultConfiguration) const override
Definition: marketimpl.cpp:302
Handle< QuantExt::CorrelationTermStructure > correlationCurve(const string &index1, const string &index2, const string &configuration=Market::defaultConfiguration) const override
Correlation curves.
Definition: marketimpl.cpp:411
Handle< OptionletVolatilityStructure > capFloorVol(const string &key, const string &configuration=Market::defaultConfiguration) const override
CapFloor volatilities.
Definition: marketimpl.cpp:269
map< pair< string, string >, Handle< BlackVolTermStructure > > equityVols_
Definition: marketimpl.hpp:226
virtual Handle< YoYInflationIndex > yoyInflationIndex(const string &indexName, const string &configuration=Market::defaultConfiguration) const override
Definition: marketimpl.cpp:347
map< pair< string, string >, Handle< QuantLib::SwaptionVolatilityStructure > > yieldVolCurves_
Definition: marketimpl.hpp:213
map< pair< string, string >, Handle< SwapIndex > > swapIndices_
Definition: marketimpl.hpp:210
map< pair< string, string >, Handle< Quote > > securitySpreads_
Definition: marketimpl.hpp:227
Handle< YieldTermStructure > yieldCurve(const YieldCurveType &type, const string &ccy, const string &configuration=Market::defaultConfiguration) const override
Yield Curves.
Definition: marketimpl.cpp:74
Handle< IborIndex > iborIndex(const string &indexName, const string &configuration=Market::defaultConfiguration) const override
Definition: marketimpl.cpp:107
map< pair< string, string >, QuantLib::Handle< QuantLib::BlackVolTermStructure > > commodityVols_
Definition: marketimpl.hpp:231
virtual void require(const MarketObject o, const string &name, const string &configuration, const bool forceBuild=false) const
Definition: marketimpl.hpp:201
Handle< QuantLib::SwaptionVolatilityStructure > yieldVol(const string &securityID, const string &configuration=Market::defaultConfiguration) const override
Yield volatility.
Definition: marketimpl.cpp:192
QuantLib::Handle< QuantLib::BlackVolTermStructure > commodityVolatility(const string &commodityName, const string &configuration=Market::defaultConfiguration) const override
Commodity volatility.
Definition: marketimpl.cpp:405
void addSwapIndex(const string &swapindex, const string &discountIndex, const string &configuration=Market::defaultConfiguration) const
add a swap index to the market
Definition: marketimpl.cpp:473
Handle< YieldTermStructure > equityForecastCurve(const string &eqName, const string &configuration=Market::defaultConfiguration) const override
Equity forecasting curves.
Definition: marketimpl.cpp:380
map< pair< string, string >, std::pair< string, QuantLib::Period > > capFloorIndexBase_
Definition: marketimpl.hpp:220
Currency and instrument specific conventions/defaults.
QuantLib::ext::shared_ptr< SwapIndex > parseSwapIndex(const string &s, const Handle< YieldTermStructure > &f, const Handle< YieldTermStructure > &d)
Convert std::string to QuantLib::SwapIndex.
bool tryParseIborIndex(const string &s, QuantLib::ext::shared_ptr< IborIndex > &index)
Try to convert std::string to QuantLib::IborIndex.
bool isGenericIborIndex(const string &indexName)
Return true if the indexName is that of a generic ibor index, otherwise false.
Map text representations to QuantLib/QuantExt types.
@ data
Definition: log.hpp:77
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
market data related utilties
An implementation of the Market class that stores the required objects in maps.
bool isFxIndex(const std::string &indexName)
Size size(const ValueType &v)
Definition: value.cpp:145
std::string inverseFxIndex(const std::string &indexName)
YieldCurveType
Definition: market.hpp:59
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.