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

SensiCube stores only npvs not equal to the base npvs. More...

#include <orea/cube/sensicube.hpp>

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

Public Member Functions

 SensiCube (const std::set< std::string > &ids, const QuantLib::Date &asof, QuantLib::Size samples, const T &t=T())
 
QuantLib::Size numIds () const override
 Return the length of each dimension. More...
 
QuantLib::Size samples () const override
 
const std::map< std::string, Size > & idsAndIndexes () const override
 Get the vector of ids for this cube. More...
 
const std::vector< QuantLib::Date > & dates () const override
 Get the vector of dates for this cube. More...
 
QuantLib::Date asof () const override
 Return the asof date (T0 date) More...
 
Real getT0 (Size i, Size) const override
 Get a T0 value from the cube. More...
 
void setT0 (Real value, Size i, Size) override
 Set a value in the cube. More...
 
Real get (Size i, Size j, Size k, Size) const override
 Get a value from the cube. More...
 
void set (Real value, Size i, Size j, Size k, Size) override
 Set a value in the cube. More...
 
void remove (Size i) override
 
void remove (Size i, Size k) override
 
std::map< QuantLib::Size, QuantLib::Real > getTradeNPVs (QuantLib::Size i) const override
 
std::set< QuantLib::Size > relevantScenarios () const override
 
- Public Member Functions inherited from NPVSensiCube
QuantLib::Size numDates () const override
 Number of dates in the NPVSensiCube is exactly one i.e. the as of date. More...
 
QuantLib::Size depth () const override
 The depth in the NPVSensiCube is exactly one. More...
 
Real get (QuantLib::Size id, QuantLib::Size sample) const
 Convenience method to get a value from the cube using id and sample only. More...
 
Real get (const std::string &id, QuantLib::Size sample) const
 Convenience method to get a value from the cube using id and sample only. More...
 
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. More...
 
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. More...
 
Size getTradeIndex (const std::string &tradeId) const
 Return the index of the trade in the cube. More...
 
virtual std::map< QuantLib::Size, QuantLib::Real > getTradeNPVs (Size tradeIdx) const =0
 
std::map< QuantLib::Size, QuantLib::Real > getTradeNPVs (const std::string &tradeId) const
 
virtual std::set< QuantLib::Size > relevantScenarios () const =0
 
virtual Real get (Size id, Size date, Size sample, Size depth=0) const=0
 Get a value from 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, Size id, Size date, Size sample, Size depth=0)=0
 Set a value in the cube using index. 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...
 
- 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
 

Protected Member Functions

void check (QuantLib::Size i, QuantLib::Size j, QuantLib::Size k) const
 
- Protected Member Functions inherited from NPVCube
virtual Size index (const std::string &id) const
 
virtual Size index (const QuantLib::Date &date) const
 

Protected Attributes

std::vector< T > t0Data_
 
std::vector< std::map< QuantLib::Size, T > > tradeNPVs_
 
std::set< QuantLib::Size > relevantScenarios_
 

Private Attributes

std::map< std::string, Size > idIdx_
 
QuantLib::Date asof_
 
std::vector< QuantLib::Date > dates_
 
QuantLib::Size samples_
 

Detailed Description

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

SensiCube stores only npvs not equal to the base npvs.

Definition at line 45 of file sensicube.hpp.

Constructor & Destructor Documentation

◆ SensiCube()

SensiCube ( const std::set< std::string > &  ids,
const QuantLib::Date &  asof,
QuantLib::Size  samples,
const T &  t = T() 
)

Definition at line 47 of file sensicube.hpp.

48 : asof_(asof), dates_(1, asof), samples_(samples), t0Data_(ids.size(), t),
49 tradeNPVs_(ids.size(), map<Size, T>()) {
50 Size pos = 0;
51 for (const auto& id : ids) {
52 idIdx_[id] = pos++;
53 }
54 }
const std::set< std::string > ids() const
Get a set of all ids in the cube.
Definition: npvcube.hpp:75
QuantLib::Size samples() const override
Definition: sensicube.hpp:58
QuantLib::Size samples_
Definition: sensicube.hpp:122
std::vector< std::map< QuantLib::Size, T > > tradeNPVs_
Definition: sensicube.hpp:126
std::vector< QuantLib::Date > dates_
Definition: sensicube.hpp:121
std::vector< T > t0Data_
Definition: sensicube.hpp:125
QuantLib::Date asof() const override
Return the asof date (T0 date)
Definition: sensicube.hpp:67
std::map< std::string, Size > idIdx_
Definition: sensicube.hpp:119
+ Here is the call graph for this function:

Member Function Documentation

◆ numIds()

QuantLib::Size numIds ( ) const
overridevirtual

Return the length of each dimension.

Implements NPVCube.

Definition at line 57 of file sensicube.hpp.

57{ return idIdx_.size(); }
+ Here is the caller graph for this function:

◆ samples()

QuantLib::Size samples ( ) const
overridevirtual

Implements NPVCube.

Definition at line 58 of file sensicube.hpp.

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

◆ idsAndIndexes()

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

