Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
npvsensicube.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 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/npvsensicube.hpp
20 \brief An NPV cube for storing NPVs resulting from risk factor shifts
21 \ingroup cube
22*/
23
24#pragma once
25
26#include <map>
27#include <orea/cube/npvcube.hpp>
28#include <ql/time/date.hpp>
29#include <ql/types.hpp>
30#include <set>
31
32namespace ore {
33namespace analytics {
34//! NPVSensiCube class stores NPVs resulting from risk factor shifts on an as of date.
35/*! This class is a restriction of the NPVCube to a grid of values where the ids are
36 trade IDs and the samples are risk factor shifts
37
38 \ingroup cube
39 */
40class NPVSensiCube : public NPVCube {
41public:
42 using NPVCube::get;
43 using NPVCube::set;
44
45 //! Number of dates in the NPVSensiCube is exactly one i.e. the as of date
46 QuantLib::Size numDates() const override { return 1; }
47
48 //! The depth in the NPVSensiCube is exactly one
49 QuantLib::Size depth() const override { return 1; }
50
51 //! Convenience method to get a value from the cube using \p id and \p sample only
52 Real get(QuantLib::Size id, QuantLib::Size sample) const { return this->get(id, 0, sample, 0); }
53
54 //! Convenience method to get a value from the cube using \p id and \p sample only
55 Real get(const std::string& id, QuantLib::Size sample) const { return this->get(id, asof(), sample, 0); };
56
57 //! Convenience method to set a value in the cube using \p id and \p sample only
58 void set(QuantLib::Real value, QuantLib::Size id, QuantLib::Size sample) { this->set(value, id, 0, sample, 0); }
59
60 //! Convenience method to set a value in the cube using \p id and \p sample only
61 void set(QuantLib::Real value, const std::string& id, QuantLib::Size sample) {
62 this->set(value, id, asof(), sample, 0);
63 }
64
65 //! Return the index of the trade in the cube
66 Size getTradeIndex(const std::string& tradeId) const { return index(tradeId); }
67
68 /*! Return a map for the trade ID at index \p tradeIdx where the map key is the index of the
69 risk factor shift and the map value is the NPV under that shift
70 */
71 virtual std::map<QuantLib::Size, QuantLib::Real> getTradeNPVs(Size tradeIdx) const = 0;
72
73 /*! Return a map for the \p tradeId where the map key is the index of the
74 risk factor shift and the map value is the NPV under that shift
75 */
76 std::map<QuantLib::Size, QuantLib::Real> getTradeNPVs(const std::string& tradeId) const {
77 return getTradeNPVs(index(tradeId));
78 }
79
80 /*! Return the set of scenario indices with non-zero result */
81 virtual std::set<QuantLib::Size> relevantScenarios() const = 0;
82};
83
84} // namespace analytics
85} // namespace ore
NPV Cube class stores both future and current NPV values.
Definition: npvcube.hpp:53
virtual Real get(Size id, Size date, Size sample, Size depth=0) const =0
Get a value from the cube using index.
virtual QuantLib::Date asof() const =0
Return the asof date (T0 date)
virtual void set(Real value, Size id, Size date, Size sample, Size depth=0)=0
Set a value in the cube using index.
virtual Size index(const std::string &id) const
Definition: npvcube.hpp:121
NPVSensiCube class stores NPVs resulting from risk factor shifts on an as of date.
Size getTradeIndex(const std::string &tradeId) const
Return the index of the trade in the cube.
QuantLib::Size depth() const override
The depth in the NPVSensiCube is exactly one.
std::map< QuantLib::Size, QuantLib::Real > getTradeNPVs(const std::string &tradeId) const
virtual std::set< QuantLib::Size > relevantScenarios() const =0
void set(QuantLib::Real value, const std::string &id, QuantLib::Size sample)
Convenience method to set a value in the cube using id and sample only.
Real get(const std::string &id, QuantLib::Size sample) const
Convenience method to get a value from the cube using id and sample only.
void set(QuantLib::Real value, QuantLib::Size id, QuantLib::Size sample)
Convenience method to set a value in the cube using id and sample only.
Real get(QuantLib::Size id, QuantLib::Size sample) const
Convenience method to get a value from the cube using id and sample only.
virtual std::map< QuantLib::Size, QuantLib::Real > getTradeNPVs(Size tradeIdx) const =0
QuantLib::Size numDates() const override
Number of dates in the NPVSensiCube is exactly one i.e. the as of date.
SafeStack< ValueType > value
The base NPV cube class.