Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
sensitivityscenariodata.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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 scenario/sensitivityscenariodata.hpp
20 \brief A class to hold the parametrisation for building sensitivity scenarios
21 \ingroup scenario
22*/
23
24#pragma once
25
30
31namespace ore {
32namespace analytics {
36using QuantLib::Period;
37using QuantLib::Rate;
38using std::map;
39using std::pair;
40using std::string;
41using std::vector;
42
43//! Description of sensitivity shift scenarios
44/*! \ingroup scenario
45 */
47public:
48 struct ShiftData {
49 virtual ~ShiftData() {}
50
51 // default shift size, type (Absolute, Relative) and scheme (Forward, Backward, Central)
53 Real shiftSize = 0.0;
55
56 // product specific shift size, type, scheme
57 map<string, ShiftType> keyedShiftType;
58 map<string, Real> keyedShiftSize;
59 map<string, ShiftScheme> keyedShiftScheme;
60 };
61
65 virtual ~CurveShiftData() {}
66 vector<Period> shiftTenors;
67 };
68
70
74 string ccy;
75 vector<Period> shiftExpiries;
76 };
77
81 vector<Period> shiftTerms;
82 vector<Real> shiftLossLevels;
83 string indexName;
84 };
85
87 VolShiftData() : shiftStrikes({0.0}), isRelative(false) {}
88 VolShiftData(const ShiftData& d) : ShiftData(d), shiftStrikes({0.0}), isRelative(false) {}
89 vector<Period> shiftExpiries;
90 vector<Real> shiftStrikes;
92 };
93
97 string indexName;
98 };
99
103 vector<Period> shiftTerms;
104 };
105
109 vector<string> parInstruments;
111
112 // Allows direct specification of discount curve if parInstrumentSingleCurve is false
113 // If not given, we default to old behaviour of using the market's discount curve for
114 // that currency. This string will be an index name that is searched for in the market.
115 std::string discountCurve;
116
117 // Allow specification of the other currency when creating cross currency basis swap
118 // par instruments for discount curves. If left empty, we take the base currency of the
119 // run as the other leg's currency.
120 std::string otherCurrency;
121
122 map<string, string> parInstrumentConventions;
123 };
124
128 vector<string> parInstruments;
130
131 // Allows direct specification of discount curve
132 // If not given, we default to old behaviour of using the market's discount curve for
133 // that currency. This string will be an index name that is searched for in the market.
134 std::string discountCurve;
135
136 map<string, string> parInstrumentConventions;
137 };
138
139 //! Default constructor
142
143 //! \name Inspectors
144 //@{
145 const map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& discountCurveShiftData() const {
147 }
148 const map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& indexCurveShiftData() const { return indexCurveShiftData_; }
149 const map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& yieldCurveShiftData() const { return yieldCurveShiftData_; }
150 const map<string, SpotShiftData>& fxShiftData() const { return fxShiftData_; }
151 const map<string, QuantLib::ext::shared_ptr<CapFloorVolShiftData>>& capFloorVolShiftData() const {
153 }
154 const map<string, GenericYieldVolShiftData>& swaptionVolShiftData() const { return swaptionVolShiftData_; }
155 const map<string, GenericYieldVolShiftData>& yieldVolShiftData() const { return yieldVolShiftData_; }
156 const map<string, VolShiftData>& fxVolShiftData() const { return fxVolShiftData_; }
157 const map<string, CdsVolShiftData>& cdsVolShiftData() const { return cdsVolShiftData_; }
158 const map<string, BaseCorrelationShiftData>& baseCorrelationShiftData() const { return baseCorrelationShiftData_; }
159 const map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& zeroInflationCurveShiftData() const {
161 }
162 const map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& yoyInflationCurveShiftData() const {
164 }
165 const map<string, QuantLib::ext::shared_ptr<CapFloorVolShiftData>>& yoyInflationCapFloorVolShiftData() const {
167 }
168 const map<string, QuantLib::ext::shared_ptr<CapFloorVolShiftData>>& zeroInflationCapFloorVolShiftData() const {
170 }
171 const map<string, string>& creditCcys() const { return creditCcys_; }
172 const map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& creditCurveShiftData() const { return creditCurveShiftData_; }
173 const map<string, SpotShiftData>& equityShiftData() const { return equityShiftData_; }
174 const map<string, VolShiftData>& equityVolShiftData() const { return equityVolShiftData_; }
175 const map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& dividendYieldShiftData() const {
177 }
178 const map<string, string>& commodityCurrencies() const { return commodityCurrencies_; }
179 const map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& commodityCurveShiftData() const {
181 }
182 const map<string, VolShiftData>& commodityVolShiftData() const { return commodityVolShiftData_; }
183 const map<string, VolShiftData>& correlationShiftData() const { return correlationShiftData_; }
184 const map<string, SpotShiftData>& securityShiftData() const { return securityShiftData_; }
185
186 const vector<pair<string, string>>& crossGammaFilter() const { return crossGammaFilter_; }
187 const bool computeGamma() const { return computeGamma_; }
189
190 //! Give back the shift data for the given risk factor type, \p keyType, with the given \p name
191 const ShiftData& shiftData(const ore::analytics::RiskFactorKey::KeyType& keyType, const std::string& name) const;
192 //@}
193
194 //! \name Setters
195 //@{
196 bool& parConversion() { return parConversion_; }
197
198 map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& discountCurveShiftData() { return discountCurveShiftData_; }
199 map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& indexCurveShiftData() { return indexCurveShiftData_; }
200 map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& yieldCurveShiftData() { return yieldCurveShiftData_; }
201 map<string, SpotShiftData>& fxShiftData() { return fxShiftData_; }
202 map<string, GenericYieldVolShiftData>& swaptionVolShiftData() { return swaptionVolShiftData_; }
203 map<string, GenericYieldVolShiftData>& yieldVolShiftData() { return yieldVolShiftData_; }
204 map<string, QuantLib::ext::shared_ptr<CapFloorVolShiftData>>& capFloorVolShiftData() { return capFloorVolShiftData_; }
205 map<string, VolShiftData>& fxVolShiftData() { return fxVolShiftData_; }
206 map<string, CdsVolShiftData>& cdsVolShiftData() { return cdsVolShiftData_; }
207 map<string, BaseCorrelationShiftData>& baseCorrelationShiftData() { return baseCorrelationShiftData_; }
208 map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& zeroInflationCurveShiftData() {
210 }
211 map<string, string>& creditCcys() { return creditCcys_; }
212 map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& creditCurveShiftData() { return creditCurveShiftData_; }
213 map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& yoyInflationCurveShiftData() { return yoyInflationCurveShiftData_; }
214 map<string, QuantLib::ext::shared_ptr<CapFloorVolShiftData>>& yoyInflationCapFloorVolShiftData() {
216 }
217 map<string, QuantLib::ext::shared_ptr<CapFloorVolShiftData>>& zeroInflationCapFloorVolShiftData() {
219 }
220 map<string, SpotShiftData>& equityShiftData() { return equityShiftData_; }
221 map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& dividendYieldShiftData() { return dividendYieldShiftData_; }
222 map<string, VolShiftData>& equityVolShiftData() { return equityVolShiftData_; }
223 map<string, string>& commodityCurrencies() { return commodityCurrencies_; }
224 map<string, QuantLib::ext::shared_ptr<CurveShiftData>>& commodityCurveShiftData() { return commodityCurveShiftData_; }
225 map<string, VolShiftData>& commodityVolShiftData() { return commodityVolShiftData_; }
226 map<string, VolShiftData>& correlationShiftData() { return correlationShiftData_; }
227 map<string, SpotShiftData>& securityShiftData() { return securityShiftData_; }
228
229 vector<pair<string, string>>& crossGammaFilter() { return crossGammaFilter_; }
230 bool& computeGamma() { return computeGamma_; }
232 //@}
233
234 //! \name Serialisation
235 //@{
236 virtual void fromXML(XMLNode* node) override;
237 virtual XMLNode* toXML(ore::data::XMLDocument& doc) const override;
238 //@}
239
240 //! \name Equality Operators
241 //@{
242 // bool operator==(const SensitivityScenarioData& rhs);
243 // bool operator!=(const SensitivityScenarioData& rhs);
244 //@}
245
246 //! Utilities
247 //@{
248 string getIndexCurrency(string indexName);
249 //@}
250
251protected:
252 void shiftDataFromXML(XMLNode* child, ShiftData& data);
253 void curveShiftDataFromXML(XMLNode* child, CurveShiftData& data);
254 void volShiftDataFromXML(XMLNode* child, VolShiftData& data, const bool requireShiftStrikes = true);
255
256 //! toXML helper methods
257 //@{
258 void shiftDataToXML(ore::data::XMLDocument& doc, XMLNode* node, const ShiftData& data) const;
259 void curveShiftDataToXML(ore::data::XMLDocument& doc, XMLNode* node, const CurveShiftData& data) const;
260 void volShiftDataToXML(ore::data::XMLDocument& doc, XMLNode* node, const VolShiftData& data) const;
261 //@}
262
263 map<string, QuantLib::ext::shared_ptr<CurveShiftData>> discountCurveShiftData_; // key: ccy
264 map<string, QuantLib::ext::shared_ptr<CurveShiftData>> indexCurveShiftData_; // key: indexName
265 map<string, QuantLib::ext::shared_ptr<CurveShiftData>> yieldCurveShiftData_; // key: yieldCurveName
266 map<string, SpotShiftData> fxShiftData_; // key: ccy pair
267 map<string, QuantLib::ext::shared_ptr<CapFloorVolShiftData>> capFloorVolShiftData_; // key: ccy
268 map<string, GenericYieldVolShiftData> swaptionVolShiftData_; // key: ccy
269 map<string, GenericYieldVolShiftData> yieldVolShiftData_; // key: securityId
270 map<string, VolShiftData> fxVolShiftData_; // key: ccy pair
271 map<string, CdsVolShiftData> cdsVolShiftData_; // key: ccy pair
272 map<string, BaseCorrelationShiftData> baseCorrelationShiftData_;
273 map<string, QuantLib::ext::shared_ptr<CurveShiftData>> zeroInflationCurveShiftData_; // key: inflation index name
274 map<string, QuantLib::ext::shared_ptr<CurveShiftData>> yoyInflationCurveShiftData_; // key: yoy inflation index name
275 map<string, QuantLib::ext::shared_ptr<CapFloorVolShiftData>> yoyInflationCapFloorVolShiftData_; // key: inflation index name
276 map<string, QuantLib::ext::shared_ptr<CapFloorVolShiftData>>
277 zeroInflationCapFloorVolShiftData_; // key: inflation index name
278 map<string, string> creditCcys_;
279 map<string, QuantLib::ext::shared_ptr<CurveShiftData>> creditCurveShiftData_; // key: credit name
280 map<string, SpotShiftData> equityShiftData_; // key: equity name
281 map<string, VolShiftData> equityVolShiftData_; // key: equity name
282 map<string, QuantLib::ext::shared_ptr<CurveShiftData>> dividendYieldShiftData_; // key: equity name
283 map<string, std::string> commodityCurrencies_;
284 map<string, QuantLib::ext::shared_ptr<CurveShiftData>> commodityCurveShiftData_;
285 map<string, VolShiftData> correlationShiftData_;
286 map<string, VolShiftData> commodityVolShiftData_;
287 map<string, SpotShiftData> securityShiftData_; // key: security name
288
289 vector<pair<string, string>> crossGammaFilter_;
293
294private:
295 void parDataFromXML(XMLNode* child, CurveShiftParData& data);
296
297 //! toXML helper method
298 XMLNode* parDataToXML(ore::data::XMLDocument& doc, const QuantLib::ext::shared_ptr<CurveShiftData>& csd) const;
299};
300
301// Utility to extract the set of keys that are used in a sensi config to qualiffy shift specs
302std::set<std::string> getShiftSpecKeys(const SensitivityScenarioData& d);
303
304} // namespace analytics
305} // namespace ore
KeyType
Risk Factor types.
Definition: scenario.hpp:51
Description of sensitivity shift scenarios.
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & discountCurveShiftData()
void shiftDataFromXML(XMLNode *child, ShiftData &data)
map< string, GenericYieldVolShiftData > swaptionVolShiftData_
map< string, CdsVolShiftData > & cdsVolShiftData()
map< string, GenericYieldVolShiftData > & yieldVolShiftData()
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & indexCurveShiftData()
const map< string, QuantLib::ext::shared_ptr< CapFloorVolShiftData > > & yoyInflationCapFloorVolShiftData() const
const map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & indexCurveShiftData() const
map< string, QuantLib::ext::shared_ptr< CapFloorVolShiftData > > capFloorVolShiftData_
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > commodityCurveShiftData_
const map< string, QuantLib::ext::shared_ptr< CapFloorVolShiftData > > & capFloorVolShiftData() const
const map< string, SpotShiftData > & securityShiftData() const
const ShiftData & shiftData(const ore::analytics::RiskFactorKey::KeyType &keyType, const std::string &name) const
Give back the shift data for the given risk factor type, keyType, with the given name.
map< string, BaseCorrelationShiftData > & baseCorrelationShiftData()
map< string, QuantLib::ext::shared_ptr< CapFloorVolShiftData > > yoyInflationCapFloorVolShiftData_
vector< pair< string, string > > & crossGammaFilter()
const map< string, string > & creditCcys() const
const map< string, VolShiftData > & equityVolShiftData() const
string getIndexCurrency(string indexName)
Utilities.
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > creditCurveShiftData_
const map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & discountCurveShiftData() const
SensitivityScenarioData(bool parConversion=true)
Default constructor.
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & commodityCurveShiftData()
const map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & dividendYieldShiftData() const
map< string, VolShiftData > & fxVolShiftData()
vector< pair< string, string > > crossGammaFilter_
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > zeroInflationCurveShiftData_
const map< string, VolShiftData > & fxVolShiftData() const
const map< string, GenericYieldVolShiftData > & yieldVolShiftData() const
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > yoyInflationCurveShiftData_
const map< string, VolShiftData > & correlationShiftData() const
const map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & zeroInflationCurveShiftData() const
const vector< pair< string, string > > & crossGammaFilter() const
void parDataFromXML(XMLNode *child, CurveShiftParData &data)
map< string, GenericYieldVolShiftData > yieldVolShiftData_
map< string, VolShiftData > & commodityVolShiftData()
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & dividendYieldShiftData()
const map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & creditCurveShiftData() const
map< string, CdsVolShiftData > cdsVolShiftData_
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & creditCurveShiftData()
XMLNode * parDataToXML(ore::data::XMLDocument &doc, const QuantLib::ext::shared_ptr< CurveShiftData > &csd) const
toXML helper method
virtual void fromXML(XMLNode *node) override
map< string, VolShiftData > & correlationShiftData()
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > yieldCurveShiftData_
void curveShiftDataFromXML(XMLNode *child, CurveShiftData &data)
const map< string, SpotShiftData > & fxShiftData() const
const map< string, GenericYieldVolShiftData > & swaptionVolShiftData() const
const map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & yoyInflationCurveShiftData() const
void volShiftDataToXML(ore::data::XMLDocument &doc, XMLNode *node, const VolShiftData &data) const
map< string, SpotShiftData > & equityShiftData()
const map< string, QuantLib::ext::shared_ptr< CapFloorVolShiftData > > & zeroInflationCapFloorVolShiftData() const
map< string, QuantLib::ext::shared_ptr< CapFloorVolShiftData > > & capFloorVolShiftData()
virtual XMLNode * toXML(ore::data::XMLDocument &doc) const override
void volShiftDataFromXML(XMLNode *child, VolShiftData &data, const bool requireShiftStrikes=true)
const map< string, BaseCorrelationShiftData > & baseCorrelationShiftData() const
map< string, BaseCorrelationShiftData > baseCorrelationShiftData_
const map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & yieldCurveShiftData() const
const map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & commodityCurveShiftData() const
map< string, SpotShiftData > & securityShiftData()
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & yieldCurveShiftData()
map< string, QuantLib::ext::shared_ptr< CapFloorVolShiftData > > & yoyInflationCapFloorVolShiftData()
map< string, SpotShiftData > & fxShiftData()
const map< string, string > & commodityCurrencies() const
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > dividendYieldShiftData_
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > discountCurveShiftData_
void curveShiftDataToXML(ore::data::XMLDocument &doc, XMLNode *node, const CurveShiftData &data) const
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > indexCurveShiftData_
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & zeroInflationCurveShiftData()
map< string, QuantLib::ext::shared_ptr< CapFloorVolShiftData > > zeroInflationCapFloorVolShiftData_
map< string, VolShiftData > & equityVolShiftData()
map< string, QuantLib::ext::shared_ptr< CurveShiftData > > & yoyInflationCurveShiftData()
const map< string, VolShiftData > & commodityVolShiftData() const
map< string, GenericYieldVolShiftData > & swaptionVolShiftData()
void shiftDataToXML(ore::data::XMLDocument &doc, XMLNode *node, const ShiftData &data) const
toXML helper methods
const map< string, CdsVolShiftData > & cdsVolShiftData() const
const map< string, SpotShiftData > & equityShiftData() const
map< string, QuantLib::ext::shared_ptr< CapFloorVolShiftData > > & zeroInflationCapFloorVolShiftData()
std::set< std::string > getShiftSpecKeys(const SensitivityScenarioData &d)
Scenario class.
SensitivityScenarioData::CurveShiftData CurveShiftData