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

JaggedCube stores the cube in memory using a vector of trade specific blocks. More...

#include <orea/cube/jaggedcube.hpp>

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

Public Member Functions

 JaggedCube (Date asof, QuantLib::ext::shared_ptr< ore::data::Portfolio > &portfolio, const vector< Date > &dates, Size samples, Size depth)
 
 JaggedCube (Date asof, QuantLib::ext::shared_ptr< ore::data::Portfolio > &portfolio, const vector< Date > &dates, Size samples, const DepthCalculator &dc)
 
void init (Date asof, QuantLib::ext::shared_ptr< ore::data::Portfolio > &portfolio, const vector< Date > &dates, Size samples, const DepthCalculator &dc)
 
Size numIds () const override
 Return the length of each dimension. More...
 
Size numDates () const override
 
Size samples () const override
 
Size depth () const override
 
Real avgDateLen () const
 
Real avgDepth () const
 
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 d) const override
 Get a T0 value from the cube. More...
 
void setT0 (Real value, Size i, Size d) override
 Set a value in the cube. More...
 
Real get (Size i, Size j, Size k, Size d) const override
 Get a value from the cube. More...
 
void set (Real value, Size i, Size j, Size k, Size d) override
 Set a value in the cube. 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 (Size i, Size j, Size k, Size d) const
 
- Protected Member Functions inherited from NPVCube
virtual Size index (const std::string &id) const
 
virtual Size index (const QuantLib::Date &date) const
 

Private Member Functions

template<class Archive >
void serialize (Archive &ar, const unsigned int)
 

Private Attributes

QuantLib::Date asof_
 
std::map< std::string, Size > ids_
 
vector< QuantLib::Date > dates_
 
Size samples_
 
Size maxDepth_
 
vector< TradeBlock< T > > blocks_
 

Friends

class boost::serialization::access
 

Detailed Description

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

JaggedCube stores the cube in memory using a vector of trade specific blocks.

JaggedCube stores the cube in memory using a vector of trade specific blocks to allow both single and double precision implementations.

Definition at line 140 of file jaggedcube.hpp.

Constructor & Destructor Documentation

◆ JaggedCube() [1/2]

JaggedCube ( Date  asof,
QuantLib::ext::shared_ptr< ore::data::Portfolio > &  portfolio,
const vector< Date > &  dates,
Size  samples,
Size  depth 
)

Definition at line 142 of file jaggedcube.hpp.

143 {
144 init(asof, portfolio, dates, samples, ConstantDepthCalculator(depth));
145 }
const std::vector< QuantLib::Date > & dates() const override
Get the vector of dates for this cube.
Definition: jaggedcube.hpp:210
void init(Date asof, QuantLib::ext::shared_ptr< ore::data::Portfolio > &portfolio, const vector< Date > &dates, Size samples, const DepthCalculator &dc)
Definition: jaggedcube.hpp:153
Size depth() const override
Definition: jaggedcube.hpp:183
QuantLib::Date asof() const override
Return the asof date (T0 date)
Definition: jaggedcube.hpp:213
Size samples() const override
Definition: jaggedcube.hpp:182
+ Here is the call graph for this function:

◆ JaggedCube() [2/2]

JaggedCube ( Date  asof,
QuantLib::ext::shared_ptr< ore::data::Portfolio > &  portfolio,
const vector< Date > &  dates,
Size  samples,
const DepthCalculator dc 
)

Definition at line 147 of file jaggedcube.hpp.

148 {
149 init(asof, portfolio, dates, samples, dc);
150 }
+ Here is the call graph for this function:

Member Function Documentation

◆ init()

void init ( Date  asof,
QuantLib::ext::shared_ptr< ore::data::Portfolio > &  portfolio,
const vector< Date > &  dates,
Size  samples,
const DepthCalculator dc 
)

Definition at line 153 of file jaggedcube.hpp.

154 {
155 asof_ = asof;
156 dates_ = dates;
158 maxDepth_ = 0;
159 // Loop over each trade, calculate it's dateLength by checking the trade maturity
160 // get depth with the depth calculator
161 // create a TradeBlock with these parameters and store it.
162 //
163 // setup asof, .....
164 Size pos = 0;
165 for (const auto& [tid, t] : portfolio->trades()) {
166 // for each trade: set id and set a tradeblock
167 ids_[tid] = pos++;
168 // TradeBlock
169 Size depth = dc.depth(t);
170 maxDepth_ = std::max(maxDepth_, depth);
171
172 Size dateLen = 0;
173 while (dateLen < dates_.size() && dates_[dateLen] < t->maturity())
174 dateLen++;
175 blocks_.push_back(TradeBlock<T>(dateLen, depth, samples));
176 }
177 }
std::map< std::string, Size > ids_
Definition: jaggedcube.hpp:261
vector< TradeBlock< T > > blocks_
Definition: jaggedcube.hpp:265
vector< QuantLib::Date > dates_
Definition: jaggedcube.hpp:262
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ numIds()

Size numIds ( ) const
overridevirtual

