@@ -76,27 +76,32 @@ void Crif::addSimmCrifRecord(const CrifRecord& record, bool aggregateDifferentAm
7676
7777void 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
9396void 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+
130154void Crif::addRecords (const Crif& crif, bool aggregateDifferentAmountCurrencies, bool sortFxVolQualifer) {
131155 for (const auto & r : crif.records_ ) {
132156 addRecord (r, aggregateDifferentAmountCurrencies, sortFxVolQualifer);
0 commit comments