Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
SparseNpvCube< T > Class Template Reference

#include <orea/cube/sparsenpvcube.hpp>

+ Inheritance diagram for SparseNpvCube< T >:
+ Collaboration diagram for SparseNpvCube< T >:

Public Member Functions

 SparseNpvCube ()
 
 SparseNpvCube (const Date &asof, const std::set< std::string > &ids, const std::vector< Date > &dates, Size samples, Size depth, const T &t=T())
 
Size numIds () const override
 Return the length of each dimension. More...
 
Size numDates () const override
 
Size samples () const override
 
Size depth () const override
 
Date asof () const override
 Return the asof date (T0 date) More...
 
const std::map< std::string, Size > & idsAndIndexes () const override
 Get a map of id and their index position in this cube. More...
 
const std::vector< QuantLib::Date > & dates () const override
 Get the vector of dates for this cube. More...
 
Real getT0 (Size i, Size d) const override
 Get a T0 value from the cube using index. More...
 
void setT0 (Real value, Size i, Size d) override
 Set a value in the cube using index. More...
 
Real get (Size i, Size j, Size k, Size d) const override
 Get a value from the cube using index. More...
 
void set (Real value, Size i, Size j, Size k, Size d) override
 Set a value in the cube using index. More...
 
- Public Member Functions inherited from NPVCube
 NPVCube ()
 default ctor More...
 
 NPVCube (NPVCube &)=delete
 Do not allow cube copying. More...
 
NPVCubeoperator= (NPVCube const &)=delete
 
virtual ~NPVCube ()
 dtor More...
 
virtual Size numIds () const =0
 Return the length of each dimension. More...
 
virtual Size numDates () const =0
 
virtual Size samples () const =0
 
virtual Size depth () const =0
 
virtual const std::map< std::string, Size > & idsAndIndexes () const =0
 Get a map of id and their index position in this cube. More...
 
const std::set< std::string > ids () const
 Get a set of all ids in the cube. More...
 
virtual const std::vector< QuantLib::Date > & dates () const =0
 Get the vector of dates for this cube. More...
 
virtual QuantLib::Date asof () const =0
 Return the asof date (T0 date) More...
 
virtual Real getT0 (Size id, Size depth=0) const =0
 Get a T0 value from the cube using index. More...
 
virtual Real getT0 (const std::string &id, Size depth=0) const
 Get a T0 value from the cube using trade id. More...
 
virtual void setT0 (Real value, Size id, Size depth=0)=0
 Set a value in the cube using index. More...
 
virtual void setT0 (Real value, const std::string &id, Size depth=0)
 Set a value in the cube using trade id. More...
 
virtual Real get (Size id, Size date, Size sample, Size depth=0) const =0
 Get a value from the cube using index. More...
 
virtual void set (Real value, Size id, Size date, Size sample, Size depth=0)=0
 Set a value in the cube using index. More...
 
virtual Real get (const std::string &id, const QuantLib::Date &date, Size sample, Size depth=0) const
 Get a value from the cube using trade id and date. More...
 
virtual void set (Real value, const std::string &id, const QuantLib::Date &date, Size sample, Size depth=0)
 Set a value in the cube using trade id and date. More...
 
virtual void remove (Size id)
 
virtual void remove (Size id, Size sample)
 
Size getTradeIndex (const std::string &id) const
 

Private Member Functions

void check (Size i, Size j, Size k, Size d) const
 
Size pos (Size i, Size j, Size d) const
 

Private Attributes

QuantLib::Date asof_
 
std::map< std::string, Size > ids_
 
std::vector< QuantLib::Date > dates_
 
Size samples_
 
Size depth_
 
std::map< Size, std::vector< T > > data_
 

Additional Inherited Members

- Protected Member Functions inherited from NPVCube
virtual Size index (const std::string &id) const
 
virtual Size index (const QuantLib::Date &date) const
 

Detailed Description

template<typename T>
class ore::analytics::SparseNpvCube< T >

Definition at line 36 of file sparsenpvcube.hpp.

Constructor & Destructor Documentation

◆ SparseNpvCube() [1/2]

template SparseNpvCube ( )

Definition at line 33 of file sparsenpvcube.cpp.

33{}

◆ SparseNpvCube() [2/2]

SparseNpvCube ( const Date &  asof,
const std::set< std::string > &  ids,
const std::vector< Date > &  dates,
Size  samples,
Size  depth,
const T &  t = T() 
)

Definition at line 36 of file sparsenpvcube.cpp.

39 QL_REQUIRE(ids.size() > 0, "SparseNpvCube::SparseNpvCube no ids specified");
40 QL_REQUIRE(dates.size() > 0, "SparseNpvCube::SparseNpvCube no dates specified");
41 QL_REQUIRE(samples > 0, "SparseNpvCube::SparseNpvCube samples must be > 0");
42 QL_REQUIRE(depth > 0, "SparseNpvCube::SparseNpvCube depth must be > 0");
43 Size check = std::numeric_limits<Size>::max();
44 check /= ids.size();
45 check /= dates.size();
46 check /= depth;
47 QL_REQUIRE(check >= 1, "SparseNpvCube::SparseNpvCube: total size exceeded: ids ("
48 << ids_.size() << ") * dates (" << dates.size() << ") * depth (" << depth << ") > "
49 << std::numeric_limits<Size>::max());
50 Size pos = 0;
51 for (const auto& id : ids) {
52 ids_[id] = pos++;
53 }
54}
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)
Size depth() const override
std::vector< QuantLib::Date > dates_
Size samples() const override
std::map< std::string, Size > ids_
const std::vector< QuantLib::Date > & dates() const override
Get the vector of dates for this cube.
+ Here is the call graph for this function:

