21#include <ql/errors.hpp>
30 const QuantLib::ext::shared_ptr<NPVSensiCube>& cube2,
const std::set<std::string>& ids)
34 const std::set<std::string>& ids)
39 QL_REQUIRE(!cubes.empty(),
"JointNPVSensiCube: at least one cube must be given");
43 for (Size i = 1; i < cubes.size(); ++i) {
45 "JointNPVSensiCube: numDates do not match for cube #"
48 "JointNPVSensiCube: samples do not match for cube #"
51 << i <<
" (" <<
cubes_[i]->
depth() <<
" vs. cube #0 ("
52 << cubes[0]->
depth() <<
")");
55 std::set<std::string> allIds;
61 for (Size i = 0; i <
cubes_.size(); ++i) {
63 const auto& [ignored2, success] = allIds.insert(
id);
65 "JointNPVSensiCube: input cubes have duplicate id '" <<
id <<
"', this is not allowed");
72 for (
const auto&
id : allIds) {
78 for (
const auto& [
id, jointPos] :
idIdx_) {
79 for (
auto const& c :
cubes_) {
80 auto searchIt = c->idsAndIndexes().find(
id);
81 if (searchIt != c->idsAndIndexes().end()) {
82 QL_REQUIRE(
cubeAndId_[jointPos].first ==
nullptr,
83 "JointNPVSensiCube: input cubes have duplicate id '" <<
id <<
"', this is not allowed");
84 cubeAndId_[jointPos] = std::make_pair(c, searchIt->second);
106 "JointNPVSensiCube: id (" <<
id <<
") out of range, have " <<
cubeAndId_.size() <<
" ids");
112 return c.first->getT0(c.second,
depth);
122 return c.first->get(c.second, date, sample,
depth);
127 c.first->set(
value, c.second, date, sample,
depth);
132 return c.first->getTradeNPVs(c.second);
136 std::set<QuantLib::Size> tmp;
137 for (
auto const& c :
cubes_) {
138 auto r = c->relevantScenarios();
139 tmp.insert(r.begin(), r.end());
146 c.first->remove(c.second);
151 c.first->remove(c.second, sample);
void set(Real value, Size id, Size date, Size sample, Size depth=0) override
Set a value in the cube using index.
Size numDates() const override
std::set< QuantLib::Size > relevantScenarios() const override
const std::map< std::string, Size > & idsAndIndexes() const override
Get a map of id and their index position in this cube.
Real getT0(Size id, Size depth=0) const override
Get a T0 value from the cube using index.
std::vector< std::pair< QuantLib::ext::shared_ptr< NPVSensiCube >, Size > > cubeAndId_
Size numIds() const override
Return the length of each dimension.
const std::pair< QuantLib::ext::shared_ptr< NPVSensiCube >, Size > & cubeAndId(Size id) const
const std::vector< QuantLib::ext::shared_ptr< NPVSensiCube > > cubes_
JointNPVSensiCube(const QuantLib::ext::shared_ptr< NPVSensiCube > &cube1, const QuantLib::ext::shared_ptr< NPVSensiCube > &cube2, const std::set< std::string > &ids={})
const std::vector< QuantLib::Date > & dates() const override
Get the vector of dates for this cube.
Size depth() const override
void remove(Size id) override
QuantLib::Date asof() const override
Return the asof date (T0 date)
std::map< QuantLib::Size, QuantLib::Real > getTradeNPVs(Size tradeIdx) const override
std::map< std::string, Size > idIdx_
Size samples() const override
void setT0(Real value, Size id, Size depth=0) override
Set a value in the cube using index.
Real get(Size id, Size date, Size sample, Size depth=0) const override
Get a value from the cube using index.
const std::set< std::string > ids() const
Get a set of all ids in the cube.
NPVSensiCube class stores NPVs resulting from risk factor shifts on an as of date.
SafeStack< ValueType > value
join n sensi cubes in terms of stored ids