Skip to content

Commit e7f5ba8

Browse files
pcaspersjenkins
authored andcommitted
QPR-11641 cleanup
1 parent 656f4c1 commit e7f5ba8

3 files changed

Lines changed: 13 additions & 29 deletions

File tree

OREAnalytics/orea/cube/sensitivitycube.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,13 @@ void SensitivityCube::initialise() {
105105
factors_.insert(des.key1());
106106
upFactors_[des.key1()] = fd;
107107
upIndexToKey_[fd.index] = des.key1();
108-
upDownIndexToKey_[fd.index] = des.key1();
109108
break;
110109
case ShiftScenarioDescription::Type::Down:
111110
QL_REQUIRE(downFactors_.count(des.key1()) == 0, "Cannot have multiple down factors with "
112111
"the same risk factor key ["
113112
<< des.key1() << "]");
114113
downFactors_[des.key1()] = fd;
115114
downIndexToKey_[fd.index] = des.key1();
116-
upDownIndexToKey_[fd.index] = des.key1();
117115
break;
118116
case ShiftScenarioDescription::Type::Cross:
119117
factorPair = make_pair(des.key1(), des.key2());
@@ -155,24 +153,16 @@ void SensitivityCube::initialise() {
155153

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

158-
RiskFactorKey SensitivityCube::upFactor(const Size upDownIndex) const {
159-
if (auto k = upIndexToKey_.find(upDownIndex); k != upIndexToKey_.end()) {
156+
RiskFactorKey SensitivityCube::upFactor(const Size upIndex) const {
157+
if (auto k = upIndexToKey_.find(upIndex); k != upIndexToKey_.end()) {
160158
return k->second;
161159
} else {
162160
return RiskFactorKey();
163161
}
164162
}
165163

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-
174-
RiskFactorKey SensitivityCube::upDownFactor(const Size upDownIndex) const {
175-
if (auto k = upDownIndexToKey_.find(upDownIndex); k != upDownIndexToKey_.end()) {
164+
RiskFactorKey SensitivityCube::downFactor(const Size downIndex) const {
165+
if (auto k = downIndexToKey_.find(downIndex); k != downIndexToKey_.end()) {
176166
return k->second;
177167
} else {
178168
return RiskFactorKey();

OREAnalytics/orea/cube/sensitivitycube.hpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,13 @@ 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;
79+
/*! Return factor for given up scenario index or None if given index is not an up scenario (to be reviewed) */
80+
RiskFactorKey upFactor(const Size upIndex) const;
8281

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;
82+
/*! Return factor for given down scenario index or None if given index is not an down scenario (to be reviewed) */
83+
RiskFactorKey downFactor(const Size downIndex) const;
8684

87-
/*! Return factor for given up/down scenario index or None if given index
88-
is not an up/down scenario (to be reviewed) */
89-
RiskFactorKey upDownFactor(const Size upDownIndex) const;
90-
91-
/*! Return factor for given cross scenario index or None if given index
92-
is not a cross scenario (to be reviewed) */
85+
/*! Return factor for given cross scenario index or None if given index is not a cross scenario (to be reviewed) */
9386
crossPair crossFactor(const Size crossIndex) const;
9487

9588
//! Check if the cube has scenario NPVs for scenario with description \p scenarioDescription
@@ -181,10 +174,9 @@ class SensitivityCube {
181174
// Set of risk factor key types where we want a two-sided delta calculation.
182175
std::set<RiskFactorKey::KeyType> twoSidedDeltas_;
183176

184-
// map of up / down / up-or-down / cross factor index to risk factor key
177+
// map of up / down / cross factor index to risk factor key
185178
std::map<QuantLib::Size, RiskFactorKey> upIndexToKey_;
186179
std::map<QuantLib::Size, RiskFactorKey> downIndexToKey_;
187-
std::map<QuantLib::Size, RiskFactorKey> upDownIndexToKey_;
188180
std::map<QuantLib::Size, crossPair> crossIndexToKey_;
189181

190182
};

OREAnalytics/orea/engine/sensitivitycubestream.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ void SensitivityCubeStream::updateForNewTrade() {
9898
// add delta keys
9999

100100
for (auto const& [idx, _] : cube_->npvCube()->getTradeNPVs(tradeIdx_->second)) {
101-
if (auto k = cube_->upDownFactor(idx); k.keytype != RiskFactorKey::KeyType::None)
101+
if (auto k = cube_->upFactor(idx); k.keytype != RiskFactorKey::KeyType::None)
102+
currentDeltaKeys_.insert(k);
103+
else if (auto k = cube_->downFactor(idx); k.keytype != RiskFactorKey::KeyType::None)
102104
currentDeltaKeys_.insert(k);
103105
}
104106

0 commit comments

Comments
 (0)