Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
decomposedsensitivitystream.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2023 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 orea/engine/Decomposedsensitivitystream.hpp
20 \brief Class that wraps a sensitivity stream and decomposes equity/commodity and default risk records
21 */
22
23#pragma once
29
30#include <fstream>
31#include <set>
32#include <string>
33
34namespace ore {
35namespace analytics {
36
37//! Class that wraps a sensitivity stream and decompose default, equity and commodity risk records given weights
39public:
40 /*! Constructor providing the weights for the credit index decomposition and the ids and reference data used for
41 */
43 const QuantLib::ext::shared_ptr<SensitivityStream>& ss, const std::string& baseCurrency,
44 std::map<std::string, std::map<std::string, double>> defaultRiskDecompositionWeights = {},
45 const std::set<std::string>& eqComDecompositionTradeIds = {},
46 const std::map<std::string, std::map<std::string, double>>& currencyHedgedIndexQuantities = {},
47 const QuantLib::ext::shared_ptr<ore::data::ReferenceDataManager>& refDataManager = nullptr,
48 const QuantLib::ext::shared_ptr<ore::data::CurveConfigurations>& curveConfigs = nullptr,
49 const QuantLib::ext::shared_ptr<SensitivityScenarioData>& scenarioData = nullptr,
50 const QuantLib::ext::shared_ptr<ore::data::Market>& todaysMarket = nullptr);
51 //! Returns the next SensitivityRecord in the stream after filtering
52 SensitivityRecord next() override;
53 //! Resets the stream so that SensitivityRecord objects can be streamed again
54 void reset() override;
55
56private:
57 // Result of a equity / commodity index decomposition
59 std::map<std::string, double> spotRisk;
60 std::map<std::string, double> fxRisk;
61 std::string indexCurrency;
62 };
63
64
65 //! Decompose a equity/commodity spot sensitivity into the constituent spot sensistivities
66 std::map<std::string, double>
67 constituentSpotRiskFromDecomposition(const double spotDelta, const std::map<std::string, double>& indexWeights) const;
68
69 //! Compute the resulting fx risks from a given equity/commodity decomposition
70 std::map<std::string, double>
71 fxRiskFromDecomposition(const std::map<std::string, double>& spotRisk,
72 const std::map<std::string, std::vector<std::string>>& constituentCurrencies,
73 const std::map<std::string, double>& fxSpotShiftSize, const double eqShiftSize) const;
74
75 //! Return the sensi shift size for the shifting the ccy-baseCurrency spot quote
76 double fxRiskShiftSize(const std::string ccy) const;
77 //! Returns the shift sizes for all currencies in the map
78 std::map<std::string, double> fxRiskShiftSizes(const std::map<std::string, std::vector<std::string>>& constituentCurrencies) const;
79
80 //! Return the asset spot shift size
81 double assetSpotShiftSize(const std::string name, const ore::data::CurveSpec::CurveType curveType) const;
82 double equitySpotShiftSize(const std::string name) const;
83 double commoditySpotShiftSize(const std::string name) const;
84
85 std::map<std::string, std::vector<std::string>> getConstituentCurrencies(const std::map<std::string, double>& constituents,
86 const std::string& indexCurrency,
87 const ore::data::CurveSpec::CurveType curveType) const;
88
89 //! Decompose the record and add it to the internal storage;
90 std::vector<SensitivityRecord> decompose(const SensitivityRecord& record) const;
91 std::vector<SensitivityRecord> decomposeSurvivalProbability(const SensitivityRecord& record) const;
92 std::vector<SensitivityRecord> decomposeCurrencyHedgedIndexRisk(const SensitivityRecord& record) const;
93
94 IndexDecompositionResult indexDecomposition(double delta, const std::string& indexName,
95 const ore::data::CurveSpec::CurveType curveType) const;
96
97 std::vector<SensitivityRecord> sensitivityRecords(const std::map<std::string, double>& eqDeltas,
98 const std::map<std::string, double>& fxDeltas,
99 const std::string indexCurrency,
100 const SensitivityRecord& orginialRecord) const;
101
102 // get the curve currency for name, fallback to check equity curves
103 std::string curveCurrency(const std::string& name, ore::data::CurveSpec::CurveType curveType) const;
104 // Scale the fx risk entries from the index decomposition
105 std::vector<SensitivityRecord> decomposedRecords_;
106 std::vector<SensitivityRecord>::iterator itCurrent_;
107
108 //! The underlying sensitivity stream that has been wrapped
109 QuantLib::ext::shared_ptr<SensitivityStream> ss_;
110 std::string baseCurrency_;
111 //! map of trade ids to the basket consituents with their resp. weights
112 std::map<std::string, std::map<std::string, double>> defaultRiskDecompositionWeights_;
113 //! list of trade id, for which a equity index decomposition should be applied
114 std::set<std::string> eqComDecompositionTradeIds_;
115 //! list of trade id, for which a commodity index decomposition should be applied
116 std::map<std::string, std::map<std::string, double>> currencyHedgedIndexQuantities_;
117 //! refDataManager holding the equity and commodity index decomposition weights
118 QuantLib::ext::shared_ptr<ore::data::ReferenceDataManager> refDataManager_;
119 QuantLib::ext::shared_ptr<ore::data::CurveConfigurations> curveConfigs_;
120 QuantLib::ext::shared_ptr<SensitivityScenarioData> ssd_;
121 // needed for currency hedged index decomposition
122 QuantLib::ext::shared_ptr<ore::data::Market> todaysMarket_;
123 // flag if decompose is possible
125};
126
127} // namespace analytics
128} // namespace ore
Class that wraps a sensitivity stream and decompose default, equity and commodity risk records given ...
QuantLib::ext::shared_ptr< ore::data::CurveConfigurations > curveConfigs_
std::map< std::string, std::vector< std::string > > getConstituentCurrencies(const std::map< std::string, double > &constituents, const std::string &indexCurrency, const ore::data::CurveSpec::CurveType curveType) const
QuantLib::ext::shared_ptr< ore::data::Market > todaysMarket_
IndexDecompositionResult indexDecomposition(double delta, const std::string &indexName, const ore::data::CurveSpec::CurveType curveType) const
double commoditySpotShiftSize(const std::string name) const
double assetSpotShiftSize(const std::string name, const ore::data::CurveSpec::CurveType curveType) const
Return the asset spot shift size.
std::string curveCurrency(const std::string &name, ore::data::CurveSpec::CurveType curveType) const
double equitySpotShiftSize(const std::string name) const
QuantLib::ext::shared_ptr< SensitivityScenarioData > ssd_
std::vector< SensitivityRecord > decomposeSurvivalProbability(const SensitivityRecord &record) const
QuantLib::ext::shared_ptr< SensitivityStream > ss_
The underlying sensitivity stream that has been wrapped.
std::vector< SensitivityRecord > decompose(const SensitivityRecord &record) const
Decompose the record and add it to the internal storage;.
std::map< std::string, double > fxRiskFromDecomposition(const std::map< std::string, double > &spotRisk, const std::map< std::string, std::vector< std::string > > &constituentCurrencies, const std::map< std::string, double > &fxSpotShiftSize, const double eqShiftSize) const
Compute the resulting fx risks from a given equity/commodity decomposition.
QuantLib::ext::shared_ptr< ore::data::ReferenceDataManager > refDataManager_
refDataManager holding the equity and commodity index decomposition weights
double fxRiskShiftSize(const std::string ccy) const
Return the sensi shift size for the shifting the ccy-baseCurrency spot quote.
std::vector< SensitivityRecord >::iterator itCurrent_
std::map< std::string, std::map< std::string, double > > currencyHedgedIndexQuantities_
list of trade id, for which a commodity index decomposition should be applied
std::vector< SensitivityRecord > decomposeCurrencyHedgedIndexRisk(const SensitivityRecord &record) const
std::map< std::string, double > constituentSpotRiskFromDecomposition(const double spotDelta, const std::map< std::string, double > &indexWeights) const
Decompose a equity/commodity spot sensitivity into the constituent spot sensistivities.
std::map< std::string, double > fxRiskShiftSizes(const std::map< std::string, std::vector< std::string > > &constituentCurrencies) const
Returns the shift sizes for all currencies in the map.
std::vector< SensitivityRecord > sensitivityRecords(const std::map< std::string, double > &eqDeltas, const std::map< std::string, double > &fxDeltas, const std::string indexCurrency, const SensitivityRecord &orginialRecord) const
void reset() override
Resets the stream so that SensitivityRecord objects can be streamed again.
SensitivityRecord next() override
Returns the next SensitivityRecord in the stream after filtering.
std::set< std::string > eqComDecompositionTradeIds_
list of trade id, for which a equity index decomposition should be applied
std::map< std::string, std::map< std::string, double > > defaultRiskDecompositionWeights_
map of trade ids to the basket consituents with their resp. weights
Base Class for streaming SensitivityRecords.
A class to hold the parametrisation for building sensitivity scenarios.
Base class for sensitivity record streamer.
vector< string > curveConfigs