Get the vector of ids for this cube.

Implements NPVCube.

Definition at line 61 of file sensicube.hpp.

61{ return idIdx_; }

◆ dates()

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

Get the vector of dates for this cube.

Implements NPVCube.

Definition at line 64 of file sensicube.hpp.

64{ return dates_; }

◆ asof()

QuantLib::Date asof ( ) const
overridevirtual

Return the asof date (T0 date)

Implements NPVCube.

Definition at line 67 of file sensicube.hpp.

67{ return asof_; }

◆ getT0()

Real getT0 ( Size  i,
Size   
) const
overridevirtual

Get a T0 value from the cube.

Implements NPVCube.

Definition at line 70 of file sensicube.hpp.

70 {
71 this->check(i, 0, 0);
72 return this->t0Data_[i];
73 }

◆ setT0()

void setT0 ( Real  value,
Size  i,
Size   
)
overridevirtual

Set a value in the cube.

Implements NPVCube.

Definition at line 76 of file sensicube.hpp.

76 {
77 this->check(i, 0, 0);
78 this->t0Data_[i] = static_cast<T>(value);
79 }
SafeStack< ValueType > value

◆ get()

Real get ( Size  i,
Size  j,
Size  k,
Size   
) const
overridevirtual

Get a value from the cube.

Implements NPVCube.

Definition at line 82 of file sensicube.hpp.

82 {
83 this->check(i, j, k);
84
85 auto itr = this->tradeNPVs_[i].find(k);
86 if (itr != tradeNPVs_[i].end()) {
87 return itr->second;
88 } else {
89 return this->t0Data_[i];
90 }
91 }

◆ set()

void set ( Real  value,
Size  i,
Size  j,
Size  k,
Size   
)
overridevirtual

Set a value in the cube.

Implements NPVCube.

Definition at line 94 of file sensicube.hpp.

94 {
95 this->check(i, j, k);
96 T castValue = static_cast<T>(value);
97 if (boost::math::epsilon_difference<T>(castValue, t0Data_[i]) > 42) {
98 this->tradeNPVs_[i][k] = castValue;
99 relevantScenarios_.insert(k);
100 }
101 }
std::set< QuantLib::Size > relevantScenarios_
Definition: sensicube.hpp:127

◆ remove() [1/2]

void remove ( Size  id)
overridevirtual

remove all values for a given id, i.e. change the state as if setT0() and set() has never been called for the id the default implementation has generelly to be overriden in derived classes depending on how values are stored

Reimplemented from NPVCube.

Definition at line 103 of file sensicube.hpp.

103 {
104 this->check(i,0,0);
105 this->t0Data_[i] = 0.0;
106 this->tradeNPVs_[i].clear();
107 }

◆ remove() [2/2]

void remove ( Size  id,
Size  sample 
)
overridevirtual

simliar as above, but remove all values for a given id and scenario and keep T0 values

Reimplemented from NPVCube.

Definition at line 109 of file sensicube.hpp.

109 {
110 this->check(i,0,k);
111 this->tradeNPVs_[i].erase(k);
112 }

◆ getTradeNPVs()

std::map< QuantLib::Size, QuantLib::Real > getTradeNPVs ( QuantLib::Size  i) const
override

Definition at line 114 of file sensicube.hpp.

114{ return tradeNPVs_[i]; }

◆ relevantScenarios()

std::set< QuantLib::Size > relevantScenarios ( ) const
overridevirtual

Return the set of scenario indices with non-zero result

Implements NPVSensiCube.

Definition at line 116 of file sensicube.hpp.

116{ return relevantScenarios_; }

◆ check()

void check ( QuantLib::Size  i,
QuantLib::Size  j,
QuantLib::Size  k 
) const
protected

Definition at line 129 of file sensicube.hpp.

129 {
130 QL_REQUIRE(i < numIds(), "Out of bounds on ids (i=" << i << ")");
131 QL_REQUIRE(j < depth(), "Out of bounds on depth (j=" << j << ")");
132 QL_REQUIRE(k < samples(), "Out of bounds on samples (k=" << k << ")");
133 }
QuantLib::Size depth() const override
The depth in the NPVSensiCube is exactly one.
QuantLib::Size numIds() const override
Return the length of each dimension.
Definition: sensicube.hpp:57
+ Here is the call graph for this function:

Member Data Documentation

◆ idIdx_

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

Definition at line 119 of file sensicube.hpp.

◆ asof_

QuantLib::Date asof_
private

Definition at line 120 of file sensicube.hpp.

◆ dates_

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

Definition at line 121 of file sensicube.hpp.

◆ samples_

QuantLib::Size samples_
private

Definition at line 122 of file sensicube.hpp.

◆ t0Data_

std::vector<T> t0Data_
protected

Definition at line 125 of file sensicube.hpp.

◆ tradeNPVs_

std::vector<std::map<QuantLib::Size, T> > tradeNPVs_
protected

Definition at line 126 of file sensicube.hpp.

◆ relevantScenarios_

std::set<QuantLib::Size> relevantScenarios_
protected

Definition at line 127 of file sensicube.hpp.