Return the length of each dimension.

Implements NPVCube.

Definition at line 180 of file jaggedcube.hpp.

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

◆ numDates()

Size numDates ( ) const
overridevirtual

Implements NPVCube.

Definition at line 181 of file jaggedcube.hpp.

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

◆ samples()

Size samples ( ) const
overridevirtual

Implements NPVCube.

Definition at line 182 of file jaggedcube.hpp.

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

◆ depth()

Size depth ( ) const
overridevirtual

Implements NPVCube.

Definition at line 183 of file jaggedcube.hpp.

183{ return maxDepth_; }
+ Here is the caller graph for this function:

◆ avgDateLen()

Real avgDateLen ( ) const

Definition at line 185 of file jaggedcube.hpp.

185 {
186 // loop over tradeblocks
187 Size dateTotal = 0;
188 Real dateLenAvg = 0.0;
189 for (auto b : blocks_)
190 dateTotal += b.dateLen;
191 // get date length of each
192 // return avg date (float)
193 dateLenAvg = dateTotal / blocks_.size();
194 return dateLenAvg;
195 }

◆ avgDepth()

Real avgDepth ( ) const

Definition at line 197 of file jaggedcube.hpp.

197 {
198 // same as above
199 Size depthTotal = 0;
200 Real depthAvg = 0.0;
201 for (auto b : blocks_)
202 depthTotal += b.depth;
203 depthAvg = depthTotal / blocks_.size();
204 return depthAvg;
205 }

◆ idsAndIndexes()

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

Get the vector of ids for this cube.

Implements NPVCube.

Definition at line 208 of file jaggedcube.hpp.

208{ return ids_; }

◆ dates()

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

Get the vector of dates for this cube.

Implements NPVCube.

Definition at line 210 of file jaggedcube.hpp.

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

◆ asof()

QuantLib::Date asof ( ) const
overridevirtual

Return the asof date (T0 date)

Implements NPVCube.

Definition at line 213 of file jaggedcube.hpp.

213{ return asof_; }
+ Here is the caller graph for this function:

◆ getT0()

Real getT0 ( Size  i,
Size  d 
) const
overridevirtual

Get a T0 value from the cube.

Implements NPVCube.

Definition at line 216 of file jaggedcube.hpp.

216 {
217 QL_REQUIRE(i < blocks_.size(), "Invalid trade index i " << i);
218 return blocks_[i].getT0(d);
219 }

◆ setT0()

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

Set a value in the cube.

Implements NPVCube.

Definition at line 222 of file jaggedcube.hpp.

222 {
223 QL_REQUIRE(i < blocks_.size(), "Invalid trade index i " << i);
224 TradeBlock<T>& tb = blocks_[i];
225 return tb.setT0(value, d);
226 }
+ Here is the call graph for this function:

◆ get()

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

Get a value from the cube.

Implements NPVCube.

Definition at line 229 of file jaggedcube.hpp.

229 {
230 check(i, j, k, d);
231 return blocks_[i].get(j, k, d);
232 }

◆ set()

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

Set a value in the cube.

Implements NPVCube.

Definition at line 235 of file jaggedcube.hpp.

235 {
236 check(i, j, k, d);
237 TradeBlock<T>& tb = blocks_[i];
238 return tb.set(value, j, k, d);
239 }
+ Here is the call graph for this function:

◆ check()

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

Definition at line 242 of file jaggedcube.hpp.

242 {
243 QL_REQUIRE(i < numIds(), "Out of bounds on ids (i=" << i << ")");
244 QL_REQUIRE(j < numDates(), "Out of bounds on dates (j=" << j << ")");
245 QL_REQUIRE(k < samples(), "Out of bounds on samples (k=" << k << ")");
246 QL_REQUIRE(d < depth(), "Out of bounds on depth (d=" << d << ")");
247 }
Size numDates() const override
Definition: jaggedcube.hpp:181
Size numIds() const override
Return the length of each dimension.
Definition: jaggedcube.hpp:180
+ Here is the call graph for this function:

◆ serialize()

void serialize ( Archive &  ar,
const unsigned int   
)
private

Definition at line 251 of file jaggedcube.hpp.

251 {
252 ar& asof_;
253 ar& ids_;
254 ar& dates_;
255 ar& samples_;
256 ar& maxDepth_;
257 ar& blocks_;
258 }

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Definition at line 250 of file jaggedcube.hpp.

Member Data Documentation

◆ asof_

QuantLib::Date asof_
private

Definition at line 260 of file jaggedcube.hpp.

◆ ids_

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

Definition at line 261 of file jaggedcube.hpp.

◆ dates_

vector<QuantLib::Date> dates_
private

Definition at line 262 of file jaggedcube.hpp.

◆ samples_

Size samples_
private

Definition at line 263 of file jaggedcube.hpp.

◆ maxDepth_

Size maxDepth_
private

Definition at line 264 of file jaggedcube.hpp.

◆ blocks_

vector<TradeBlock<T> > blocks_
private

Definition at line 265 of file jaggedcube.hpp.