29#include <ql/errors.hpp>
31#include <boost/make_shared.hpp>
57 QL_REQUIRE(
ids.size() > 0,
"InMemoryCube::InMemoryCube no ids specified");
58 QL_REQUIRE(
dates.size() > 0,
"InMemoryCube::InMemoryCube no dates specified");
59 QL_REQUIRE(
samples > 0,
"InMemoryCube::InMemoryCube samples must be > 0");
61 for (
const auto&
id :
ids) {
78 const std::vector<QuantLib::Date>&
dates()
const override {
return dates_; }
81 QuantLib::Date
asof()
const override {
return asof_; }
84 void check(Size i, Size j, Size k, Size d)
const {
85 QL_REQUIRE(i <
numIds(),
"Out of bounds on ids (i=" << i <<
", numIds=" <<
numIds() <<
")");
86 QL_REQUIRE(j <
numDates(),
"Out of bounds on dates (j=" << j <<
", numDates=" <<
numDates() <<
")");
87 QL_REQUIRE(k <
samples(),
"Out of bounds on samples (k=" << k <<
", samples=" <<
samples() <<
")");
88 QL_REQUIRE(d <
depth(),
"Out of bounds on depth (d=" << d <<
", depth=" <<
depth() <<
")");
95 vector<vector<vector<T>>>
data_;
115 Size
depth()
const override {
return 1; }
118 virtual Real
getT0(Size i, Size d)
const override {
119 this->
check(i, 0, 0, d);
124 virtual void setT0(Real value, Size i, Size d)
override {
125 this->
check(i, 0, 0, d);
130 Real
get(Size i, Size j, Size k, Size d)
const override {
131 this->
check(i, j, k, d);
132 return this->
data_[i][j][k];
136 void set(Real value, Size i, Size j, Size k, Size d)
override {
137 this->
check(i, j, k, d);
156 Size
depth()
const override {
return this->
data_[0][0][0].size(); }
159 virtual Real
getT0(Size i, Size d)
const override {
160 this->
check(i, 0, 0, d);
165 virtual void setT0(Real value, Size i, Size d)
override {
166 this->
check(i, 0, 0, d);
171 Real
get(Size i, Size j, Size k, Size d)
const override {
172 this->
check(i, j, k, d);
173 return this->
data_[i][j][k][d];
177 void set(Real value, Size i, Size j, Size k, Size d)
override {
178 this->
check(i, j, k, d);
179 this->
data_[i][j][k][d] =
static_cast<T
>(
value);
InMemoryCube of fixed depth 1.
virtual Real getT0(Size i, Size d) const override
Get a T0 value from the cube.
virtual void setT0(Real value, Size i, Size d) override
Set a value in the cube.
Size depth() const override
Fixed depth.
Real get(Size i, Size j, Size k, Size d) const override
Get a value from the cube.
InMemoryCube1(const Date &asof, const std::set< std::string > &ids, const vector< Date > &dates, Size samples, const T &t=T())
ctor
void set(Real value, Size i, Size j, Size k, Size d) override
Set a value in the cube.
InMemoryCube stores the cube in memory using nested STL vectors.
Size numDates() const override
const std::map< std::string, Size > & idsAndIndexes() const override
Return a map of all ids and their position in the cube.
Size numIds() const override
Return the length of each dimension.
vector< vector< vector< T > > > data_
void check(Size i, Size j, Size k, Size d) const
virtual Size samples() const override
const std::vector< QuantLib::Date > & dates() const override
Get the vector of dates for this cube.
InMemoryCubeBase()
default constructor
QuantLib::Date asof() const override
Return the asof date (T0 date)
std::map< std::string, Size > idIdx_
vector< QuantLib::Date > dates_
InMemoryCubeBase(const Date &asof, const std::set< std::string > &ids, const vector< Date > &dates, Size samples, const T &t=T())
default ctor
InMemoryCube of variable depth.
InMemoryCubeN(const Date &asof, const std::set< std::string > &ids, const vector< Date > &dates, Size samples, Size depth, const T &t=T())
ctor
virtual Real getT0(Size i, Size d) const override
Get a T0 value from the cube.
virtual void setT0(Real value, Size i, Size d) override
Set a value in the cube.
Size depth() const override
Depth.
Real get(Size i, Size j, Size k, Size d) const override
Get a value from the cube.
void set(Real value, Size i, Size j, Size k, Size d) override
Set a value in the cube.
NPV Cube class stores both future and current NPV values.
virtual Size depth() const =0
const std::set< std::string > ids() const
Get a set of all ids in the cube.
SafeStack< ValueType > value
Size size(const ValueType &v)