Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
simmcalibration.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/simm/simmcalibration.hpp
20 \brief SIMM class for defining SIMM risk weights, thresholds, buckets, and labels.
21 Currently only supports the latest ISDA SIMM versions
22 (apart from changes in the aforementioned four things).
23*/
24
25#pragma once
26
27#include <boost/any.hpp>
30
31#include <map>
32#include <string>
33
34namespace ore {
35namespace analytics {
36
38public:
39 typedef std::map<std::tuple<std::string, std::string, std::string>, std::string> Amounts;
40 typedef std::map<std::tuple<std::string, std::string, std::string>, std::set<std::string>> CurrencyLists;
42 public:
43 Amount() {}
44 Amount(const std::string& bucket, const std::string& label1, const std::string& label2,
45 const std::string& value)
47 Amount(const std::tuple<std::string, std::string, std::string>& key, const std::string& value);
49
51 void fromXML(ore::data::XMLNode* node) override;
52
53 const std::tuple<std::string, std::string, std::string> key() const;
54
55 const std::string& bucket() const { return bucket_; }
56 const std::string& label1() const { return label1_; }
57 const std::string& label2() const { return label2_; }
58 const std::string& value() const { return value_; }
59
60 private:
61 std::string bucket_, label1_, label2_, value_;
62 };
63
65 public:
67 public:
71
72 virtual const std::map<CrifRecord::RiskType, std::map<QuantLib::Size, QuantLib::ext::shared_ptr<Amount>>>
74 return std::map<CrifRecord::RiskType, std::map<QuantLib::Size, QuantLib::ext::shared_ptr<Amount>>>();
75 }
76
77 //! \name Serialisation
78 //@{
80 void fromXML(ore::data::XMLNode* node) override;
81 //@}
82
83 const std::map<QuantLib::Size, Amounts>& delta() const { return delta_; }
84 const std::map<QuantLib::Size, Amounts>& vega() const { return vega_; }
85 const std::map<QuantLib::Size, QuantLib::ext::shared_ptr<Amount>>& historicalVolatilityRatio() const {
87 }
88
89 private:
91 // MPOR days
92 std::map<QuantLib::Size, Amounts> delta_;
93 std::map<QuantLib::Size, Amounts> vega_;
94 std::map<QuantLib::Size, QuantLib::ext::shared_ptr<Amount>> historicalVolatilityRatio_;
95 };
96 class IRRiskWeights : public RiskWeights {
97 public:
99 //! \name Serialisation
100 //@{
101 ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
102 void fromXML(ore::data::XMLNode* node) override;
103 //@}
104 virtual const std::map<CrifRecord::RiskType, std::map<QuantLib::Size, QuantLib::ext::shared_ptr<Amount>>>
105 uniqueRiskWeights() const override;
106
107 const std::map<QuantLib::Size, QuantLib::ext::shared_ptr<Amount>>& inflation() const { return inflation_; }
108 const std::map<QuantLib::Size, QuantLib::ext::shared_ptr<Amount>>& xCcyBasis() const { return xCcyBasis_; }
109 const CurrencyLists& currencyLists() const { return currencyLists_; }
110
111 private:
112 std::map<QuantLib::Size, QuantLib::ext::shared_ptr<Amount>> inflation_;
113 std::map<QuantLib::Size, QuantLib::ext::shared_ptr<Amount>> xCcyBasis_;
115 };
117 public:
119 //! \name Serialisation
120 //@{
121 ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
122 void fromXML(ore::data::XMLNode* node) override;
123 //@}
124 virtual const std::map<CrifRecord::RiskType, std::map<QuantLib::Size, QuantLib::ext::shared_ptr<Amount>>>
125 uniqueRiskWeights() const override;
126
127 private:
128 std::map<QuantLib::Size, QuantLib::ext::shared_ptr<Amount>> baseCorrelation_;
129 };
130 class FXRiskWeights : public RiskWeights {
131 public:
133 //! \name Serialisation
134 //@{
135 ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
136 void fromXML(ore::data::XMLNode* node) override;
137 //@}
138 const CurrencyLists& currencyLists() const { return currencyLists_; }
139
140 private:
142 };
143
145 public:
148 //! \name Serialisation
149 //@{
150 ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
151 void fromXML(ore::data::XMLNode* node) override;
152 //@}
155
156 private:
159 };
161 public:
163 //! \name Serialisation
164 //@{
165 ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
166 void fromXML(ore::data::XMLNode* node) override;
167 //@}
168 const QuantLib::ext::shared_ptr<Amount>& subCurves() const { return subCurves_; }
169 const QuantLib::ext::shared_ptr<Amount>& inflation() const { return inflation_; }
170 const QuantLib::ext::shared_ptr<Amount>& xCcyBasis() const { return xCcyBasis_; }
171 const QuantLib::ext::shared_ptr<Amount>& outer() const { return outer_; }
172
173 private:
174 QuantLib::ext::shared_ptr<Amount> subCurves_;
175 QuantLib::ext::shared_ptr<Amount> inflation_;
176 QuantLib::ext::shared_ptr<Amount> xCcyBasis_;
177 QuantLib::ext::shared_ptr<Amount> outer_;
178 };
180 public:
182 //! \name Serialisation
183 //@{
184 ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
185 void fromXML(ore::data::XMLNode* node) override;
186 //@}
187 const QuantLib::ext::shared_ptr<Amount>& baseCorrelation() const { return baseCorrelation_; }
188
189 private:
190 QuantLib::ext::shared_ptr<Amount> baseCorrelation_;
191 };
193 public:
195 //! \name Serialisation
196 //@{
197 ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
198 void fromXML(ore::data::XMLNode* node) override;
199 //@}
200 const QuantLib::ext::shared_ptr<Amount>& volatility() const { return volatility_; }
201
202 private:
203 QuantLib::ext::shared_ptr<Amount> volatility_;
204 };
205
207 public:
210 //! \name Serialisation
211 //@{
212 ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
213 void fromXML(ore::data::XMLNode* node) override;
214 //@}
215
216 const Amounts& delta() const { return delta_; }
217 const Amounts& vega() const { return vega_; }
218
219 private:
222 };
224 public:
227 //! \name Serialisation
228 //@{
229 ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
230 void fromXML(ore::data::XMLNode* node) override;
231 //@}
232
233 const CurrencyLists& currencyLists() const { return currencyLists_; }
234
235 private:
237 };
238
240 RiskClassData(const SimmConfiguration::RiskClass& riskClass) : riskClass_(riskClass) {}
241
242 //! \name Serialisation
243 //@{
244 ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
245 void fromXML(ore::data::XMLNode* node) override;
246 //@}
247
248 const QuantLib::ext::shared_ptr<RiskWeights>& riskWeights() const { return riskWeights_; }
249 const QuantLib::ext::shared_ptr<Correlations>& correlations() const { return correlations_; }
250 const QuantLib::ext::shared_ptr<ConcentrationThresholds>& concentrationThresholds() const {
252 }
253 const std::map<CrifRecord::RiskType, std::vector<std::string>>& buckets() const { return buckets_; }
254 const std::map<CrifRecord::RiskType, std::vector<std::string>>& labels1() const { return labels1_; }
255 const std::map<CrifRecord::RiskType, std::vector<std::string>>& labels2() const { return labels2_; }
256
257 private:
259 QuantLib::ext::shared_ptr<RiskWeights> riskWeights_;
260 QuantLib::ext::shared_ptr<Correlations> correlations_;
261 QuantLib::ext::shared_ptr<ConcentrationThresholds> concentrationThresholds_;
262 std::map<CrifRecord::RiskType, std::vector<std::string>> buckets_;
263 std::map<CrifRecord::RiskType, std::vector<std::string>> labels1_;
264 std::map<CrifRecord::RiskType, std::vector<std::string>> labels2_;
265 };
266
269
270 const std::string& version() const;
271 const std::vector<std::string>& versionNames() const { return versionNames_; }
272 const std::vector<std::pair<std::string, std::string>>& additionalFields() const { return additionalFields_; }
273
274 //! \name Serialisation
275 //@{
276 ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
277 void fromXML(ore::data::XMLNode* node) override;
278 //@}
279 const std::map<SimmConfiguration::RiskClass, QuantLib::ext::shared_ptr<RiskClassData>>& riskClassData() const {
280 return riskClassData_;
281 }
283
284 // TODO: This would be useful for ensuring that the SimmCalibration obj is compatible with the data provided.
285 void validate() const {}
286
287 const std::string& id() const { return id_; }
288
289private:
290 std::string id_;
291 std::vector<std::string> versionNames_;
292 std::vector<std::pair<std::string, std::string>> additionalFields_;
293 std::map<SimmConfiguration::RiskClass, QuantLib::ext::shared_ptr<RiskClassData>> riskClassData_;
295};
296
298public:
299 //!
301
302 //! \name Serialisation
303 //@{
304 ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
305 void fromXML(ore::data::XMLNode* node) override;
306 //@}
307
308 void add(const QuantLib::ext::shared_ptr<SimmCalibration>&);
309 bool hasId(const std::string& id) const { return data_.find(id) != data_.end(); }
310 const QuantLib::ext::shared_ptr<SimmCalibration>& getById(const std::string& id) const;
311 const QuantLib::ext::shared_ptr<SimmCalibration> getBySimmVersion(const std::string& id) const;
312
313private:
314 std::map<std::string, QuantLib::ext::shared_ptr<SimmCalibration>> data_;
315};
316
317} // namespace analytics
318} // namespace ore
void fromXML(ore::data::XMLNode *node) override
const std::string & label2() const
Amount(const std::tuple< std::string, std::string, std::string > &key, const std::string &value)
Amount(const std::string &bucket, const std::string &label1, const std::string &label2, const std::string &value)
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
const std::string & label1() const
const std::tuple< std::string, std::string, std::string > key() const
const std::string & bucket() const
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
const QuantLib::ext::shared_ptr< Amount > & baseCorrelation() const
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
virtual const std::map< CrifRecord::RiskType, std::map< QuantLib::Size, QuantLib::ext::shared_ptr< Amount > > > uniqueRiskWeights() const override
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
std::map< QuantLib::Size, QuantLib::ext::shared_ptr< Amount > > baseCorrelation_
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
const QuantLib::ext::shared_ptr< Amount > & volatility() const
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
const QuantLib::ext::shared_ptr< Amount > & inflation() const
const QuantLib::ext::shared_ptr< Amount > & subCurves() const
const QuantLib::ext::shared_ptr< Amount > & xCcyBasis() const
const QuantLib::ext::shared_ptr< Amount > & outer() const
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
virtual const std::map< CrifRecord::RiskType, std::map< QuantLib::Size, QuantLib::ext::shared_ptr< Amount > > > uniqueRiskWeights() const override
const std::map< QuantLib::Size, QuantLib::ext::shared_ptr< Amount > > & xCcyBasis() const
std::map< QuantLib::Size, QuantLib::ext::shared_ptr< Amount > > inflation_
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
const std::map< QuantLib::Size, QuantLib::ext::shared_ptr< Amount > > & inflation() const
std::map< QuantLib::Size, QuantLib::ext::shared_ptr< Amount > > xCcyBasis_
const std::map< QuantLib::Size, Amounts > & delta() const
RiskWeights(const SimmConfiguration::RiskClass &rc)
const std::map< QuantLib::Size, Amounts > & vega() const
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
const std::map< QuantLib::Size, QuantLib::ext::shared_ptr< Amount > > & historicalVolatilityRatio() const
virtual const std::map< CrifRecord::RiskType, std::map< QuantLib::Size, QuantLib::ext::shared_ptr< Amount > > > uniqueRiskWeights() const
std::map< QuantLib::Size, QuantLib::ext::shared_ptr< Amount > > historicalVolatilityRatio_
std::map< CrifRecord::RiskType, std::vector< std::string > > buckets_
const std::map< CrifRecord::RiskType, std::vector< std::string > > & labels2() const
void fromXML(ore::data::XMLNode *node) override
std::map< CrifRecord::RiskType, std::vector< std::string > > labels1_
QuantLib::ext::shared_ptr< ConcentrationThresholds > concentrationThresholds_
QuantLib::ext::shared_ptr< Correlations > correlations_
const std::map< CrifRecord::RiskType, std::vector< std::string > > & labels1() const
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
RiskClassData(const SimmConfiguration::RiskClass &riskClass)
std::map< CrifRecord::RiskType, std::vector< std::string > > labels2_
QuantLib::ext::shared_ptr< RiskWeights > riskWeights_
const QuantLib::ext::shared_ptr< ConcentrationThresholds > & concentrationThresholds() const
const std::map< CrifRecord::RiskType, std::vector< std::string > > & buckets() const
const QuantLib::ext::shared_ptr< Correlations > & correlations() const
const QuantLib::ext::shared_ptr< RiskWeights > & riskWeights() const
void fromXML(ore::data::XMLNode *node) override
std::map< std::string, QuantLib::ext::shared_ptr< SimmCalibration > > data_
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
void add(const QuantLib::ext::shared_ptr< SimmCalibration > &)
const QuantLib::ext::shared_ptr< SimmCalibration > getBySimmVersion(const std::string &id) const
const QuantLib::ext::shared_ptr< SimmCalibration > & getById(const std::string &id) const
bool hasId(const std::string &id) const
const std::string & version() const
const std::vector< std::pair< std::string, std::string > > & additionalFields() const
const std::string & id() const
const std::map< SimmConfiguration::RiskClass, QuantLib::ext::shared_ptr< RiskClassData > > & riskClassData() const
void fromXML(ore::data::XMLNode *node) override
std::map< std::tuple< std::string, std::string, std::string >, std::string > Amounts
const std::vector< std::string > & versionNames() const
std::vector< std::string > versionNames_
std::vector< std::pair< std::string, std::string > > additionalFields_
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
std::map< SimmConfiguration::RiskClass, QuantLib::ext::shared_ptr< RiskClassData > > riskClassData_
std::map< std::tuple< std::string, std::string, std::string >, std::set< std::string > > CurrencyLists
const Amounts & riskClassCorrelations() const
SimmCalibration(ore::data::XMLNode *node)
Abstract base class defining the interface for a SIMM configuration.
SIMM configuration interface.