@@ -63,12 +63,14 @@ typedef SimmConfiguration::SimmSide SimmSide;
6363
6464SimmCalculator::SimmCalculator (const SimmNetSensitivities& simmNetSensitivities,
6565 const boost::shared_ptr<SimmConfiguration>& simmConfiguration,
66- const string& calculationCcy, const string& resultCcy, const boost::shared_ptr<Market> market,
67- const bool determineWinningRegulations,
68- const bool enforceIMRegulations, const bool quiet)
66+ const string& calculationCcy, const string& resultCcy,
67+ const boost::shared_ptr<Market> market, const bool determineWinningRegulations,
68+ const bool enforceIMRegulations, const bool quiet,
69+ const map<SimmSide, set<NettingSetDetails>>& hasSEC,
70+ const map<SimmSide, set<NettingSetDetails>>& hasCFTC)
6971 : simmNetSensitivities_(simmNetSensitivities), simmConfiguration_(simmConfiguration),
7072 calculationCcy_ (calculationCcy), resultCcy_(resultCcy.empty() ? calculationCcy_ : resultCcy), market_(market),
71- quiet_(quiet) {
73+ quiet_(quiet), hasSEC_(hasSEC), hasCFTC_(hasCFTC) {
7274
7375 QL_REQUIRE (checkCurrency (calculationCcy_),
7476 " SIMM Calculator: The calculation currency (" << calculationCcy_ << " ) must be a valid ISO currency code" );
@@ -116,31 +118,50 @@ SimmCalculator::SimmCalculator(const SimmNetSensitivities& simmNetSensitivities,
116118
117119 // Some additional processing depending on the regulations applicable to each netting set
118120 for (auto & sv : regSensitivities_) {
121+ const SimmSide& side = sv.first ;
119122
120123 for (auto & s : sv.second ) {
124+ const NettingSetDetails& nettingDetails = s.first ;
125+
121126 // Where there is SEC and CFTC in the portfolio, we add the CFTC trades to SEC,
122127 // but still continue with CFTC calculations
123- const bool hasCFTC = s.second .find (" CFTC" ) != s.second .end ();
124- const bool hasSEC = s.second .find (" SEC" ) != s.second .end ();
125- if (hasCFTC && hasSEC) {
126- const SimmNetSensitivities& netRecordsCFTC = s.second .at (" CFTC" )->netRecords (true );
127- const SimmNetSensitivities& netRecordsSEC = s.second .at (" SEC" )->netRecords (true );
128- for (const auto & cr : netRecordsCFTC) {
129- // Only add CFTC records to SEC if the record was not already in SEC,
130- // i.e. we skip over CRIF records with regulations specified as e.g. "..., CFTC, SEC, ..."
131- if (netRecordsSEC.find (cr) == netRecordsSEC.end ()) {
132- if (!quiet_) {
133- DLOG (" SimmCalculator: Inserting CRIF record with CFTC "
134- << s.first << " regulation into SEC CRIF records: " << cr);
128+ const bool hasCFTCGlobal = hasCFTC_[side].find (nettingDetails) != hasCFTC_[side].end ();
129+ const bool hasSECGlobal = hasSEC_[side].find (nettingDetails) != hasSEC_[side].end ();
130+ const bool hasSECLocal = s.second .find (" SEC" ) != s.second .end ();
131+ const bool hasCFTCLocal = s.second .find (" CFTC" ) != s.second .end ();
132+
133+ if ((hasSECLocal && hasCFTCLocal) || (hasCFTCGlobal && hasSECGlobal)) {
134+ if (!hasSECLocal) {
135+ if (!hasCFTCLocal) {
136+ continue ;
137+ } else {
138+ s.second [" SEC" ] = boost::make_shared<CrifLoader>(simmConfiguration_,
139+ CrifRecord::additionalHeaders, true , false );
140+ }
141+ }
142+
143+ if (hasCFTCLocal) {
144+ // At this point, we expect to have both SEC and CFTC sensitivities for the netting set
145+ const SimmNetSensitivities& netRecordsCFTC = s.second .at (" CFTC" )->netRecords (true );
146+ const SimmNetSensitivities& netRecordsSEC = s.second .at (" SEC" )->netRecords (true );
147+ for (const auto & cr : netRecordsCFTC) {
148+ // Only add CFTC records to SEC if the record was not already in SEC,
149+ // i.e. we skip over CRIF records with regulations specified as e.g. "..., CFTC, SEC, ..."
150+ if (netRecordsSEC.find (cr) == netRecordsSEC.end ()) {
151+ if (!quiet_) {
152+ DLOG (" SimmCalculator: Inserting CRIF record with CFTC "
153+ << s.first << " regulation into SEC CRIF records: " << cr);
154+ }
155+ s.second .at (" SEC" )->add (cr);
135156 }
136- s.second .at (" SEC" )->add (cr);
137157 }
138158 }
159+
139160 }
140161 // The CrifLoader was set initially without aggregation, so make sure to aggregate this now
141- if (hasCFTC )
162+ if (hasCFTCLocal )
142163 s.second .at (" CFTC" )->aggregate ();
143- if (hasSEC )
164+ if (hasSECLocal )
144165 s.second .at (" SEC" )->aggregate ();
145166
146167 // If netting set has "Unspecified" plus other regulations, the "Unspecified" sensis are to be excluded.
0 commit comments