Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
marketimpl.hpp
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/*! \file ored/marketdata/marketimpl.hpp
20 \brief An implementation of the Market class that stores the required objects in maps
21 \ingroup marketdata
22*/
23
24#pragma once
25
29
32
33#include <map>
34
35namespace ore {
36namespace data {
37using namespace QuantLib;
40using std::map;
41using std::pair;
42using std::string;
43using std::tuple;
44
45// TODO: rename class
46//! Market Implementation
47/*!
48 The MarketImpl class differs from the Market base class in that it contains concrete maps
49 of term structures, and it implements the interface.
50
51 \ingroup marketdata
52 */
53class MarketImpl : public Market {
54public:
56
57 //! \name Market interface
58 //@{
59 //! Get the asof Date
60 Date asofDate() const override { return asof_; }
61
62 //! Yield Curves
63 Handle<YieldTermStructure> yieldCurve(const YieldCurveType& type, const string& ccy,
64 const string& configuration = Market::defaultConfiguration) const override;
65 Handle<YieldTermStructure> discountCurveImpl(const string& ccy,
66 const string& configuration = Market::defaultConfiguration) const override;
67 Handle<YieldTermStructure> yieldCurve(const string& name,
68 const string& configuration = Market::defaultConfiguration) const override;
69 Handle<IborIndex> iborIndex(const string& indexName,
70 const string& configuration = Market::defaultConfiguration) const override;
71 Handle<SwapIndex> swapIndex(const string& indexName,
72 const string& configuration = Market::defaultConfiguration) const override;
73
74 //! Swaptions
75 Handle<QuantLib::SwaptionVolatilityStructure>
76 swaptionVol(const string& key, const string& configuration = Market::defaultConfiguration) const override;
77 string shortSwapIndexBase(const string& key,
78 const string& configuration = Market::defaultConfiguration) const override;
79 string swapIndexBase(const string& key, const string& configuration = Market::defaultConfiguration) const override;
80
81 //! Yield volatility
82 Handle<QuantLib::SwaptionVolatilityStructure>
83 yieldVol(const string& securityID, const string& configuration = Market::defaultConfiguration) const override;
84
85 //! FX
86 QuantLib::Handle<QuantExt::FxIndex>
87 fxIndexImpl(const string& fxIndex, const string& configuration = Market::defaultConfiguration) const override;
88 Handle<Quote> fxRateImpl(const string& ccypair,
89 const string& configuration = Market::defaultConfiguration) const override;
90 Handle<Quote> fxSpotImpl(const string& ccypair,
91 const string& configuration = Market::defaultConfiguration) const override;
92 Handle<BlackVolTermStructure> fxVolImpl(const string& ccypair,
93 const string& configuration = Market::defaultConfiguration) const override;
94
95 //! Default Curves and Recovery Rates
96 Handle<QuantExt::CreditCurve> defaultCurve(const string&,
97 const string& configuration = Market::defaultConfiguration) const override;
98 Handle<Quote> recoveryRate(const string&, const string& configuration = Market::defaultConfiguration) const override;
99
100 //! CDS volatilities
101 Handle<QuantExt::CreditVolCurve> cdsVol(const string& name,
102 const string& configuration = Market::defaultConfiguration) const override;
103
104 //! Base correlation structures
105 Handle<QuantExt::BaseCorrelationTermStructure>
106 baseCorrelation(const string& name, const string& configuration = Market::defaultConfiguration) const override;
107
108 //! CapFloor volatilities
109 Handle<OptionletVolatilityStructure> capFloorVol(const string& key,
110 const string& configuration = Market::defaultConfiguration) const override;
111 std::pair<string, QuantLib::Period>
112 capFloorVolIndexBase(const string& key, const string& configuration = Market::defaultConfiguration) const override;
113
114 //! YoY Inflation CapFloor volatilities
115 Handle<QuantExt::YoYOptionletVolatilitySurface>
116 yoyCapFloorVol(const string& name, const string& configuration = Market::defaultConfiguration) const override;
117
118 //! Inflation Indexes
119 virtual Handle<ZeroInflationIndex>
120 zeroInflationIndex(const string& indexName, const string& configuration = Market::defaultConfiguration) const override;
121 virtual Handle<YoYInflationIndex>
122 yoyInflationIndex(const string& indexName, const string& configuration = Market::defaultConfiguration) const override;
123
124 //! Inflation Cap Floor Volatility Surfaces
125 virtual Handle<CPIVolatilitySurface>
126 cpiInflationCapFloorVolatilitySurface(const string& indexName,
127 const string& configuration = Market::defaultConfiguration) const override;
128
129 //! Equity curves
130 Handle<Quote> equitySpot(const string& eqName, const string& configuration = Market::defaultConfiguration) const override;
131 Handle<QuantExt::EquityIndex2> equityCurve(const string& eqName,
132 const string& configuration = Market::defaultConfiguration) const override;
133
134 Handle<YieldTermStructure> equityDividendCurve(const string& eqName,
135 const string& configuration = Market::defaultConfiguration) const override;
136
137 //! Equity volatilities
138 Handle<BlackVolTermStructure> equityVol(const string& eqName,
139 const string& configuration = Market::defaultConfiguration) const override;
140
141 //! Equity forecasting curves
142 Handle<YieldTermStructure> equityForecastCurve(const string& eqName,
143 const string& configuration = Market::defaultConfiguration) const override;
144
145 //! Bond Spreads
146 Handle<Quote> securitySpread(const string& securityID,
147 const string& configuration = Market::defaultConfiguration) const override;
148
149 //! Cpi Base Quotes
150 Handle<QuantExt::InflationIndexObserver> baseCpis(const string& index,
151 const string& configuration = Market::defaultConfiguration) const;
152
153 //! Commodity curves
154 QuantLib::Handle<QuantExt::PriceTermStructure>
155 commodityPriceCurve(const string& commodityName, const string& configuration = Market::defaultConfiguration) const override;
156
157 //! Commodity index
158 QuantLib::Handle<QuantExt::CommodityIndex> commodityIndex(const std::string& commodityName,
159 const std::string& configuration = Market::defaultConfiguration) const override;
160
161 //! Commodity volatility
162 QuantLib::Handle<QuantLib::BlackVolTermStructure>
163 commodityVolatility(const string& commodityName, const string& configuration = Market::defaultConfiguration) const override;
164 //@}
165
166 //! Correlation curves
167 Handle<QuantExt::CorrelationTermStructure>
168 correlationCurve(const string& index1, const string& index2,
169 const string& configuration = Market::defaultConfiguration) const override;
170 //! \name Conditional Prepayment Rates
171 //@{
172 QuantLib::Handle<Quote> cpr(const string& securityID,
173 const string& configuration = Market::defaultConfiguration) const override;
174 //@}
175
176 //! \name Disable copying
177 //@{
178 MarketImpl(const MarketImpl&) = delete;
179 MarketImpl& operator=(const MarketImpl&) = delete;
180 //@}
181
182 //! Send an explicit update() call to all term structures
183 void refresh(const string& configuration = Market::defaultConfiguration) override;
184
185protected:
186 /*! Require a market object, this can be used in derived classes to build objects lazily. If the
187 method is not overwritten in a derived class, it is assumed that the class builds all market
188 object upfront.
189
190 For FXVols and Correlations the require is not 'hard', e.g. both EURUSD and USDEUR might
191 be required for FXVols, but only one of them is expected to be actually built (the other
192 one is then constructed on the fly from the first one). Therefore no error should be thrown
193 in the implementation of require(), if an object is ultimately not found, an appropriate error
194 will be thrown from this class.
195
196 An object is required for a single configuration. If it can't be built for this configuration,
197 it should be tried to be built for the "default" configuration instead, because this is used
198 as a fallback.
199
200 Notice that correlation curves are required with '&' as a delimiter between the indexes. */
201 virtual void require(const MarketObject o, const string& name, const string& configuration,
202 const bool forceBuild = false) const {}
203
204 Date asof_;
205 // fx quotes / indices, this is shared between all configurations
206 QuantLib::ext::shared_ptr<FXTriangulation> fx_;
207 // maps (configuration, key) => term structure
208 mutable map<tuple<string, YieldCurveType, string>, Handle<YieldTermStructure>> yieldCurves_;
209 mutable map<pair<string, string>, Handle<IborIndex>> iborIndices_;
210 mutable map<pair<string, string>, Handle<SwapIndex>> swapIndices_;
211 mutable map<pair<string, string>, Handle<QuantLib::SwaptionVolatilityStructure>> swaptionCurves_;
212 mutable map<pair<string, string>, pair<string, string>> swaptionIndexBases_;
213 mutable map<pair<string, string>, Handle<QuantLib::SwaptionVolatilityStructure>> yieldVolCurves_;
214 mutable map<pair<string, string>, Handle<BlackVolTermStructure>> fxVols_;
215 mutable map<pair<string, string>, Handle<QuantExt::CreditCurve>> defaultCurves_;
216 mutable map<pair<string, string>, Handle<QuantExt::CreditVolCurve>> cdsVols_;
217 mutable map<pair<string, string>, Handle<QuantExt::BaseCorrelationTermStructure>> baseCorrelations_;
218 mutable map<pair<string, string>, Handle<Quote>> recoveryRates_;
219 mutable map<pair<string, string>, Handle<OptionletVolatilityStructure>> capFloorCurves_;
220 mutable map<pair<string, string>, std::pair<string, QuantLib::Period>> capFloorIndexBase_;
221 mutable map<pair<string, string>, Handle<YoYOptionletVolatilitySurface>> yoyCapFloorVolSurfaces_;
222 mutable map<pair<string, string>, Handle<ZeroInflationIndex>> zeroInflationIndices_;
223 mutable map<pair<string, string>, Handle<YoYInflationIndex>> yoyInflationIndices_;
224 mutable map<pair<string, string>, Handle<CPIVolatilitySurface>> cpiInflationCapFloorVolatilitySurfaces_;
225 mutable map<pair<string, string>, Handle<Quote>> equitySpots_;
226 mutable map<pair<string, string>, Handle<BlackVolTermStructure>> equityVols_;
227 mutable map<pair<string, string>, Handle<Quote>> securitySpreads_;
228 mutable map<pair<string, string>, Handle<QuantExt::InflationIndexObserver>> baseCpis_;
229 mutable map<tuple<string, string, string>, Handle<QuantExt::CorrelationTermStructure>> correlationCurves_;
230 mutable map<pair<string, string>, QuantLib::Handle<QuantExt::CommodityIndex>> commodityIndices_;
231 mutable map<pair<string, string>, QuantLib::Handle<QuantLib::BlackVolTermStructure>> commodityVols_;
232 mutable map<pair<string, string>, QuantLib::Handle<QuantExt::EquityIndex2>> equityCurves_;
233 mutable map<pair<string, string>, Handle<Quote>> cprs_;
234
235 //! add a swap index to the market
236 void addSwapIndex(const string& swapindex, const string& discountIndex,
237 const string& configuration = Market::defaultConfiguration) const;
238
239 // set of term structure pointers for refresh (per configuration)
240 map<string, std::set<QuantLib::ext::shared_ptr<TermStructure>>> refreshTs_;
241
242private:
243 pair<string, string> swapIndexBases(const string& key,
244 const string& configuration = Market::defaultConfiguration) const;
245};
246
247} // namespace data
248} // namespace ore
Abstract base class for convention objects.
Definition: conventions.hpp:55
Repository for currency dependent market conventions.
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
bool handlePseudoCurrencies() const
Definition: market.hpp:339
Market Implementation.
Definition: marketimpl.hpp:53
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
MarketImpl(const MarketImpl &)=delete
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
MarketImpl(const bool handlePseudoCurrencies)
Definition: marketimpl.hpp:55
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
Date asofDate() const override
Get the asof Date.
Definition: marketimpl.hpp:60
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
MarketImpl & operator=(const MarketImpl &)=delete
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.
Intelligent FX price repository.
@ data
Definition: log.hpp:77
Base Market class.
MarketObject
Definition: market.hpp:65
YieldCurveType
Definition: market.hpp:59
Serializable Credit Default Swap.
Definition: namespaces.docs:23
string name