Skip to content

Commit f90bfc6

Browse files
NathanielVolfangojenkins
authored andcommitted
QPR-11462 -- Improve error message and update tests
1 parent 95f85e3 commit f90bfc6

3 files changed

Lines changed: 37 additions & 25 deletions

File tree

OREAnalytics/orea/simm/simmresults.cpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,41 @@ namespace analytics {
3535
void 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+
6573
void 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();

OREAnalytics/orea/simm/simmresults.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class SimmResults {
5656
const SimmConfiguration::MarginType& mt, const std::string& b, QuantLib::Real im,
5757
const std::string& resultCurrency, const std::string& calculationCurrency, const bool overwrite);
5858

59+
void add(const Key& key, QuantLib::Real im, const std::string& resultCurrency,
60+
const std::string& calculationCurrency, const bool overwrite);
61+
5962
//! Convert SIMM amounts to a different currency
6063
void convert(const QuantLib::ext::shared_ptr<ore::data::Market>& market, const std::string& currency);
6164
void convert(QuantLib::Real fxSpot, const std::string& currency);

Tools/PythonTools/comparison_config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,8 @@
636636
"GreenUpTo",
637637
"AmberUpTo",
638638
"Zone",
639-
"Currency",
639+
"DiscountingCurrency",
640+
"SIMMResultCurrency",
640641
"SIMMCalculationCurrency"
641642
],
642643
"abs_tol": null,

0 commit comments

Comments
 (0)