Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
sensitivityscenariogenerator.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/sensitivityscenariogenerator.hpp
20 \brief Sensitivity scenario generation
21 \ingroup scenario
22*/
23
24#pragma once
25
32
33#include <map>
34
35namespace ore {
36namespace analytics {
37using namespace data;
38
39//! Sensitivity Scenario Generator
40/*!
41 This class builds a vector of sensitivity scenarios based on instructions in SensitivityScenarioData
42 and ScenarioSimMarketParameters objects passed.
43
44 The ScenarioSimMarketParameters object determines the scope and structure of a "simulation"
45 market (currencies, currency pairs, curve tenor points, vol matrix expiries and terms/strikes etc)
46 to which sensitivity scenarios are applied in order to compute their NPV impact.
47
48 The SensitivityScenarioData object determines the structure of shift curves (shift tenor points
49 can differ from the simulation market's tenor points), as well as type (relative/absolute) and size
50 of shifts applied.
51
52 The generator then produces comprehensive scenarios that can be applied to the simulation market,
53 i.e. covering all quotes in the simulation market, possibly filled with "base" scenario values.
54
55 Both UP and DOWN shifts are generated in order to facilitate delta and gamma calculation.
56
57 The generator currently covers the IR/FX asset class, with shifts for the following term
58 structure types:
59 - FX spot rates
60 - FX ATM volatilities
61 - Discount curve zero rates
62 - Index curve zero rates
63 - Yield curve zero rates
64 - Swaption ATM volatility matrices
65 - Yield volatility matrices
66 - Cap/Floor volatility matrices (by expiry and strike)
67
68 For Credit the generator covers shifts to the following termstructure types:
69 - Default curve integrated hazard rates.
70
71 To apply shifts to the integrated hazard rates let:
72 - S(t) be the survival probability at time t
73 - &lambda(t) be the "instantaneous" hazard rate at time t
74 - &Lambda(t) be the averaged hazard rate at time t
75
76 The relationship between these three can be expressed as:
77 \f[
78 S(t) = e^{-&Lambda(t) t}
79 \f]
80 \f[
81 &Lambda(t) = \frac{ \int_{0}^t &lambda(t) du}{t}
82 \f]
83
84 The survival probability quotes from the scenarioSimMarket default curves are then converted as follows:
85 \f[
86 &Lambda(t) = - \frac{ ln( S(t) )}{t}
87 \f]
88
89
90 Note:
91 - For yield curves, the class generates sensitivities in the Zero rate domain only.
92 Conversion into par rate sensitivities has to be implemented as a postprocessor step.
93 - Likewise, Cap/Floor volatility sensitivities are computed in the optionlet domain.
94 Conversion into par (flat cap/floor) volatility sensis has to be implemented as a
95 postprocessor step.
96
97 If sensitivityData_->generateSpreadScenarios() = true spread scenarios will be generated for
98 supported risk factor types.
99
100 \ingroup scenario
101 */
103public:
104 //! Constructor
105 SensitivityScenarioGenerator(const QuantLib::ext::shared_ptr<SensitivityScenarioData>& sensitivityData,
106 const QuantLib::ext::shared_ptr<Scenario>& baseScenario,
107 const QuantLib::ext::shared_ptr<ScenarioSimMarketParameters>& simMarketData,
108 const QuantLib::ext::shared_ptr<ScenarioSimMarket>& simMarket,
109 const QuantLib::ext::shared_ptr<ScenarioFactory>& sensiScenarioFactory,
110 const bool overrideTenors, const std::string& sensitivityTemplate = std::string(),
111 const bool continueOnError = false,
112 const QuantLib::ext::shared_ptr<Scenario>& baseScenarioAbsolute = nullptr);
113 //! Default destructor
115
116 /*! Return the map of absolute shift sizes by risk factor key for this generator
117
118 \warning Where there are tenor specific shifts the shift size is only meaningful
119 if the tenors in the sensitivity configuration line up with the tenors in
120 the simulation market configuration. If this is not the case, an absolute
121 shift size of <code>Null<Real>()</code> is added for the given risk factor
122 key
123 */
124 const std::map<RiskFactorKey, QuantLib::Real>& shiftSizes() const { return shiftSizes_; }
125
126 /* Return the map of (delta) shift schemes */
127 const std::map<RiskFactorKey, ShiftScheme>& shiftSchemes() const { return shiftSchemes_; }
128
129 /*! Similarly, reeturn the base values for each risk factor */
130 const std::map<RiskFactorKey, QuantLib::Real>& baseValues() const { return baseValues_; }
131
132 Size numScenarios() const { return scenarios_.size(); }
133
134 QuantLib::ext::shared_ptr<Scenario> baseScenarioAbsolute() const { return baseScenarioAbsolute_; }
135
136private:
141 void storeShiftData(const RiskFactorKey& key, const Real rate, const Real newRate);
142
143 void generateScenarios();
144 void generateYieldCurveScenarios(bool up);
145 void generateDiscountCurveScenarios(bool up);
146 void generateIndexCurveScenarios(bool up);
147 void generateFxScenarios(bool up);
148 void generateEquityScenarios(bool up);
149 void generateDividendYieldScenarios(bool up);
150 void generateSwaptionVolScenarios(bool up);
151 void generateYieldVolScenarios(bool up);
152 void generateFxVolScenarios(bool up);
153 void generateEquityVolScenarios(bool up);
154 void generateCapFloorVolScenarios(bool up);
156 void generateCdsVolScenarios(bool up);
157 void generateZeroInflationScenarios(bool up);
159 void generateYoYInflationScenarios(bool up);
163 void generateCommodityVolScenarios(bool up);
165 void generateCorrelationScenarios(bool up);
166
167 // common helper for generateSwaptionVolScenarios(), generateYieldVolScenarios()
169
170 ScenarioDescription discountScenarioDescription(string ccy, Size bucket, bool up, ShiftScheme shiftScheme);
171 ScenarioDescription indexScenarioDescription(string index, Size bucket, bool up, ShiftScheme shiftScheme);
172 ScenarioDescription yieldScenarioDescription(string name, Size bucket, bool up, ShiftScheme shiftScheme);
173 ScenarioDescription fxScenarioDescription(string ccypair, bool up, ShiftScheme shiftScheme);
174 ScenarioDescription fxVolScenarioDescription(string ccypair, Size expiryBucket, Size strikeBucket, bool up,
175 ShiftScheme shiftScheme);
176 ScenarioDescription equityScenarioDescription(string equity, bool up, ShiftScheme shiftScheme);
177 ScenarioDescription dividendYieldScenarioDescription(string equity, Size bucket, bool up, ShiftScheme shiftScheme);
178 ScenarioDescription equityVolScenarioDescription(string equity, Size expiryBucket, Size strikeBucket, bool up,
179 ShiftScheme shiftScheme);
180 ScenarioDescription swaptionVolScenarioDescription(string ccy, Size expiryBucket, Size termBucket,
181 Size strikeBucket, bool up, ShiftScheme shiftScheme);
182 ScenarioDescription yieldVolScenarioDescription(string securityId, Size expiryBucket, Size termBucket, bool up,
183 ShiftScheme shiftScheme);
184 ScenarioDescription capFloorVolScenarioDescription(string ccy, Size expiryBucket, Size strikeBucket, bool up,
185 bool isAtm, ShiftScheme shiftScheme);
186 ScenarioDescription survivalProbabilityScenarioDescription(string name, Size bucket, bool up,
187 ShiftScheme shiftScheme);
188 ScenarioDescription CdsVolScenarioDescription(string name, Size expiryBucket, Size strikeBucket, bool up,
189 ShiftScheme shiftScheme);
190 ScenarioDescription zeroInflationScenarioDescription(string index, Size bucket, bool up, ShiftScheme shiftScheme);
191 ScenarioDescription yoyInflationScenarioDescription(string index, Size bucket, bool up, ShiftScheme shiftScheme);
192 ScenarioDescription zeroInflationCapFloorVolScenarioDescription(string name, Size expiryBucket, Size strikeBucket,
193 bool up, ShiftScheme shiftScheme);
194 ScenarioDescription yoyInflationCapFloorVolScenarioDescription(string name, Size expiryBucket, Size strikeBucket,
195 bool up, ShiftScheme shiftScheme);
196 ScenarioDescription baseCorrelationScenarioDescription(string indexName, Size lossLevelBucket, Size termBucket,
197 bool up, ShiftScheme shiftScheme);
198 ScenarioDescription commodityCurveScenarioDescription(const std::string& commodityName, QuantLib::Size bucket,
199 bool up, ShiftScheme shiftScheme);
200 ScenarioDescription commodityVolScenarioDescription(const std::string& commodityName, QuantLib::Size expiryBucket,
201 QuantLib::Size strikeBucket, bool up, ShiftScheme shiftScheme);
202 ScenarioDescription securitySpreadScenarioDescription(string bond, bool up, ShiftScheme shiftScheme);
203 ScenarioDescription correlationScenarioDescription(string pair, Size expiryBucket, Size strikeBucket, bool up,
204 ShiftScheme shiftScheme);
205
206 QuantLib::ext::shared_ptr<SensitivityScenarioData> sensitivityData_;
207 QuantLib::ext::shared_ptr<ScenarioFactory> sensiScenarioFactory_;
210
211 //! Holds the shift sizes for each risk factor key
212 std::map<RiskFactorKey, QuantLib::Real> shiftSizes_;
213 //! Holds the delta shift schemes for each risk factor key
214 std::map<RiskFactorKey, ShiftScheme> shiftSchemes_;
215 //! Holds the base valuesfor each risk factor key
216 std::map<RiskFactorKey, QuantLib::Real> baseValues_;
217
218 QuantLib::ext::shared_ptr<Scenario> baseScenarioAbsolute_;
219};
220} // namespace analytics
221} // namespace ore
Data types stored in the scenario class.
Definition: scenario.hpp:48
KeyType
Risk Factor types.
Definition: scenario.hpp:51
const std::map< RiskFactorKey, QuantLib::Real > & baseValues() const
ScenarioDescription fxVolScenarioDescription(string ccypair, Size expiryBucket, Size strikeBucket, bool up, ShiftScheme shiftScheme)
ScenarioDescription indexScenarioDescription(string index, Size bucket, bool up, ShiftScheme shiftScheme)
std::map< RiskFactorKey, ShiftScheme > shiftSchemes_
Holds the delta shift schemes for each risk factor key.
QuantLib::ext::shared_ptr< ScenarioFactory > sensiScenarioFactory_
ScenarioDescription correlationScenarioDescription(string pair, Size expiryBucket, Size strikeBucket, bool up, ShiftScheme shiftScheme)
QuantLib::ext::shared_ptr< SensitivityScenarioData > sensitivityData_
ScenarioDescription yieldScenarioDescription(string name, Size bucket, bool up, ShiftScheme shiftScheme)
ScenarioDescription commodityVolScenarioDescription(const std::string &commodityName, QuantLib::Size expiryBucket, QuantLib::Size strikeBucket, bool up, ShiftScheme shiftScheme)
ScenarioDescription fxScenarioDescription(string ccypair, bool up, ShiftScheme shiftScheme)
ScenarioDescription dividendYieldScenarioDescription(string equity, Size bucket, bool up, ShiftScheme shiftScheme)
ScenarioDescription zeroInflationCapFloorVolScenarioDescription(string name, Size expiryBucket, Size strikeBucket, bool up, ShiftScheme shiftScheme)
const std::map< RiskFactorKey, QuantLib::Real > & shiftSizes() const
QuantLib::ext::shared_ptr< Scenario > baseScenarioAbsolute() const
ScenarioDescription securitySpreadScenarioDescription(string bond, bool up, ShiftScheme shiftScheme)
ScenarioDescription yoyInflationScenarioDescription(string index, Size bucket, bool up, ShiftScheme shiftScheme)
ScenarioDescription zeroInflationScenarioDescription(string index, Size bucket, bool up, ShiftScheme shiftScheme)
std::map< RiskFactorKey, QuantLib::Real > baseValues_
Holds the base valuesfor each risk factor key.
void storeShiftData(const RiskFactorKey &key, const Real rate, const Real newRate)
std::map< RiskFactorKey, QuantLib::Real > shiftSizes_
Holds the shift sizes for each risk factor key.
ScenarioDescription baseCorrelationScenarioDescription(string indexName, Size lossLevelBucket, Size termBucket, bool up, ShiftScheme shiftScheme)
ScenarioDescription survivalProbabilityScenarioDescription(string name, Size bucket, bool up, ShiftScheme shiftScheme)
QuantLib::ext::shared_ptr< Scenario > baseScenarioAbsolute_
ScenarioDescription equityVolScenarioDescription(string equity, Size expiryBucket, Size strikeBucket, bool up, ShiftScheme shiftScheme)
ScenarioDescription CdsVolScenarioDescription(string name, Size expiryBucket, Size strikeBucket, bool up, ShiftScheme shiftScheme)
ScenarioDescription yoyInflationCapFloorVolScenarioDescription(string name, Size expiryBucket, Size strikeBucket, bool up, ShiftScheme shiftScheme)
bool isScenarioRelevant(bool up, SensitivityScenarioData::ShiftData &data) const
void generateGenericYieldVolScenarios(bool up, RiskFactorKey::KeyType rfType)
ScenarioDescription yieldVolScenarioDescription(string securityId, Size expiryBucket, Size termBucket, bool up, ShiftScheme shiftScheme)
const std::map< RiskFactorKey, ShiftScheme > & shiftSchemes() const
ShiftScheme getShiftScheme(SensitivityScenarioData::ShiftData &data) const
ScenarioDescription discountScenarioDescription(string ccy, Size bucket, bool up, ShiftScheme shiftScheme)
ScenarioDescription swaptionVolScenarioDescription(string ccy, Size expiryBucket, Size termBucket, Size strikeBucket, bool up, ShiftScheme shiftScheme)
ShiftType getShiftType(SensitivityScenarioData::ShiftData &data) const
ScenarioDescription commodityCurveScenarioDescription(const std::string &commodityName, QuantLib::Size bucket, bool up, ShiftScheme shiftScheme)
Real getShiftSize(SensitivityScenarioData::ShiftData &data) const
ScenarioDescription capFloorVolScenarioDescription(string ccy, Size expiryBucket, Size strikeBucket, bool up, bool isAtm, ShiftScheme shiftScheme)
ScenarioDescription equityScenarioDescription(string equity, bool up, ShiftScheme shiftScheme)
const QuantLib::ext::shared_ptr< Scenario > & baseScenario()
Return the base scenario, i.e. cached initial values of all relevant market points.
std::vector< QuantLib::ext::shared_ptr< Scenario > > scenarios_
data
factory classes for scenarios
Scenario generator base classes.
A Market class that can be updated by Scenarios.
A class to hold the parametrisation for building sensitivity scenarios.
Shift scenario generation.