Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
market.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/market.hpp
20 \brief Base Market class
21 \ingroup marketdata
22*/
23
24#pragma once
25
26
27#include <ql/experimental/inflation/cpicapfloortermpricesurface.hpp>
28#include <ql/experimental/inflation/yoycapfloortermpricesurface.hpp>
29#include <ql/indexes/iborindex.hpp>
30#include <ql/indexes/inflationindex.hpp>
31#include <ql/indexes/swapindex.hpp>
32#include <ql/quote.hpp>
33#include <ql/termstructures/defaulttermstructure.hpp>
34#include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp>
35#include <ql/termstructures/volatility/inflation/cpivolatilitystructure.hpp>
36#include <ql/termstructures/volatility/optionlet/optionletvolatilitystructure.hpp>
37#include <ql/termstructures/volatility/swaption/swaptionvolstructure.hpp>
38#include <ql/termstructures/yieldtermstructure.hpp>
39#include <ql/time/date.hpp>
40#include <ql/termstructures/volatility/inflation/yoyinflationoptionletvolatilitystructure.hpp>
41
50
51#include <boost/thread/shared_mutex.hpp>
52#include <boost/thread/locks.hpp>
53
54namespace ore {
55namespace data {
56using namespace QuantLib;
57using std::string;
58
59enum class YieldCurveType {
60 Discount = 0, // Chosen to match MarketObject::DiscountCurve
61 Yield = 1, // Chosen to match MarketObject::YieldCurve
63};
64
65enum class MarketObject {
66 DiscountCurve = 0,
67 YieldCurve = 1,
68 IndexCurve = 2,
70 FXSpot = 4,
71 FXVol = 5,
72 SwaptionVol = 6,
73 DefaultCurve = 7,
74 CDSVol = 8,
76 CapFloorVol = 10,
81 EquityCurve = 15,
82 EquityVol = 16,
83 Security = 17,
84 CommodityCurve = 18,
86 Correlation = 20,
87 YieldVol = 21
88};
89
90//! Struct to store parameters for commodities to be treatred as pseudo currencies
92 bool treatAsFX; // flag to pass through to Pure FX
93 string baseCurrency; // pseudo currency base currency, typically USD
94 std::map<string, string> curves; // map from pseudo currency to commodity curve, e.g. "XAU" -> "PM:XAUUSD", "BTC" -> "CRYPTO:BTCUSD"
95 string fxIndexTag; // tag for FX correlations
96 Real defaultCorrelation; // default correlation or Null<Real> if none is set
97};
98
99std::ostream& operator<<(std::ostream&, const struct PseudoCurrencyMarketParameters&);
100
101//! Function to build parameters from PricingEngine GlobalParametrs.
102/*! If no PricingEngine Global Parameters (PEGP) are provided the default params are returned which have treatAsFX =
103 * true. If PEGP are present, we look for the following fields
104 *
105 * name="PseudoCurrency.TreatAsFX" value = true or false
106 * name="PseudoCurrency.BaseCurrency" value = currency code
107 * name="PseudoCurrency.FXIndexTag" value = Tag name for FX indices, e.g. GENERIC means we request correlation for
108 * "FX-GENERIC-USD-EUR" name="PseudeoCurrency.Curves.XXX" value = curve name, here XXX should be a 3 letter Precious metal or Crypto currency
109 * code name="PseudoCurrency.DefaultCorrelation" value = correlation. This is optional, if present we use this when the
110 * market has no correlation
111 *
112 * A typical configuration is
113 * <pre>
114 * <GlobalParameters>
115 * <Parameter name="PseudoCurrency.TreatAsFX">false</Parameter>
116 * <Parameter name="PseudoCurrency.BaseCurrency">USD</Parameter>
117 * <Parameter name="PseudoCurrency.FXIndexTag">GENERIC</Parameter>
118 * <Parameter name="PseudoCurrency.Curve.XAU">PM:XAUUSD</Parameter>
119 * <Parameter name="PseudoCurrency.Curve.XBT">CRYPTO:XBTUSD</Parameter>
120 * </GlobalParameters>
121 * </pre>
122 */
124 const std::map<string, string>& pricingEngineGlobalParameters = std::map<string, string>());
125
126//! Singleton to store Global parameters, this should be initialised at some point with PEGP
128 : public Singleton<GlobalPseudoCurrencyMarketParameters, std::integral_constant<bool, true>> {
129 friend class Singleton<GlobalPseudoCurrencyMarketParameters, std::integral_constant<bool, true>>;
130
131public:
133 boost::shared_lock<boost::shared_mutex> lock(mutex_);
134 return params_;
135 }
136
138 boost::unique_lock<boost::shared_mutex> lock(mutex_);
139 params_ = params;
140 }
141 void set(const std::map<string, string>& pegp) {
142 boost::unique_lock<boost::shared_mutex> lock(mutex_);
144 }
145
146private:
148 // default behaviour is from above
150 };
151
153 mutable boost::shared_mutex mutex_;
154};
155
156//! Market
157/*!
158 Base class for central repositories containing all term structure objects
159 needed in instrument pricing.
160
161 \ingroup marketdata
162*/
163class Market {
164public:
165 //! Constructor
167
168 //! Destructor
169 virtual ~Market() {}
170
171 //! Get the asof Date
172 virtual Date asofDate() const = 0;
173
174 //! \name Yield Curves
175 //@{
176 virtual Handle<YieldTermStructure> yieldCurve(const YieldCurveType& type, const string& name,
177 const string& configuration = Market::defaultConfiguration) const = 0;
178 Handle<YieldTermStructure> discountCurve(const string& ccy,
179 const string& configuration = Market::defaultConfiguration) const;
180 virtual Handle<YieldTermStructure>
181 discountCurveImpl(const string& ccy, const string& configuration = Market::defaultConfiguration) const = 0;
182
183 virtual Handle<YieldTermStructure> yieldCurve(const string& name,
184 const string& configuration = Market::defaultConfiguration) const = 0;
185 virtual Handle<IborIndex> iborIndex(const string& indexName,
186 const string& configuration = Market::defaultConfiguration) const = 0;
187 virtual Handle<SwapIndex> swapIndex(const string& indexName,
188 const string& configuration = Market::defaultConfiguration) const = 0;
189 //@}
190
191 //! \name Swaptions
192 //@{
193 virtual Handle<SwaptionVolatilityStructure>
194 swaptionVol(const string& key, const string& configuration = Market::defaultConfiguration) const = 0;
195 virtual string shortSwapIndexBase(const string& key,
196 const string& configuration = Market::defaultConfiguration) const = 0;
197 virtual string swapIndexBase(const string& key,
198 const string& configuration = Market::defaultConfiguration) const = 0;
199 //@}
200
201 //! \name Yield volatilities
202 //@{
203 virtual Handle<SwaptionVolatilityStructure>
204 yieldVol(const string& securityID, const string& configuration = Market::defaultConfiguration) const = 0;
205 //@}
206
207 //! \name Foreign Exchange
208 //@{
209 QuantLib::Handle<QuantExt::FxIndex> fxIndex(const string& fxIndex,
210 const string& configuration = Market::defaultConfiguration) const;
211 virtual QuantLib::Handle<QuantExt::FxIndex>
212 fxIndexImpl(const string& fxIndex, const string& configuration = Market::defaultConfiguration) const = 0;
213 // Fx Rate is the fx rate as of today
214 Handle<Quote> fxRate(const string& ccypair, const string& configuration = Market::defaultConfiguration) const;
215 virtual Handle<Quote> fxRateImpl(const string& ccypair,
216 const string& configuration = Market::defaultConfiguration) const = 0;
217 // Fx Spot is the spot rate quoted in the market
218 Handle<Quote> fxSpot(const string& ccypair, const string& configuration = Market::defaultConfiguration) const;
219 virtual Handle<Quote> fxSpotImpl(const string& ccypair,
220 const string& configuration = Market::defaultConfiguration) const = 0;
221 Handle<BlackVolTermStructure> fxVol(const string& ccypair,
222 const string& configuration = Market::defaultConfiguration) const;
223 virtual Handle<BlackVolTermStructure>
224 fxVolImpl(const string& ccypair, const string& configuration = Market::defaultConfiguration) const = 0;
225 //@}
226
227 //! \name Default Curves and Recovery Rates
228 //@{
229 virtual Handle<QuantExt::CreditCurve>
230 defaultCurve(const string&, const string& configuration = Market::defaultConfiguration) const = 0;
231 virtual Handle<Quote> recoveryRate(const string&,
232 const string& configuration = Market::defaultConfiguration) const = 0;
233 //@}
234
235 //! \name (Index) CDS Option volatilities
236 //@{
237 virtual Handle<QuantExt::CreditVolCurve>
238 cdsVol(const string&, const string& configuration = Market::defaultConfiguration) const = 0;
239 //@}
240
241 //! \name Base Correlation term structures
242 //@{
243 virtual Handle<QuantExt::BaseCorrelationTermStructure>
244 baseCorrelation(const string&, const string& configuration = Market::defaultConfiguration) const = 0;
245 //@}
246
247 //! \name Stripped Cap/Floor volatilities i.e. caplet/floorlet volatilities
248 //@{
249 virtual Handle<OptionletVolatilityStructure>
250 capFloorVol(const string& key, const string& configuration = Market::defaultConfiguration) const = 0;
251 // get - ibor index name (might be empty = unspecified) and
252 // - rate computation period for OIS indices (might be 0*Days = unspecified)
253 virtual std::pair<std::string, QuantLib::Period>
254 capFloorVolIndexBase(const string& key, const string& configuration = Market::defaultConfiguration) const = 0;
255 //@}
256
257 //! \name Stripped YoY Inflation Cap/Floor volatilities i.e. caplet/floorlet volatilities
258 //@{
259 virtual Handle<QuantExt::YoYOptionletVolatilitySurface>
260 yoyCapFloorVol(const string& indexName, const string& configuration = Market::defaultConfiguration) const = 0;
261 //@}
262
263 //! Inflation Indexes
264 virtual Handle<ZeroInflationIndex>
265 zeroInflationIndex(const string& indexName, const string& configuration = Market::defaultConfiguration) const = 0;
266 virtual Handle<YoYInflationIndex>
267 yoyInflationIndex(const string& indexName, const string& configuration = Market::defaultConfiguration) const = 0;
268
269 //! CPI Inflation Cap Floor Volatility Surfaces
270 virtual Handle<CPIVolatilitySurface>
272 const string& configuration = Market::defaultConfiguration) const = 0;
273
274 //! \name Equity curves
275 //@{
276 virtual Handle<Quote> equitySpot(const string& eqName,
277 const string& configuration = Market::defaultConfiguration) const = 0;
278 virtual Handle<YieldTermStructure>
279 equityDividendCurve(const string& eqName, const string& configuration = Market::defaultConfiguration) const = 0;
280 virtual Handle<YieldTermStructure>
281 equityForecastCurve(const string& eqName, const string& configuration = Market::defaultConfiguration) const = 0;
282 virtual Handle<QuantExt::EquityIndex2>
283 equityCurve(const string& eqName, const string& configuration = Market::defaultConfiguration) const = 0;
284 //@}
285
286 //! \name Equity volatilities
287 //@{
288 virtual Handle<BlackVolTermStructure>
289 equityVol(const string& eqName, const string& configuration = Market::defaultConfiguration) const = 0;
290 //@}
291
292 //! Refresh term structures for a given configuration
293 virtual void refresh(const string&) {}
294
295 //! Default configuration label
296 static const string defaultConfiguration;
297
298 //! InCcy configuration label
299 static const string inCcyConfiguration;
300
301 //! \name BondSpreads
302 //@{
303 virtual Handle<Quote> securitySpread(const string& securityID,
304 const string& configuration = Market::defaultConfiguration) const = 0;
305 //@}
306
307 //! \name Commodity price curves and indices
308 //@{
309 virtual QuantLib::Handle<QuantExt::PriceTermStructure>
310 commodityPriceCurve(const std::string& commodityName,
311 const std::string& configuration = Market::defaultConfiguration) const = 0;
312
313 virtual QuantLib::Handle<QuantExt::CommodityIndex> commodityIndex(const std::string& commodityName,
314 const std::string& configuration = Market::defaultConfiguration) const = 0;
315 //@}
316
317 //! \name Commodity volatility
318 //@{
319 virtual QuantLib::Handle<QuantLib::BlackVolTermStructure>
320 commodityVolatility(const std::string& commodityName,
321 const std::string& configuration = Market::defaultConfiguration) const = 0;
322 //@}
323
324 //! \name Correlation
325 //@{
326 virtual QuantLib::Handle<QuantExt::CorrelationTermStructure>
327 correlationCurve(const std::string& index1, const std::string& index2,
328 const std::string& configuration = Market::defaultConfiguration) const = 0;
329 //@}
330 //! \name Conditional Prepayment Rates
331 //@{
332 virtual Handle<Quote> cpr(const string& securityID,
333 const string& configuration = Market::defaultConfiguration) const = 0;
334 //@}
335
336 // public utility
337 string commodityCurveLookup(const string& pm) const;
338
340
341protected:
343
344private:
345 // caches for the market data objects
346 mutable std::map<string, Handle<Quote>> spotCache_;
347 mutable std::map<string, Handle<BlackVolTermStructure>> volCache_;
348 mutable std::map<string, Handle<YieldTermStructure>> discountCurveCache_;
349
350 mutable std::map<string, Handle<Quote>> fxRateCache_;
351 mutable std::map<std::pair<string, string>, QuantLib::Handle<QuantExt::FxIndex>> fxIndicesCache_;
352
353 // private utilities
354 Handle<Quote> getFxBaseQuote(const string& ccy, const string& config) const;
355 Handle<Quote> getFxSpotBaseQuote(const string& ccy, const string& config) const;
356 Handle<BlackVolTermStructure> getVolatility(const string& ccy, const string& config) const;
357 string getCorrelationIndexName(const string& ccy) const;
358};
359} // namespace data
360} // namespace ore
Wrapper class for building Swaption volatility structures.
Wrapper class for building Equity curves (spot quote, yield term structure, risk free IR term structu...
Definition: equitycurve.hpp:44
Singleton to store Global parameters, this should be initialised at some point with PEGP.
Definition: market.hpp:128
void set(const PseudoCurrencyMarketParameters &params)
Definition: market.hpp:137
void set(const std::map< string, string > &pegp)
Definition: market.hpp:141
PseudoCurrencyMarketParameters params_
Definition: market.hpp:152
virtual Handle< QuantExt::CreditCurve > defaultCurve(const string &, const string &configuration=Market::defaultConfiguration) const =0
virtual Handle< CPIVolatilitySurface > cpiInflationCapFloorVolatilitySurface(const string &indexName, const string &configuration=Market::defaultConfiguration) const =0
CPI Inflation Cap Floor Volatility Surfaces.
virtual Handle< Quote > equitySpot(const string &eqName, const string &configuration=Market::defaultConfiguration) const =0
Handle< Quote > fxSpot(const string &ccypair, const string &configuration=Market::defaultConfiguration) const
Definition: market.cpp:241
static const string inCcyConfiguration
InCcy configuration label.
Definition: market.hpp:299
virtual QuantLib::Handle< QuantLib::BlackVolTermStructure > commodityVolatility(const std::string &commodityName, const std::string &configuration=Market::defaultConfiguration) const =0
virtual Handle< OptionletVolatilityStructure > capFloorVol(const string &key, const string &configuration=Market::defaultConfiguration) const =0
std::map< std::pair< string, string >, QuantLib::Handle< QuantExt::FxIndex > > fxIndicesCache_
Definition: market.hpp:351
std::map< string, Handle< BlackVolTermStructure > > volCache_
Definition: market.hpp:347
virtual Handle< Quote > securitySpread(const string &securityID, const string &configuration=Market::defaultConfiguration) const =0
virtual Handle< Quote > cpr(const string &securityID, const string &configuration=Market::defaultConfiguration) const =0
std::map< string, Handle< YieldTermStructure > > discountCurveCache_
Definition: market.hpp:348
Handle< Quote > fxRate(const string &ccypair, const string &configuration=Market::defaultConfiguration) const
Definition: market.cpp:216
virtual string swapIndexBase(const string &key, const string &configuration=Market::defaultConfiguration) const =0
virtual ~Market()
Destructor.
Definition: market.hpp:169
bool handlePseudoCurrencies_
Definition: market.hpp:342
virtual QuantLib::Handle< QuantExt::PriceTermStructure > commodityPriceCurve(const std::string &commodityName, const std::string &configuration=Market::defaultConfiguration) const =0
virtual Handle< YieldTermStructure > equityForecastCurve(const string &eqName, const string &configuration=Market::defaultConfiguration) const =0
std::map< string, Handle< Quote > > fxRateCache_
Definition: market.hpp:350
virtual Handle< SwaptionVolatilityStructure > yieldVol(const string &securityID, const string &configuration=Market::defaultConfiguration) const =0
virtual Handle< QuantExt::BaseCorrelationTermStructure > baseCorrelation(const string &, const string &configuration=Market::defaultConfiguration) const =0
virtual Handle< QuantExt::YoYOptionletVolatilitySurface > yoyCapFloorVol(const string &indexName, const string &configuration=Market::defaultConfiguration) const =0
virtual Handle< ZeroInflationIndex > zeroInflationIndex(const string &indexName, const string &configuration=Market::defaultConfiguration) const =0
Inflation Indexes.
Handle< BlackVolTermStructure > fxVol(const string &ccypair, const string &configuration=Market::defaultConfiguration) const
Definition: market.cpp:287
Handle< BlackVolTermStructure > getVolatility(const string &ccy, const string &config) const
Definition: market.cpp:266
virtual Handle< Quote > recoveryRate(const string &, const string &configuration=Market::defaultConfiguration) const =0
virtual Handle< IborIndex > iborIndex(const string &indexName, const string &configuration=Market::defaultConfiguration) const =0
virtual Handle< YieldTermStructure > discountCurveImpl(const string &ccy, const string &configuration=Market::defaultConfiguration) const =0
virtual QuantLib::Handle< QuantExt::CorrelationTermStructure > correlationCurve(const std::string &index1, const std::string &index2, const std::string &configuration=Market::defaultConfiguration) const =0
virtual Handle< QuantExt::CreditVolCurve > cdsVol(const string &, const string &configuration=Market::defaultConfiguration) const =0
virtual std::pair< std::string, QuantLib::Period > capFloorVolIndexBase(const string &key, const string &configuration=Market::defaultConfiguration) const =0
string commodityCurveLookup(const string &pm) const
Definition: market.cpp:112
virtual void refresh(const string &)
Refresh term structures for a given configuration.
Definition: market.hpp:293
QuantLib::Handle< QuantExt::FxIndex > fxIndex(const string &fxIndex, const string &configuration=Market::defaultConfiguration) const
Definition: market.cpp:151
virtual Handle< SwapIndex > swapIndex(const string &indexName, const string &configuration=Market::defaultConfiguration) const =0
virtual Handle< SwaptionVolatilityStructure > swaptionVol(const string &key, const string &configuration=Market::defaultConfiguration) const =0
virtual Handle< BlackVolTermStructure > equityVol(const string &eqName, const string &configuration=Market::defaultConfiguration) const =0
virtual Handle< YieldTermStructure > yieldCurve(const YieldCurveType &type, const string &name, const string &configuration=Market::defaultConfiguration) const =0
static const string defaultConfiguration
Default configuration label.
Definition: market.hpp:296
virtual string shortSwapIndexBase(const string &key, const string &configuration=Market::defaultConfiguration) const =0
bool handlePseudoCurrencies() const
Definition: market.hpp:339
virtual Date asofDate() const =0
Get the asof Date.
virtual Handle< Quote > fxSpotImpl(const string &ccypair, const string &configuration=Market::defaultConfiguration) const =0
virtual QuantLib::Handle< QuantExt::FxIndex > fxIndexImpl(const string &fxIndex, const string &configuration=Market::defaultConfiguration) const =0
virtual Handle< YoYInflationIndex > yoyInflationIndex(const string &indexName, const string &configuration=Market::defaultConfiguration) const =0
virtual Handle< Quote > fxRateImpl(const string &ccypair, const string &configuration=Market::defaultConfiguration) const =0
Handle< Quote > getFxSpotBaseQuote(const string &ccy, const string &config) const
Definition: market.cpp:135
string getCorrelationIndexName(const string &ccy) const
Definition: market.cpp:275
virtual QuantLib::Handle< QuantExt::CommodityIndex > commodityIndex(const std::string &commodityName, const std::string &configuration=Market::defaultConfiguration) const =0
virtual Handle< YieldTermStructure > equityDividendCurve(const string &eqName, const string &configuration=Market::defaultConfiguration) const =0
Market(const bool handlePseudoCurrencies)
Constructor.
Definition: market.hpp:166
virtual Handle< YieldTermStructure > yieldCurve(const string &name, const string &configuration=Market::defaultConfiguration) const =0
virtual Handle< QuantExt::EquityIndex2 > equityCurve(const string &eqName, const string &configuration=Market::defaultConfiguration) const =0
Handle< Quote > getFxBaseQuote(const string &ccy, const string &config) const
Definition: market.cpp:120
virtual Handle< BlackVolTermStructure > fxVolImpl(const string &ccypair, const string &configuration=Market::defaultConfiguration) const =0
std::map< string, Handle< Quote > > spotCache_
Definition: market.hpp:346
Handle< YieldTermStructure > discountCurve(const string &ccy, const string &configuration=Market::defaultConfiguration) const
Definition: market.cpp:351
Wrapper class for holding Bond Spread and recovery rate quotes.
Definition: security.hpp:39
Wrapper class for building yield term structures.
Definition: yieldcurve.hpp:61
@ data
Definition: log.hpp:77
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
PseudoCurrencyMarketParameters buildPseudoCurrencyMarketParameters(const std::map< string, string > &pegp)
Function to build parameters from PricingEngine GlobalParametrs.
Definition: market.cpp:54
MarketObject
Definition: market.hpp:65
YieldCurveType
Definition: market.hpp:59
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Struct to store parameters for commodities to be treatred as pseudo currencies.
Definition: market.hpp:91
std::map< string, string > curves
Definition: market.hpp:94
string name