Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
simmconcentrationcalibration.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2023 Quaternion Risk Management Ltd
3 All rights reserved.
4*/
9#include <ql/errors.hpp>
10
11using namespace QuantLib;
12
13using std::map;
14using std::set;
15using std::string;
16
17namespace ore {
18namespace analytics {
19
20// Ease syntax
23using IRFXConcentrationThresholds = SimmCalibration::RiskClassData::IRFXConcentrationThresholds;
24
25SimmConcentrationCalibration::SimmConcentrationCalibration(const QuantLib::ext::shared_ptr<SimmCalibration>& simmCalibration,
26 const QuantLib::ext::shared_ptr<SimmBucketMapper>& simmBucketMapper)
27 : simmBucketMapper_(simmBucketMapper) {
28
29 for (const auto& [riskClass, rcData] : simmCalibration->riskClassData()) {
30
31 const auto& concThresholds = rcData->concentrationThresholds();
32
33 // IR and FX currency lists
34 if (riskClass == RiskClass::InterestRate || riskClass == RiskClass::FX) {
35 const auto& irFxThresholds = QuantLib::ext::dynamic_pointer_cast<IRFXConcentrationThresholds>(concThresholds);
36 QL_REQUIRE(irFxThresholds, "Cannot cast ConcentrationThresholds to IRFXConcentrationThresholds");
37 const auto& ccyLists = irFxThresholds->currencyLists();
38
39 auto& categories = riskClass == RiskClass::InterestRate ? irCategories_ : fxCategories_;
40 for (const auto& [ccyKey, ccyList] : ccyLists) {
41 const string& bucket = std::get<0>(ccyKey);
42 for (const string& ccy : ccyList) {
43 if (ccy == "Other") {
44 categories[bucket].clear();
45 } else {
46 categories[bucket].insert(ccy);
47 }
48 }
49 }
50 }
51
52 const auto& delta = concThresholds->delta();
53 const auto& vega = concThresholds->vega();
54
55 const auto& [deltaRiskType, vegaRiskType] = SimmConfiguration::riskClassToRiskType(riskClass);
56
57 // Delta concentration thresholds
58 if (delta.size() == 1) {
59 flatThresholds_[deltaRiskType] = ore::data::parseReal(delta.begin()->second);
60 } else if (delta.size() > 1) {
61 for (const auto& [key, dTh] : delta) {
62 const string& bucket = std::get<0>(key);
63 bucketedThresholds_[deltaRiskType][bucket] = ore::data::parseReal(dTh);
64 }
65 }
66
67 // Vega concentration thresholds
68 if (vega.size() == 1) {
69 flatThresholds_[vegaRiskType] = ore::data::parseReal(vega.begin()->second);
70 } else if (vega.size() > 1) {
71 for (const auto& [key, vTh] : vega) {
72 const string& bucket = std::get<0>(key);
73 bucketedThresholds_[vegaRiskType][bucket] = ore::data::parseReal(vTh);
74 }
75 }
76 }
77}
78
79Real SimmConcentrationCalibration::threshold(const RiskType& riskType, const string& qualifier) const {
80 return thresholdImpl(simmBucketMapper_, riskType, qualifier);
81}
82
83} // namespace analytics
84} // namespace ore
std::map< std::string, std::set< std::string > > fxCategories_
std::map< std::string, std::set< std::string > > irCategories_
std::map< CrifRecord::RiskType, std::map< std::string, QuantLib::Real > > bucketedThresholds_
QuantLib::Real thresholdImpl(const QuantLib::ext::shared_ptr< SimmBucketMapper > &simmBucketMapper, const CrifRecord::RiskType &riskType, const std::string &qualifier) const
std::map< CrifRecord::RiskType, QuantLib::Real > flatThresholds_
SimmConcentrationCalibration(const QuantLib::ext::shared_ptr< SimmCalibration > &simmCalibration, const QuantLib::ext::shared_ptr< SimmBucketMapper > &simmBucketMapper)
Default constructor that adds fixed known mappings.
QuantLib::Real threshold(const CrifRecord::RiskType &riskType, const std::string &qualifier) const override
QuantLib::ext::shared_ptr< SimmBucketMapper > simmBucketMapper_
Help getting SIMM buckets from SIMM qualifiers.
static std::pair< CrifRecord::RiskType, CrifRecord::RiskType > riskClassToRiskType(const RiskClass &rc)
For a given risk class, return the corresponding risk types.
Real parseReal(const string &s)
SimmCalibration::RiskClassData::IRFXConcentrationThresholds IRFXConcentrationThresholds
SimmConfiguration::RiskClass RiskClass
CrifRecord::RiskType RiskType
Definition: crifloader.cpp:92
SIMM concentration thresholds built from SIMM calibration.
SIMM configuration interface.