Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
sparsenpvcube.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 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/sparsenpvcube.hpp
20 \brief in memory cube, storing only non-zero entries for (id, date, depth)
21*/
22
23#pragma once
24
25#include <orea/cube/npvcube.hpp>
26
27#include <map>
28#include <set>
29
30namespace ore {
31namespace analytics {
32using QuantLib::Date;
33using QuantLib::Real;
34using QuantLib::Size;
35
36template <typename T> class SparseNpvCube : public ore::analytics::NPVCube {
37public:
39 SparseNpvCube(const Date& asof, const std::set<std::string>& ids, const std::vector<Date>& dates, Size samples,
40 Size depth, const T& t = T());
41 Size numIds() const override;
42 Size numDates() const override;
43 Size samples() const override;
44 Size depth() const override;
45 Date asof() const override;
46 const std::map<std::string, Size>& idsAndIndexes() const override;
47 const std::vector<QuantLib::Date>& dates() const override;
48 Real getT0(Size i, Size d) const override;
49 void setT0(Real value, Size i, Size d) override;
50 Real get(Size i, Size j, Size k, Size d) const override;
51 void set(Real value, Size i, Size j, Size k, Size d) override;
52
53private:
54 void check(Size i, Size j, Size k, Size d) const;
55 Size pos(Size i, Size j, Size d) const;
56
57 QuantLib::Date asof_;
58 std::map<std::string, Size> ids_;
59 std::vector<QuantLib::Date> dates_;
61 Size depth_;
62 std::map<Size, std::vector<T>> data_;
63};
64
67
68} // namespace analytics
69} // namespace ore
NPV Cube class stores both future and current NPV values.
Definition: npvcube.hpp:53
const std::set< std::string > ids() const
Get a set of all ids in the cube.
Definition: npvcube.hpp:75
Size pos(Size i, Size j, Size d) const
Date asof() const override
Return the asof date (T0 date)
Real get(Size i, Size j, Size k, Size d) const override
Get a value from the cube using index.
Size numIds() const override
Return the length of each dimension.
Size depth() const override
std::map< Size, std::vector< T > > data_
Real getT0(Size i, Size d) const override
Get a T0 value from the cube using index.
std::vector< QuantLib::Date > dates_
void setT0(Real value, Size i, Size d) override
Set a value in the cube using index.
Size numDates() const override
void set(Real value, Size i, Size j, Size k, Size d) override
Set a value in the cube using index.
Size samples() const override
std::map< std::string, Size > ids_
const std::map< std::string, Size > & idsAndIndexes() const override
Get a map of id and their index position in this cube.
const std::vector< QuantLib::Date > & dates() const override
Get the vector of dates for this cube.
SafeStack< ValueType > value
The base NPV cube class.