Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
crif.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2023 AcadiaSoft Inc.
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/crif.hpp
20 \brief Struct for holding CRIF records
21*/
22
23#pragma once
27
28namespace ore {
29namespace analytics {
30
32 bool operator()(const CrifRecord& x) { return x.isSimmParameter(); }
33};
34
35class Crif {
36public:
37 enum class CrifType { Empty, Frtb, Simm };
38 Crif() = default;
39
40 CrifType type() const { return type_; }
41
42 void addRecord(const CrifRecord& record, bool aggregateDifferentAmountCurrencies = false, bool sortFxVolQualifer = true);
43 void addRecords(const Crif& crif, bool aggregateDifferentAmountCurrencies = false, bool sortFxVolQualfier = true);
44
45 void clear() { records_.clear(); }
46
47 std::set<CrifRecord>::const_iterator begin() const { return records_.cbegin(); }
48 std::set<CrifRecord>::const_iterator end() const { return records_.cend(); }
49 std::set<CrifRecord>::const_iterator find(const CrifRecord& r) const { return records_.find(r); }
50
51 //! Find first element
52 std::set<CrifRecord>::const_iterator findBy(const NettingSetDetails nsd, CrifRecord::ProductClass pc,
53 const CrifRecord::RiskType rt, const std::string& qualifier) const;
54
55 bool empty() const { return records_.empty(); }
56
57 size_t size() const { return records_.size(); }
58
59 //! check if there are crif records beside simmParameters
60 const bool hasCrifRecords() const;
61
62 //! Simm methods
63 //! Give back the set of portfolio IDs that have been loaded
64 const std::set<std::string>& portfolioIds() const;
65 const std::set<ore::data::NettingSetDetails>& nettingSetDetails() const;
66
67 //! check if the Crif contains simmParameters
68 const bool hasSimmParameters() const;
69
70 //! returns a crif without zero amount records, FXRisk entries in currency *alwaysIncludeFxRiskCcy* are always included
71 Crif filterNonZeroAmount(double threshold = 0.0, std::string alwaysIncludeFxRiskCcy = "") const;
72
73 //! returns a Crif containing only simmParameter entries
74 Crif simmParameters() const;
75
76 //! deletes all existing simmParameter and replaces them with the new one
77 void setSimmParameters(const Crif& crif);
78
79 //! deletes all existing simmParameter and replaces them with the new one
80 void setCrifRecords(const Crif& crif);
81
82 //! For each CRIF record checks if amountCurrency and amount are
83 //! defined and uses these to populate the record's amountUsd
84 void fillAmountUsd(const QuantLib::ext::shared_ptr<ore::data::Market> market);
85
86 //! Check if netting set details are used anywhere, instead of just the netting set ID
87 bool hasNettingSetDetails() const;
88
89 //! Aggregate all existing records
90 Crif aggregate() const;
91
93 const std::string& qualifier) const;
94
95 std::set<CrifRecord::ProductClass> ProductClassesByNettingSetDetails(const NettingSetDetails nsd) const;
96
97 std::set<std::string> qualifiersBy(const NettingSetDetails nsd, CrifRecord::ProductClass pc,
98 const CrifRecord::RiskType rt) const;
99
100 std::vector<CrifRecord> filterByQualifierAndBucket(const NettingSetDetails& nsd, const CrifRecord::ProductClass pc,
101 const CrifRecord::RiskType rt, const std::string& qualifier,
102 const std::string& bucket) const;
103
104 std::vector<CrifRecord> filterByQualifier(const NettingSetDetails& nsd, const CrifRecord::ProductClass pc,
105 const CrifRecord::RiskType rt, const std::string& qualifier) const;
106
107 std::vector<CrifRecord> filterByBucket(const NettingSetDetails& nsd, const CrifRecord::ProductClass pc,
108 const CrifRecord::RiskType rt, const std::string& bucket) const;
109
110 std::vector<CrifRecord> filterBy(const NettingSetDetails& nsd, const CrifRecord::ProductClass pc,
111 const CrifRecord::RiskType rt) const;
112 std::vector<CrifRecord> filterBy(const CrifRecord::RiskType rt) const;
113 std::vector<CrifRecord> filterByTradeId(const std::string& id) const;
114 std::set<std::string> tradeIds() const;
115
116private:
117 void insertCrifRecord(const CrifRecord& record, bool aggregateDifferentAmountCurrencies = false);
118 void addFrtbCrifRecord(const CrifRecord& record, bool aggregateDifferentAmountCurrencies = false, bool sortFxVolQualifer =true);
119 void addSimmCrifRecord(const CrifRecord& record, bool aggregateDifferentAmountCurrencies = false, bool sortFxVolQualifer =true);
120 void addSimmParameterRecord(const CrifRecord& record);
121 void updateAmountExistingRecord(std::set<CrifRecord>::iterator& it, const CrifRecord& record);
122 void updateAmountExistingRecord(std::map<CrifRecord::SimmAmountCcyKey, const CrifRecord*>::iterator& it, const CrifRecord& record);
123
124
126 std::set<CrifRecord> records_;
127 std::map<CrifRecord::SimmAmountCcyKey, const CrifRecord*> diffAmountCurrenciesIndex_;
128
129 //SIMM members
130 //! Set of portfolio IDs that have been loaded
131 std::set<std::string> portfolioIds_;
132 std::set<ore::data::NettingSetDetails> nettingSetDetails_;
133
134};
135
136
137} // namespace analytics
138} // namespace ore
Crif aggregate() const
Aggregate all existing records.
Definition: crif.cpp:160
void setCrifRecords(const Crif &crif)
deletes all existing simmParameter and replaces them with the new one
Definition: crif.cpp:305
void updateAmountExistingRecord(std::set< CrifRecord >::iterator &it, const CrifRecord &record)
Definition: crif.cpp:117
std::set< std::string > qualifiersBy(const NettingSetDetails nsd, CrifRecord::ProductClass pc, const CrifRecord::RiskType rt) const
Definition: crif.cpp:227
std::set< ore::data::NettingSetDetails > nettingSetDetails_
Definition: crif.hpp:132
size_t size() const
Definition: crif.hpp:57
std::vector< CrifRecord > filterByQualifier(const NettingSetDetails &nsd, const CrifRecord::ProductClass pc, const CrifRecord::RiskType rt, const std::string &qualifier) const
Definition: crif.cpp:247
std::set< std::string > tradeIds() const
Definition: crif.cpp:284
const std::set< ore::data::NettingSetDetails > & nettingSetDetails() const
Definition: crif.cpp:322
Crif filterNonZeroAmount(double threshold=0.0, std::string alwaysIncludeFxRiskCcy="") const
returns a crif without zero amount records, FXRisk entries in currency alwaysIncludeFxRiskCcy are alw...
Definition: crif.cpp:204
void addFrtbCrifRecord(const CrifRecord &record, bool aggregateDifferentAmountCurrencies=false, bool sortFxVolQualifer=true)
Definition: crif.cpp:51
std::vector< CrifRecord > filterByBucket(const NettingSetDetails &nsd, const CrifRecord::ProductClass pc, const CrifRecord::RiskType rt, const std::string &bucket) const
Definition: crif.cpp:257
std::vector< CrifRecord > filterByQualifierAndBucket(const NettingSetDetails &nsd, const CrifRecord::ProductClass pc, const CrifRecord::RiskType rt, const std::string &qualifier, const std::string &bucket) const
Definition: crif.cpp:236
std::set< CrifRecord >::const_iterator begin() const
Definition: crif.hpp:47
std::set< CrifRecord::ProductClass > ProductClassesByNettingSetDetails(const NettingSetDetails nsd) const
Definition: crif.cpp:324
std::vector< CrifRecord > filterByTradeId(const std::string &id) const
Definition: crif.cpp:279
void addRecords(const Crif &crif, bool aggregateDifferentAmountCurrencies=false, bool sortFxVolQualfier=true)
Definition: crif.cpp:154
bool empty() const
Definition: crif.hpp:55
Crif simmParameters() const
returns a Crif containing only simmParameter entries
Definition: crif.cpp:186
const std::set< std::string > & portfolioIds() const
Give back the set of portfolio IDs that have been loaded.
Definition: crif.cpp:321
std::set< CrifRecord >::const_iterator end() const
Definition: crif.hpp:48
void addRecord(const CrifRecord &record, bool aggregateDifferentAmountCurrencies=false, bool sortFxVolQualifer=true)
Definition: crif.cpp:41
size_t countMatching(const NettingSetDetails &nsd, const CrifRecord::ProductClass pc, const CrifRecord::RiskType rt, const std::string &qualifier) const
Definition: crif.cpp:334
bool hasNettingSetDetails() const
Check if netting set details are used anywhere, instead of just the netting set ID.
Definition: crif.cpp:342
const bool hasCrifRecords() const
check if there are crif records beside simmParameters
Definition: crif.cpp:174
std::set< std::string > portfolioIds_
Set of portfolio IDs that have been loaded.
Definition: crif.hpp:131
std::set< CrifRecord > records_
Definition: crif.hpp:126
CrifType type() const
Definition: crif.hpp:40
void insertCrifRecord(const CrifRecord &record, bool aggregateDifferentAmountCurrencies=false)
Definition: crif.cpp:77
void fillAmountUsd(const QuantLib::ext::shared_ptr< ore::data::Market > market)
Definition: crif.cpp:351
const bool hasSimmParameters() const
check if the Crif contains simmParameters
Definition: crif.cpp:180
std::set< CrifRecord >::const_iterator findBy(const NettingSetDetails nsd, CrifRecord::ProductClass pc, const CrifRecord::RiskType rt, const std::string &qualifier) const
Find first element.
Definition: crif.cpp:196
CrifType type_
Definition: crif.hpp:125
std::map< CrifRecord::SimmAmountCcyKey, const CrifRecord * > diffAmountCurrenciesIndex_
Definition: crif.hpp:127
std::set< CrifRecord >::const_iterator find(const CrifRecord &r) const
Definition: crif.hpp:49
std::vector< CrifRecord > filterBy(const NettingSetDetails &nsd, const CrifRecord::ProductClass pc, const CrifRecord::RiskType rt) const
Definition: crif.cpp:266
void addSimmParameterRecord(const CrifRecord &record)
Definition: crif.cpp:96
void setSimmParameters(const Crif &crif)
deletes all existing simmParameter and replaces them with the new one
Definition: crif.cpp:290
void addSimmCrifRecord(const CrifRecord &record, bool aggregateDifferentAmountCurrencies=false, bool sortFxVolQualifer=true)
Definition: crif.cpp:60
Struct for holding a CRIF record.
bool operator()(const CrifRecord &x)
Definition: crif.hpp:32