Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ScenarioShiftCalculator Class Reference

#include <orea/scenario/scenarioshiftcalculator.hpp>

+ Collaboration diagram for ScenarioShiftCalculator:

Public Member Functions

 ScenarioShiftCalculator (const QuantLib::ext::shared_ptr< ore::analytics::SensitivityScenarioData > &sensitivityConfig, const QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > &simMarketConfig, const QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &simMarket=QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket >())
 
QuantLib::Real shift (const ore::analytics::RiskFactorKey &key, const ore::analytics::Scenario &s_1, const ore::analytics::Scenario &s_2) const
 

Private Member Functions

QuantLib::Real transform (const ore::analytics::RiskFactorKey &key, QuantLib::Real value, const QuantLib::Date &asof) const
 

Private Attributes

QuantLib::ext::shared_ptr< ore::analytics::SensitivityScenarioDatasensitivityConfig_
 
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameterssimMarketConfig_
 
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketsimMarket_
 

Detailed Description

Class for calculating the shift multiple between two scenarios for a given risk factor key.

The shift value returned is a value that is consistent with the SensitivityScenarioData and ScenarioSimMarketParameters passed in during construction. In other words, multiplying the result of the shift method with sensitivities generated using the SensitivityScenarioData configuration will give a valid estimate of the P&L move associated with moving from one scenario to another.

Definition at line 41 of file scenarioshiftcalculator.hpp.

Constructor & Destructor Documentation

◆ ScenarioShiftCalculator()

ScenarioShiftCalculator ( const QuantLib::ext::shared_ptr< ore::analytics::SensitivityScenarioData > &  sensitivityConfig,
const QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > &  simMarketConfig,
const QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > &  simMarket = QuantLib::ext::shared_ptr<ore::analytics::ScenarioSimMarket>() 
)

Constructor

Parameters
sensitivityConfigsensitivity configuration that will determine the result returned by the shift method
simMarketConfigsimulation market configuration for the scenarios that will be fed to the shift method
simMarketsimulation market that will be used if provided

Definition at line 44 of file scenarioshiftcalculator.cpp.

47 : sensitivityConfig_(sensitivityConfig), simMarketConfig_(simMarketConfig), simMarket_(simMarket) {}
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > simMarketConfig_
QuantLib::ext::shared_ptr< ore::analytics::SensitivityScenarioData > sensitivityConfig_
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarket > simMarket_

Member Function Documentation

◆ shift()

Real shift ( const ore::analytics::RiskFactorKey key,
const ore::analytics::Scenario s_1,
const ore::analytics::Scenario s_2 
) const

Calculate the shift in the risk factor key implied by going from scenario s_1 to scenario s_2.

Definition at line 49 of file scenarioshiftcalculator.cpp.

49 {
50
51 // Get the respective (transformed) scenario values
52 Real v_1 = transform(key, s_1.get(key), s_1.asof());
53 Real v_2 = transform(key, s_2.get(key), s_2.asof());
54
55 // If for any reason v_1 or v_2 are not finite or nan, log an alert and return 0
56 if (!std::isfinite(v_1) || std::isnan(v_1)) {
57 ALOG("The scenario value v_1 for key '" << key << "' is " << v_1 << " and is not usable so we are returning 0");
58 return 0.0;
59 }
60 if (!std::isfinite(v_2) || std::isnan(v_2)) {
61 ALOG("The scenario value v_2 for key '" << key << "' is " << v_2 << " and is not usable so we are returning 0");
62 return 0.0;
63 }
64
65 // Get the shift size and type from the sensitivity configuration
66 const ShiftData& shiftData = sensitivityConfig_->shiftData(key.keytype, key.name);
67 Real shiftSize = shiftData.shiftSize;
68 ShiftType shiftType = shiftData.shiftType;
69
70 // If shiftSize is zero, log an alert and return 0 early
71 if (close(shiftSize, 0.0)) {
72 ALOG("The shift size for key '" << key << "' in sensitivity config is zero");
73 return 0.0;
74 }
75
76 // Get the multiple of the sensitivity shift size in moving from scenario 1 to 2
77 Real result = 0.0;
78 if (shiftType == ShiftType::Absolute) {
79 result = v_2 - v_1;
80 } else {
81 if (close(v_1, 0.0)) {
82 ALOG("The reference scenario value for key '"
83 << key << "' is zero and the shift is relative so must return a shift of zero");
84 } else {
85 result = v_2 / v_1 - 1.0;
86 }
87 }
88 result /= shiftSize;
89
90 return result;
91}
KeyType keytype
Key type.
Definition: scenario.hpp:89
std::string name
Key name.
Definition: scenario.hpp:94
virtual const Date & asof() const =0
Return the scenario asof date.
virtual Real get(const RiskFactorKey &key) const =0
Get an element from the scenario.
QuantLib::Real transform(const ore::analytics::RiskFactorKey &key, QuantLib::Real value, const QuantLib::Date &asof) const
#define ALOG(text)
SensitivityScenarioData::ShiftData ShiftData
bool close(const Real &t_1, const Real &t_2)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ transform()

