Skip to content

Commit 7ac6545

Browse files
mgronckijenkins
authored andcommitted
bugfix
1 parent 34b57a4 commit 7ac6545

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

OREAnalytics/orea/simm/crif.hpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,20 @@ class Crif {
7575
//! check if the Crif contains simmParameters
7676
const bool hasSimmParameters() const;
7777

78-
Crif filterNonZeroAmountUsd(double threshold = 0.0, std::string alwaysIncludeFxRiskCcy = "") const {
78+
Crif filterNonZeroAmount(double threshold = 0.0, std::string alwaysIncludeFxRiskCcy = "") const {
7979
Crif results;
8080
for (auto record : records_) {
81-
QL_REQUIRE(record.amountUsd != QuantLib::Null<QuantLib::Real>(),
82-
"Internal Error, don't apply filter before calling fillAmountUsd");
83-
auto absAmountUsd = std::fabs(record.amountUsd);
84-
bool add = (absAmountUsd > threshold && !QuantLib::close_enough(absAmountUsd, threshold));
81+
QL_REQUIRE(record.amount != QuantLib::Null<QuantLib::Real>() || record.amountUsd != QuantLib::Null<double>(),
82+
"Internal Error, amount and amountUsd are empty");
83+
double absAmount = 0.0;
84+
if ((record.amount != QuantLib::Null<double>()) && (record.amountUsd != QuantLib::Null<double>())) {
85+
absAmount = std::max(std::fabs(record.amount), std::fabs(record.amountUsd));
86+
} else if (record.amount != QuantLib::Null<double>()) {
87+
absAmount = std::fabs(record.amount);
88+
} else if (record.amountUsd != QuantLib::Null<double>()) {
89+
absAmount = std::fabs(record.amountUsd);
90+
}
91+
bool add = (absAmount > threshold && !QuantLib::close_enough(absAmount, threshold));
8592
if (!alwaysIncludeFxRiskCcy.empty())
8693
add =
8794
add || (record.riskType == CrifRecord::RiskType::FX && record.qualifier == alwaysIncludeFxRiskCcy);

0 commit comments

Comments
 (0)