|
| 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 |
0 commit comments