Skip to content

Commit 656f4c1

Browse files
pcaspersjenkins
authored andcommitted
QPR-11641 fix
1 parent 15c42ed commit 656f4c1

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

OREAnalytics/orea/cube/sensitivitycube.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ void SensitivityCube::initialise() {
104104
<< des.key1() << "]");
105105
factors_.insert(des.key1());
106106
upFactors_[des.key1()] = fd;
107+
upIndexToKey_[fd.index] = des.key1();
107108
upDownIndexToKey_[fd.index] = des.key1();
108109
break;
109110
case ShiftScenarioDescription::Type::Down:
110111
QL_REQUIRE(downFactors_.count(des.key1()) == 0, "Cannot have multiple down factors with "
111112
"the same risk factor key ["
112113
<< des.key1() << "]");
113114
downFactors_[des.key1()] = fd;
115+
downIndexToKey_[fd.index] = des.key1();
114116
upDownIndexToKey_[fd.index] = des.key1();
115117
break;
116118
case ShiftScenarioDescription::Type::Cross:
@@ -153,6 +155,22 @@ void SensitivityCube::initialise() {
153155

154156
bool SensitivityCube::hasTrade(const string& tradeId) const { return tradeIdx_.count(tradeId) > 0; }
155157

158+
RiskFactorKey SensitivityCube::upFactor(const Size upDownIndex) const {
159+
if (auto k = upIndexToKey_.find(upDownIndex); k != upIndexToKey_.end()) {
160+
return k->second;
161+
} else {
162+
return RiskFactorKey();
163+
}
164+
}
165+
166+
RiskFactorKey SensitivityCube::downFactor(const Size upDownIndex) const {
167+
if (auto k = downIndexToKey_.find(upDownIndex); k != downIndexToKey_.end()) {
168+
return k->second;
169+
} else {
170+
return RiskFactorKey();
171+
}
172+
}
173+
156174
RiskFactorKey SensitivityCube::upDownFactor(const Size upDownIndex) const {
157175
if (auto k = upDownIndexToKey_.find(upDownIndex); k != upDownIndexToKey_.end()) {
158176
return k->second;

OREAnalytics/orea/cube/sensitivitycube.hpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ class SensitivityCube {
7676
//! Return the map of up trade id's to index in cube
7777
const std::map<std::string, QuantLib::Size>& tradeIdx() const { return cube_->idsAndIndexes(); };
7878

79+
/*! Return factor for given up/down scenario index or None if given index
80+
is not an up/down scenario (to be reviewed) */
81+
RiskFactorKey upFactor(const Size upDownIndex) const;
82+
83+
/*! Return factor for given up/down scenario index or None if given index
84+
is not an up/down scenario (to be reviewed) */
85+
RiskFactorKey downFactor(const Size upDownIndex) const;
86+
7987
/*! Return factor for given up/down scenario index or None if given index
8088
is not an up/down scenario (to be reviewed) */
8189
RiskFactorKey upDownFactor(const Size upDownIndex) const;
@@ -173,10 +181,10 @@ class SensitivityCube {
173181
// Set of risk factor key types where we want a two-sided delta calculation.
174182
std::set<RiskFactorKey::KeyType> twoSidedDeltas_;
175183

176-
// map of up / down factor index to risk factor key
184+
// map of up / down / up-or-down / cross factor index to risk factor key
185+
std::map<QuantLib::Size, RiskFactorKey> upIndexToKey_;
186+
std::map<QuantLib::Size, RiskFactorKey> downIndexToKey_;
177187
std::map<QuantLib::Size, RiskFactorKey> upDownIndexToKey_;
178-
179-
// map of cross factor index to risk factor pair
180188
std::map<QuantLib::Size, crossPair> crossIndexToKey_;
181189

182190
};

OREAnalytics/orea/engine/zerotoparcube.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ map<RiskFactorKey, Real> ZeroToParCube::parDeltas(QuantLib::Size tradeIdx) const
5858
const boost::shared_ptr<NPVSensiCube>& sensiCube = zeroCube_->npvCube();
5959

6060
for (auto const& kv : sensiCube->getTradeNPVs(tradeIdx)) {
61-
auto factor = zeroCube_->upDownFactor(kv.first);
61+
auto factor = zeroCube_->upFactor(kv.first);
6262
// index might not belong to an up/down scenario
6363
if (factor.keytype != RiskFactorKey::KeyType::None) {
6464
auto it = factorToIndex_.find(factor);

0 commit comments

Comments
 (0)