Real transform ( const ore::analytics::RiskFactorKey key,
QuantLib::Real  value,
const QuantLib::Date &  asof 
) const
private

For some risk factors, the sensitivty is understood to be to a transform of the quantity that appears in the scenario and this transform can generally require the time to expiry of the factor.

For example, the SensitivityScenarioData expresses shifts for IR in terms of zero rates and the scenarios hold discount factors so to convert the scenario value from \(df_t\) to \(z_t\), you need to know the year fraction until maturity i.e. \(\tau(0, t)\) and then the transformed value is:

\[ z_t = - \frac{\ln(df_t)}{\tau(0, t)} \]

Definition at line 93 of file scenarioshiftcalculator.cpp.

93 {
94
95 Period p;
96 DayCounter dc = Actual365Fixed();
97
98 switch (key.keytype) {
99 case RFType::DiscountCurve:
100 case RFType::YieldCurve:
101 case RFType::IndexCurve:
102 p = simMarketConfig_->yieldCurveTenors(key.name).at(key.index);
103 if (simMarket_)
104 dc = simMarket_->iborIndex(key.name)->forwardingTermStructure()->dayCounter();
105 break;
106 case RFType::DividendYield:
107 p = simMarketConfig_->equityDividendTenors(key.name).at(key.index);
108 if (simMarket_)
109 dc = simMarket_->equityDividendCurve(key.name)->dayCounter();
110 break;
111 case RFType::SurvivalProbability:
112 p = simMarketConfig_->defaultTenors(key.name).at(key.index);
113 if (simMarket_)
114 dc = simMarket_->defaultCurve(key.name)->curve()->dayCounter();
115 break;
116 default:
117 // If we get to here, return untransformed value
118 return value;
119 break;
120 }
121
122 // If we get to here, calculate transformed value
123 Time t = dc.yearFraction(asof, asof + p);
124
125 // The way that this is used above should be ok i.e. will always be 0 - 0 when t = 0
126 if (close(t, 0.0)) {
127 ALOG("The time needed in the denominator of the transform for key '"
128 << key << "' is zero so we return a transformed value of zero");
129 return 0.0;
130 }
131
132 return -log(value) / t;
133}
SafeStack< ValueType > value
RandomVariable log(RandomVariable x)
Date asof(14, Jun, 2018)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ sensitivityConfig_

QuantLib::ext::shared_ptr<ore::analytics::SensitivityScenarioData> sensitivityConfig_
private

Definition at line 61 of file scenarioshiftcalculator.hpp.

◆ simMarketConfig_

QuantLib::ext::shared_ptr<ore::analytics::ScenarioSimMarketParameters> simMarketConfig_
private

Definition at line 62 of file scenarioshiftcalculator.hpp.

◆ simMarket_

QuantLib::ext::shared_ptr<ore::analytics::ScenarioSimMarket> simMarket_
private

Definition at line 63 of file scenarioshiftcalculator.hpp.