Skip to content

Commit 6795aa9

Browse files
nathaniel.volfangojenkins
authored andcommitted
Merge remote-tracking branch 'origin/1.0.79' into 79.2_to_master
1 parent c900e98 commit 6795aa9

4 files changed

Lines changed: 51 additions & 13 deletions

File tree

OREAnalytics/orea/simm/crif.cpp

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,32 @@ void Crif::addSimmCrifRecord(const CrifRecord& record, bool aggregateDifferentAm
7676

7777
void Crif::insertCrifRecord(const CrifRecord& record, bool aggregateDifferentAmountCurrencies) {
7878

79-
auto it = records_.find(record);
80-
if (aggregateDifferentAmountCurrencies) {
81-
it = std::find_if(records_.begin(), records_.end(),
82-
[&record](const auto& x) { return CrifRecord::amountCcyEQCompare(x, record); });
83-
}
84-
if (it == records_.end()) {
85-
records_.insert(record);
79+
auto it = aggregateDifferentAmountCurrencies ? records_.end() : records_.find(record);
80+
auto itDiffAmountCcy = aggregateDifferentAmountCurrencies
81+
? diffAmountCurrenciesIndex_.find(record.getSimmAmountCcyKey())
82+
: diffAmountCurrenciesIndex_.end();
83+
84+
if (it == records_.end() && itDiffAmountCcy == diffAmountCurrenciesIndex_.end()) {
85+
auto recordIt = records_.insert(record);
86+
diffAmountCurrenciesIndex_[record.getSimmAmountCcyKey()] = &(*(recordIt.first));
8687
portfolioIds_.insert(record.portfolioId);
8788
nettingSetDetails_.insert(record.nettingSetDetails);
88-
} else {
89+
} else if (it != records_.end()) {
8990
updateAmountExistingRecord(it, record);
91+
} else {
92+
updateAmountExistingRecord(itDiffAmountCcy, record);
9093
}
9194
}
9295

9396
void Crif::addSimmParameterRecord(const CrifRecord& record) {
9497
auto it = records_.find(record);
9598
if (it == records_.end()) {
96-
records_.insert(record);
99+
CrifRecord newRecord = record;
100+
records_.insert(newRecord);
101+
diffAmountCurrenciesIndex_[record.getSimmAmountCcyKey()] = &newRecord;
97102
} else if (it->riskType == CrifRecord::RiskType::AddOnFixedAmount) {
98103
updateAmountExistingRecord(it, record);
99-
} else if (it->riskType == CrifRecord::RiskType::AddOnNotionalFactor &&
104+
} else if (it->riskType == CrifRecord::RiskType::AddOnNotionalFactor ||
100105
it->riskType == CrifRecord::RiskType::ProductClassMultiplier) {
101106
// Only log warning if the values are not the same. If they are, then there is no material discrepancy.
102107
if (record.amount != it->amount) {
@@ -127,6 +132,25 @@ void Crif::updateAmountExistingRecord(std::set<CrifRecord>::iterator& it, const
127132
DLOG("Updated net CRIF records: " << *it)
128133
}
129134

135+
void Crif::updateAmountExistingRecord(std::map<CrifRecord::SimmAmountCcyKey, const CrifRecord*>::iterator& it,
136+
const CrifRecord& record) {
137+
bool updated = false;
138+
if (record.hasAmountUsd()) {
139+
it->second->amountUsd += record.amountUsd;
140+
updated = true;
141+
}
142+
if (record.hasAmount() && record.hasAmountCcy() && it->second->amountCurrency == record.amountCurrency) {
143+
it->second->amount += record.amount;
144+
updated = true;
145+
}
146+
if (record.hasAmountResultCcy() && record.hasResultCcy() && it->second->resultCurrency == record.resultCurrency) {
147+
it->second->amountResultCcy += record.amountResultCcy;
148+
updated = true;
149+
}
150+
if (updated)
151+
DLOG("Updated net CRIF records: " << *(it->second))
152+
}
153+
130154
void Crif::addRecords(const Crif& crif, bool aggregateDifferentAmountCurrencies, bool sortFxVolQualifer) {
131155
for (const auto& r : crif.records_) {
132156
addRecord(r, aggregateDifferentAmountCurrencies, sortFxVolQualifer);

OREAnalytics/orea/simm/crif.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,12 @@ class Crif {
119119
void addSimmCrifRecord(const CrifRecord& record, bool aggregateDifferentAmountCurrencies = false, bool sortFxVolQualifer =true);
120120
void addSimmParameterRecord(const CrifRecord& record);
121121
void updateAmountExistingRecord(std::set<CrifRecord>::iterator& it, const CrifRecord& record);
122+
void updateAmountExistingRecord(std::map<CrifRecord::SimmAmountCcyKey, const CrifRecord*>::iterator& it, const CrifRecord& record);
122123

123124

124125
CrifType type_ = CrifType::Empty;
125126
std::set<CrifRecord> records_;
127+
std::map<CrifRecord::SimmAmountCcyKey, const CrifRecord*> diffAmountCurrenciesIndex_;
126128

127129
//SIMM members
128130
//! Set of portfolio IDs that have been loaded

OREAnalytics/orea/simm/crifrecord.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ struct CrifRecord {
125125
//! There are two entries for curvature risk in frtb, a up and down shift
126126
enum class CurvatureScenario { Empty, Up, Down };
127127

128+
// clang-format off
129+
// trade ID qualifier bucket label1 label2 collect regs post regs
130+
typedef std::tuple<std::string, NettingSetDetails, ProductClass, RiskType, std::string, std::string, std::string, std::string, std::string, std::string> SimmAmountCcyKey;
131+
// clang-format on
132+
128133
// required data
129134
std::string tradeId;
130135
std::string portfolioId;
@@ -286,6 +291,11 @@ struct CrifRecord {
286291
return value;
287292
}
288293

294+
const SimmAmountCcyKey getSimmAmountCcyKey() const {
295+
return std::make_tuple(tradeId, nettingSetDetails, productClass, riskType, qualifier, bucket, label1, label2,
296+
collectRegulations, postRegulations);
297+
}
298+
289299
//! Define how CRIF records are compared
290300
bool operator<(const CrifRecord& cr) const {
291301
if (type() == RecordType::FRTB || cr.type() == RecordType::FRTB) {

Tools/PythonTools/comparison_config.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@
9797
"names": [
9898
"TradeType",
9999
"NettingSet",
100+
"Asset",
101+
"MaturityDate",
102+
"Maturity",
100103
"NPV",
101-
"Notional",
102-
"RiskWeight",
103-
"SMRC"
104+
"SignedNotional",
105+
"RiskWeight"
104106
],
105107
"abs_tol": null,
106108
"rel_tol": 1e-12

0 commit comments

Comments
 (0)