Member Function Documentation

◆ numIds()

template Size numIds ( ) const
overridevirtual

Return the length of each dimension.

Implements NPVCube.

Definition at line 56 of file sparsenpvcube.cpp.

56{ return ids_.size(); }

◆ numDates()

template Size numDates ( ) const
overridevirtual

Implements NPVCube.

Definition at line 57 of file sparsenpvcube.cpp.

57{ return dates_.size(); }

◆ samples()

template Size samples ( ) const
overridevirtual

Implements NPVCube.

Definition at line 58 of file sparsenpvcube.cpp.

58{ return samples_; }
+ Here is the caller graph for this function:

◆ depth()

template Size depth ( ) const
overridevirtual

Implements NPVCube.

Definition at line 59 of file sparsenpvcube.cpp.

59{ return depth_; }
+ Here is the caller graph for this function:

◆ asof()

template Date asof ( ) const
overridevirtual

Return the asof date (T0 date)

Implements NPVCube.

Definition at line 60 of file sparsenpvcube.cpp.

60{ return asof_; }

◆ idsAndIndexes()

template const std::map< std::string, Size > & idsAndIndexes ( ) const
overridevirtual

Get a map of id and their index position in this cube.

Implements NPVCube.

Definition at line 61 of file sparsenpvcube.cpp.

61{ return ids_; }

◆ dates()

template const std::vector< QuantLib::Date > & dates ( ) const
overridevirtual

Get the vector of dates for this cube.

Implements NPVCube.

Definition at line 62 of file sparsenpvcube.cpp.

62{ return dates_; }
+ Here is the caller graph for this function:

◆ getT0()

template Real getT0 ( Size  id,
Size  depth 
) const
overridevirtual

Get a T0 value from the cube using index.

Implements NPVCube.

Definition at line 68 of file sparsenpvcube.cpp.

68 {
69 this->check(i, 0, 0, d);
70 auto v = data_.find(pos(i, 0, d));
71 if (v != data_.end())
72 return static_cast<Real>(v->second[0]);
73 else
74 return static_cast<Real>(0.0);
75}
std::map< Size, std::vector< T > > data_

◆ setT0()

template void setT0 ( Real  value,
Size  id,
Size  depth 
)
overridevirtual

Set a value in the cube using index.

Implements NPVCube.

Definition at line 77 of file sparsenpvcube.cpp.

77 {
78 this->check(i, 0, 0, d);
79 if (QuantLib::close_enough(value, 0.0))
80 return;
81 data_[pos(i, 0, d)] = std::vector<T>(1, static_cast<T>(value));
82}

◆ get()

template Real get ( Size  id,
Size  date,
Size  sample,
Size  depth 
) const
overridevirtual

Get a value from the cube using index.

Implements NPVCube.

Definition at line 84 of file sparsenpvcube.cpp.

84 {
85 this->check(i, j, k, d);
86 auto v = data_.find(pos(i, j + 1, d));
87 if (v != data_.end())
88 return static_cast<Real>(v->second[k]);
89 else
90 return static_cast<Real>(0.0);
91}

◆ set()

template void set ( Real  value,
Size  id,
Size  date,
Size  sample,
Size  depth 
)
overridevirtual

Set a value in the cube using index.

Implements NPVCube.

Definition at line 93 of file sparsenpvcube.cpp.

93 {
94 this->check(i, j, k, d);
95 if (QuantLib::close_enough(value, 0.0))
96 return;
97 auto v = data_.find(pos(i, j + 1, d));
98 if (v != data_.end()) {
99 v->second[k] = static_cast<T>(value);
100 } else {
101 std::vector<T> tmp(samples(), 0.0);
102 tmp[k] = static_cast<T>(value);
103 data_[pos(i, j + 1, d)] = tmp;
104 }
105}
SafeStack< ValueType > value

◆ check()

template void check ( Size  i,
Size  j,
Size  k,
Size  d 
) const
private

Definition at line 107 of file sparsenpvcube.cpp.

107 {
108 QL_REQUIRE(i < numIds(), "Out of bounds on ids (i=" << i << ", numIds=" << numIds() << ")");
109 QL_REQUIRE(j < numDates(), "Out of bounds on dates (j=" << j << ", numDates=" << numDates() << ")");
110 QL_REQUIRE(k < samples(), "Out of bounds on samples (k=" << k << ", samples=" << samples() << ")");
111 QL_REQUIRE(d < depth(), "Out of bounds on depth (d=" << d << ", depth=" << depth() << ")");
112}
Size numIds() const override
Return the length of each dimension.
Size numDates() const override

◆ pos()

template Size pos ( Size  i,
Size  j,
Size  d 
) const
private

Definition at line 64 of file sparsenpvcube.cpp.

64 {
65 return (i * (numDates() + 1) + j) * depth() + d;
66}
+ Here is the caller graph for this function:

Member Data Documentation

◆ asof_

QuantLib::Date asof_
private

Definition at line 57 of file sparsenpvcube.hpp.

◆ ids_

std::map<std::string, Size> ids_
private

Definition at line 58 of file sparsenpvcube.hpp.

◆ dates_

std::vector<QuantLib::Date> dates_
private

Definition at line 59 of file sparsenpvcube.hpp.

◆ samples_

Size samples_
private

Definition at line 60 of file sparsenpvcube.hpp.

◆ depth_

Size depth_
private

Definition at line 61 of file sparsenpvcube.hpp.

◆ data_

std::map<Size, std::vector<T> > data_
private

Definition at line 62 of file sparsenpvcube.hpp.