Skip to content

Commit 775d177

Browse files
committed
QPR-13719 add overlay npv cube
1 parent 9b5aa2d commit 775d177

3 files changed

Lines changed: 135 additions & 0 deletions

File tree

OREAnalytics/orea/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ cube/inmemorycubeopt.cpp
7171
cube/jaggedcube.cpp
7272
cube/jointnpvcube.cpp
7373
cube/jointnpvsensicube.cpp
74+
cube/overlaynpvcube.cpp
7475
cube/sensicube.cpp
7576
cube/sensitivitycube.cpp
7677
cube/sparsenpvcube.cpp
@@ -292,6 +293,7 @@ cube/jointnpvcube.hpp
292293
cube/jointnpvsensicube.hpp
293294
cube/npvcube.hpp
294295
cube/npvsensicube.hpp
296+
cube/overlaynpvcube.hpp
295297
cube/sensicube.hpp
296298
cube/sensitivitycube.hpp
297299
cube/sparsenpvcube.hpp
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
Copyright (C) 2026 Quaternion Risk Management Ltd
3+
All rights reserved.
4+
5+
This file is part of ORE, a free-software/open-source library
6+
for transparent pricing and risk analysis - http://opensourcerisk.org
7+
8+
ORE is free software: you can redistribute it and/or modify it
9+
under the terms of the Modified BSD License. You should have received a
10+
copy of the license along with this program.
11+
The license is also available online at <http://opensourcerisk.org>
12+
13+
This program is distributed on the basis that it will form a useful
14+
contribution to risk analytics and model standardisation, but WITHOUT
15+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16+
FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17+
*/
18+
19+
/*! \file orea/cube/overlaynpvcube.hpp
20+
\brief npv cube corrected by difference pricing t0 npv and sim t0 npv
21+
\ingroup cube
22+
*/
23+
24+
#include <orea/cube/overlaynpvcube.hpp>
25+
26+
namespace ore {
27+
namespace analytics {
28+
29+
OverlayNPVCube::OverlayNPVCube(const QuantLib::ext::shared_ptr<NPVCube>& cube,
30+
const std::map<std::string, double>& pricingNpvs)
31+
: cube_(cube) {
32+
pricingNpvs_.resize(cube_->numIds());
33+
for (auto const& [id, index] : cube_->idsAndIndexes()) {
34+
QL_REQUIRE(index < pricingNpvs_.size(), "OverlayNPVCube(): numIds (" << cube_->numIds()
35+
<< ") does not cover index (" << index
36+
<< ") for id " << id);
37+
if (auto p = pricingNpvs.find(id); p != pricingNpvs.end())
38+
pricingNpvs_[index] = p->second;
39+
else {
40+
QL_FAIL("OverlayNPVCube(): no pricingNpv given for id " << id);
41+
}
42+
}
43+
}
44+
45+
Size OverlayNPVCube::numIds() const { return cube_->numIds(); }
46+
47+
Size OverlayNPVCube::numDates() const { return cube_->numDates(); }
48+
49+
Size OverlayNPVCube::samples() const { return cube_->samples(); }
50+
51+
Size OverlayNPVCube::depth() const { return cube_->depth(); }
52+
53+
const std::map<std::string, Size>& OverlayNPVCube::idsAndIndexes() const { return cube_->idsAndIndexes(); }
54+
55+
const std::vector<QuantLib::Date>& OverlayNPVCube::dates() const { return cube_->dates(); }
56+
57+
QuantLib::Date OverlayNPVCube::asof() const { return cube_->asof(); }
58+
59+
Real OverlayNPVCube::getT0(Size id, Size depth) const { return cube_->getT0(id, depth) + correction(id, depth); }
60+
61+
void OverlayNPVCube::setT0(Real value, Size id, Size depth) { cube_->setT0(value - correction(id, depth), id, depth); }
62+
63+
Real OverlayNPVCube::get(Size id, Size date, Size sample, Size depth) const {
64+
return cube_->get(id, date, sample, depth) + correction(id, depth);
65+
}
66+
67+
void OverlayNPVCube::set(Real value, Size id, Size date, Size sample, Size depth) {
68+
cube_->set(value - correction(id, depth), id, date, sample, depth);
69+
}
70+
71+
bool OverlayNPVCube::usesDoublePrecision() const { return cube_->usesDoublePrecision(); }
72+
73+
double OverlayNPVCube::correction(Size id, Size depth) const {
74+
return depth == 0 ? pricingNpvs_[id] - cube_->getT0(id, depth) : 0.0;
75+
}
76+
77+
} // namespace analytics
78+
} // namespace ore
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright (C) 2026 Quaternion Risk Management Ltd
3+
All rights reserved.
4+
5+
This file is part of ORE, a free-software/open-source library
6+
for transparent pricing and risk analysis - http://opensourcerisk.org
7+
8+
ORE is free software: you can redistribute it and/or modify it
9+
under the terms of the Modified BSD License. You should have received a
10+
copy of the license along with this program.
11+
The license is also available online at <http://opensourcerisk.org>
12+
13+
This program is distributed on the basis that it will form a useful
14+
contribution to risk analytics and model standardisation, but WITHOUT
15+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16+
FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17+
*/
18+
19+
/*! \file orea/cube/overlaynpvcube.hpp
20+
\brief npv cube corrected by difference pricing t0 npv and sim t0 npv
21+
\ingroup cube
22+
*/
23+
24+
#pragma once
25+
26+
#include <orea/cube/npvcube.hpp>
27+
28+
namespace ore {
29+
namespace analytics {
30+
31+
class OverlayNPVCube : public NPVCube {
32+
public:
33+
OverlayNPVCube(const QuantLib::ext::shared_ptr<NPVCube>& cube, const std::map<std::string, double>& pricingNpvs);
34+
Size numIds() const override;
35+
Size numDates() const override;
36+
Size samples() const override;
37+
Size depth() const override;
38+
const std::map<std::string, Size>& idsAndIndexes() const override;
39+
const std::vector<QuantLib::Date>& dates() const override;
40+
QuantLib::Date asof() const override;
41+
Real getT0(Size id, Size depth = 0) const override;
42+
void setT0(Real value, Size id, Size depth = 0) override;
43+
Real get(Size id, Size date, Size sample, Size depth = 0) const override;
44+
void set(Real value, Size id, Size date, Size sample, Size depth = 0) override;
45+
bool usesDoublePrecision() const override;
46+
47+
private:
48+
double correction(Size id, Size depth) const;
49+
50+
QuantLib::ext::shared_ptr<NPVCube> cube_;
51+
std::vector<double> pricingNpvs_;
52+
};
53+
54+
} // namespace analytics
55+
} // namespace ore

0 commit comments

Comments
 (0)