Skip to content

Commit 1cfd62d

Browse files
pcaspersjenkins
authored andcommitted
QPR-12575 fix map::at error if only up (or down) factors are set
1 parent a21ba56 commit 1cfd62d

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

OREAnalytics/orea/cube/sensitivitycube.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ RiskFactorKey SensitivityCube::upDownFactor(const Size index) const {
156156
}
157157
}
158158

159+
SensitivityCube::FactorData SensitivityCube::upThenDownFactorData(const RiskFactorKey& rfkey) {
160+
if (auto f = upFactors_.find(rfkey); f != upFactors_.end())
161+
return f->second;
162+
else if (auto f = downFactors_.find(rfkey); f != downFactors_.end())
163+
return f->second;
164+
else {
165+
QL_FAIL("SensitivityCube::upThenDownFactorData(): no up or down factor data found for " << rfkey);
166+
}
167+
}
168+
159169
SensitivityCube::crossPair SensitivityCube::crossFactor(const Size crossIndex) const {
160170
if (auto k = crossIndexToKey_.find(crossIndex); k != crossIndexToKey_.end()) {
161171
return k->second;

OREAnalytics/orea/cube/sensitivitycube.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class SensitivityCube {
101101
//! Return the map of down risk factors to its factor data
102102
const std::map<RiskFactorKey, SensitivityCube::FactorData>& downFactors() const { return downFactors_; };
103103

104+
//! Return the factor data for an up shift of a rf key, if that does not exist for a down shift of the same rf key
105+
SensitivityCube::FactorData upThenDownFactorData(const RiskFactorKey& rfkey);
106+
104107
//! Returns the set of pairs of risk factor keys for which a cross gamma is available
105108
const std::map<crossPair, std::tuple<SensitivityCube::FactorData, SensitivityCube::FactorData, QuantLib::Size>>&
106109
crossFactors() const;

OREAnalytics/orea/engine/sensitivitycubestream.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ SensitivityRecord SensitivityCubeStream::next() {
8484
sr.baseNpv = cubes_[currentCubeIdx_]->npv(tradeIdx);
8585

8686
if (currentDeltaKey_ != currentDeltaKeys_.end()) {
87-
auto fd = cubes_[currentCubeIdx_]->upFactors().at(*currentDeltaKey_);
87+
auto const& fd = cubes_[currentCubeIdx_]->upThenDownFactorData(*currentDeltaKey_);
8888
sr.key_1 = *currentDeltaKey_;
8989
sr.desc_1 = fd.factorDesc;
9090
sr.shift_1 = fd.targetShiftSize;
@@ -95,7 +95,7 @@ SensitivityRecord SensitivityCubeStream::next() {
9595
sr.gamma = Null<Real>();
9696
++currentDeltaKey_;
9797
} else if (currentCrossGammaKey_ != currentCrossGammaKeys_.end()) {
98-
auto fd = cubes_[currentCubeIdx_]->crossFactors().at(*currentCrossGammaKey_);
98+
auto const& fd = cubes_[currentCubeIdx_]->crossFactors().at(*currentCrossGammaKey_);
9999
sr.key_1 = currentCrossGammaKey_->first;
100100
sr.desc_1 = std::get<0>(fd).factorDesc;
101101
sr.shift_1 = std::get<0>(fd).targetShiftSize;

0 commit comments

Comments
 (0)