Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
jointnpvsensicube.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 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/jointnpvsensicube.hpp
20 \brief join n sensi cubes in terms of stored ids
21 \ingroup cube
22*/
23
24#pragma once
25
27
28#include <set>
29
30namespace ore {
31namespace analytics {
32
33using namespace ore::analytics;
34
35using QuantLib::Real;
36using QuantLib::Size;
37
39public:
40 /*! ctor for two input cubes */
41 JointNPVSensiCube(const QuantLib::ext::shared_ptr<NPVSensiCube>& cube1, const QuantLib::ext::shared_ptr<NPVSensiCube>& cube2,
42 const std::set<std::string>& ids = {});
43
44 /*! ctor for n input cubes
45 If no ids are given, the ids in the input cubes define theids in the resulting cube, the ids must be unique
46 in this case. If ids are given they define the ids in the output cube.
47 */
48 JointNPVSensiCube(const std::vector<QuantLib::ext::shared_ptr<NPVSensiCube>>& cubes,
49 const std::set<std::string>& ids = {});
50
51 //! Return the length of each dimension
52 Size numIds() const override;
53 Size numDates() const override;
54 Size samples() const override;
55 Size depth() const override;
56
57 const std::map<std::string, Size>& idsAndIndexes() const override;
58 const std::vector<QuantLib::Date>& dates() const override;
59 QuantLib::Date asof() const override;
60
61 Real getT0(Size id, Size depth = 0) const override;
62 void setT0(Real value, Size id, Size depth = 0) override;
63
64 Real get(Size id, Size date, Size sample, Size depth = 0) const override;
65 void set(Real value, Size id, Size date, Size sample, Size depth = 0) override;
66
67 std::map<QuantLib::Size, QuantLib::Real> getTradeNPVs(Size tradeIdx) const override;
68 std::set<QuantLib::Size> relevantScenarios() const override;
69
70 void remove(Size id) override;
71 void remove(Size id, Size sample) override;
72
73private:
74 const std::pair<QuantLib::ext::shared_ptr<NPVSensiCube>, Size>& cubeAndId(Size id) const;
75 std::map<std::string, Size> idIdx_;
76 std::vector<std::pair<QuantLib::ext::shared_ptr<NPVSensiCube>, Size>> cubeAndId_;
77 const std::vector<QuantLib::ext::shared_ptr<NPVSensiCube>> cubes_;
78};
79
80} // namespace analytics
81} // namespace ore
void set(Real value, Size id, Size date, Size sample, Size depth=0) override
Set a value in the cube using index.
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_
const std::vector< QuantLib::Date > & dates() const override
Get the vector of dates for this cube.
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_
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.
Definition: npvcube.hpp:75
NPVSensiCube class stores NPVs resulting from risk factor shifts on an as of date.
SafeStack< ValueType > value
An NPV cube for storing NPVs resulting from risk factor shifts.