@@ -35,33 +35,41 @@ namespace analytics {
3535void SimmResults::add (const CrifRecord::ProductClass& pc, const SimmConfiguration::RiskClass& rc,
3636 const SimmConfiguration::MarginType& mt, const string& b, Real im, const string& resultCurrency,
3737 const string& calculationCurrency, const bool overwrite) {
38+ if (!(mt == SimmConfiguration::MarginType::AdditionalIM || mt == SimmConfiguration::MarginType::All))
39+ QL_REQUIRE (im >= 0.0 , " Cannot add negative IM " << im << " result to SimmResults for RiskClass=" << rc
40+ << " , MarginType=" << mt << " , and Bucket=" << b);
3841
39- // Add the value as long as the currencies are matching. If the SimmResults container does not yet have
40- // a currency, we set it to be that of the incoming value
41- if (resultCcy_.empty ())
42- resultCcy_ = resultCurrency;
43- else
44- QL_REQUIRE (resultCurrency == resultCcy_, " Cannot add value to SimmResults with a different result currency ("
45- << resultCurrency << " ). Expected " << resultCcy_ << " ." );
46-
47- if (calcCcy_.empty ())
48- calcCcy_ = calculationCurrency;
49- else
50- QL_REQUIRE (calculationCurrency == calcCcy_, " Cannot add value to SimmResults in a different calculation currency ("
51- << calculationCurrency << " ). Expected " << calcCcy_ << " ." );
52-
53- if (!(mt == SimmConfiguration::MarginType::AdditionalIM || mt == SimmConfiguration::MarginType::All))
54- QL_REQUIRE (im >= 0.0 , " Cannot add negative IM " << im << " result to SimmResults for RiskClass=" << rc
55- << " , MarginType=" << mt << " , and Bucket=" << b);
56-
57- const auto key = make_tuple (pc, rc, mt, b);
58- const bool hasResults = data_.find (key) != data_.end ();
59- if (hasResults && !overwrite)
60- data_[key] += im;
61- else
62- data_[key] = im;
42+ const auto key = make_tuple (pc, rc, mt, b);
43+ add (key, im, resultCurrency, calculationCurrency, overwrite);
6344}
6445
46+
47+ void SimmResults::add (const SimmResults::Key& key, QuantLib::Real im, const std::string& resultCurrency,
48+ const std::string& calculationCurrency, const bool overwrite) {
49+ // Add the value as long as the currencies are matching. If the SimmResults container does not yet have
50+ // a currency, we set it to be that of the incoming value
51+ if (resultCcy_.empty ())
52+ resultCcy_ = resultCurrency;
53+ else
54+ QL_REQUIRE (resultCurrency == resultCcy_,
55+ " Cannot add value to SimmResults with a different result currency ("
56+ << resultCurrency << " ). Expected " << resultCcy_ << " ." );
57+
58+ if (calcCcy_.empty ())
59+ calcCcy_ = calculationCurrency;
60+ else
61+ QL_REQUIRE (calculationCurrency == calcCcy_,
62+ " Cannot add value to SimmResults in a different calculation currency ("
63+ << calculationCurrency << " ). Expected " << calcCcy_ << " ." );
64+
65+ const bool hasResults = data_.find (key) != data_.end ();
66+ if (hasResults && !overwrite)
67+ data_[key] += im;
68+ else
69+ data_[key] = im;
70+ }
71+
72+
6573void SimmResults::convert (const QuantLib::ext::shared_ptr<ore::data::Market>& market, const string& currency) {
6674 // Get corresponding FX spot rate
6775 Real fxSpot = market->fxRate (resultCcy_ + currency)->value ();
0 commit comments