21#include <ql/errors.hpp>
22#include <ql/math/array.hpp>
23#include <ql/math/comparison.hpp>
24#include <ql/math/matrix.hpp>
25#include <ql/methods/montecarlo/lsmbasissystem.hpp>
26#include <ql/patterns/singleton.hpp>
27#include <ql/types.hpp>
29#include <ql/functional.hpp>
30#include <boost/timer/timer.hpp>
32#include <initializer_list>
75 explicit Filter(
const Size n,
const bool value =
false);
78 void set(
const Size i,
const bool v);
90 bool at(
const Size i)
const;
115 QL_REQUIRE(i <
n_,
"Filter::set(" << i <<
"): out of bounds, size is " <<
n_);
133 QL_REQUIRE(
n_ > 0,
"Filter::at(" << i <<
"): dimension is zero");
136 QL_REQUIRE(i <
n_,
"Filter::at(" << i <<
"): out of bounds, size is " <<
n_);
161 explicit RandomVariable(
const Size n,
const Real value = 0.0,
const Real
time = Null<Real>());
162 explicit RandomVariable(
const Filter& f,
const Real valueTrue = 1.0,
const Real valueFalse = 0.0,
163 const Real
time = Null<Real>());
172 void set(
const Size i,
const Real v);
175 void setAll(
const Real v);
185 Real
at(
const Size i)
const;
274 const Real eps = 0.0);
276 const Real eps = 0.0);
294Matrix
pcaCoordinateTransform(
const std::vector<const RandomVariable*>& regressor,
const Real varianceCutoff = 1E-5);
298 const Matrix& transform);
301std::vector<const RandomVariable*>
vec2vecptr(
const std::vector<RandomVariable>& values);
306 RandomVariable r, std::vector<const RandomVariable*> regressor,
307 const std::vector<std::function<RandomVariable(
const std::vector<const RandomVariable*>&)>>& basisFn,
309 const std::string& debugLabel = std::string());
313 const std::vector<const RandomVariable*>& regressor,
314 const std::vector<std::function<RandomVariable(
const std::vector<const RandomVariable*>&)>>& basisFn,
315 const Array& coefficients);
319 const RandomVariable& r,
const std::vector<const RandomVariable*>& regressor,
320 const std::vector<std::function<RandomVariable(
const std::vector<const RandomVariable*>&)>>& basisFn,
324RandomVariable
expectation(
const RandomVariable& r);
327RandomVariable
variance(
const RandomVariable& r);
330RandomVariable
covariance(
const RandomVariable& r,
const RandomVariable& s);
333RandomVariable
black(
const RandomVariable& omega,
const RandomVariable& t,
const RandomVariable& strike,
334 const RandomVariable& forward,
const RandomVariable& impliedVol);
341 return x.
deterministic() && QuantLib::close_enough(x[0], 0.0);
347 QL_REQUIRE(i <
n_,
"RandomVariable::set(" << i <<
"): out of bounds, size is " <<
n_);
366 QL_REQUIRE(
n_ > 0,
"RandomVariable::at(" << i <<
"): dimension is zero");
369 QL_REQUIRE(i <
n_,
"RandomVariable::at(" << i <<
"): out of bounds, size is " <<
n_);
377std::vector<std::function<
RandomVariable(
const std::vector<const RandomVariable*>&)>>
379 Size basisSystemSizeBound = Null<Size>());
BucketedDistribution operator+(const BucketedDistribution &lhs, const BucketedDistribution &rhs)
Sum probabilities in two bucketed distributions with equal buckets.
std::vector< std::function< RandomVariable(const std::vector< const RandomVariable * > &)> > multiPathBasisSystem(Size dim, Size order, QuantLib::LsmBasisSystem::PolynomialType type, Size basisSystemSizeBound)
bool operator!=(const Filter &a, const Filter &b)
RandomVariable sqrt(RandomVariable x)
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
RandomVariable variance(const RandomVariable &r)
RandomVariable cos(RandomVariable x)
CompiledFormula exp(CompiledFormula x)
RandomVariable sin(RandomVariable x)
RandomVariableRegressionMethod
bool close_enough_all(const RandomVariable &x, const RandomVariable &y)
Filter operator!(Filter x)
bool isDeterministicAndZero(const ExternalRandomVariable &x)
RandomVariable conditionalResult(const Filter &f, RandomVariable x, const RandomVariable &y)
CompiledFormula min(CompiledFormula x, const CompiledFormula &y)
RandomVariable indicatorDerivative(const RandomVariable &x, const double eps)
RandomVariable black(const RandomVariable &omega, const RandomVariable &t, const RandomVariable &strike, const RandomVariable &forward, const RandomVariable &impliedVol)
RandomVariable covariance(const RandomVariable &r, const RandomVariable &s)
bool operator==(const Dividend &d1, const Dividend &d2)
Compare dividends.
CompiledFormula pow(CompiledFormula x, const CompiledFormula &y)
std::vector< const RandomVariable * > vec2vecptr(const std::vector< RandomVariable > &values)
RandomVariable expectation(const RandomVariable &r)
RandomVariable normalCdf(RandomVariable x)
RandomVariable conditionalExpectation(const std::vector< const RandomVariable * > ®ressor, const std::vector< std::function< RandomVariable(const std::vector< const RandomVariable * > &)> > &basisFn, const Array &coefficients)
Filter operator&&(Filter x, const Filter &y)
RandomVariable applyInverseFilter(RandomVariable x, const Filter &f)
RandomVariable indicatorGeq(RandomVariable x, const RandomVariable &y, const Real trueVal, const Real falseVal, const Real eps)
CompiledFormula max(CompiledFormula x, const CompiledFormula &y)
CompiledFormula abs(CompiledFormula x)
RandomVariable applyFilter(RandomVariable x, const Filter &f)
RandomVariable indicatorEq(RandomVariable x, const RandomVariable &y, const Real trueVal, const Real falseVal)
RandomVariable normalPdf(RandomVariable x)
Filter equal(Filter x, const Filter &y)
Filter operator||(Filter x, const Filter &y)
Matrix pcaCoordinateTransform(const std::vector< const RandomVariable * > ®ressor, const Real varianceCutoff)
CompiledFormula log(CompiledFormula x)
void checkTimeConsistency(const RandomVariable &x, const RandomVariable &y)
CompiledFormula operator-(CompiledFormula x, const CompiledFormula &y)
CompiledFormula operator/(CompiledFormula x, const CompiledFormula &y)
Array regressionCoefficients(RandomVariable r, std::vector< const RandomVariable * > regressor, const std::vector< std::function< RandomVariable(const std::vector< const RandomVariable * > &)> > &basisFn, const Filter &filter, const RandomVariableRegressionMethod regressionMethod, const std::string &debugLabel)
RandomVariable indicatorGt(RandomVariable x, const RandomVariable &y, const Real trueVal, const Real falseVal, const Real eps)
std::vector< RandomVariable > applyCoordinateTransform(const std::vector< const RandomVariable * > ®ressor, const Matrix &transform)
BucketedDistribution operator*(Real factor, const BucketedDistribution &rhs)
void set(const Size i, const bool v)
friend Filter operator&&(Filter, const Filter &)
friend Filter equal(Filter, const Filter &)
bool operator[](const Size i) const
friend Filter operator||(Filter, const Filter &)
bool deterministic() const
void setAll(const bool v)
void updateDeterministic()
friend Filter operator!(Filter)
friend bool operator==(const Filter &, const Filter &)
bool at(const Size i) const
Filter & operator=(const Filter &r)
void resetSize(const Size n)
friend bool close_enough_all(const RandomVariable &, const RandomVariable &)
static std::function< void(RandomVariable &)> deleter
friend RandomVariable sin(RandomVariable)
friend Filter operator<=(const RandomVariable &, const RandomVariable &)
RandomVariable(const std::vector< double > &data, const Real time=Null< Real >())
void copyToMatrixCol(QuantLib::Matrix &, const Size j) const
RandomVariable & operator+=(const RandomVariable &)
friend RandomVariable sqrt(RandomVariable)
friend RandomVariable min(RandomVariable, const RandomVariable &)
friend RandomVariable indicatorGt(RandomVariable, const RandomVariable &, const Real trueVal, const Real falseVal, const Real eps)
friend bool operator==(const RandomVariable &, const RandomVariable &)
friend Filter operator>=(const RandomVariable &, const RandomVariable &)
friend Filter operator<(const RandomVariable &, const RandomVariable &)
friend RandomVariable operator*(RandomVariable, const RandomVariable &)
void checkTimeConsistencyAndUpdate(const Real t)
friend RandomVariable normalCdf(RandomVariable)
Real at(const Size i) const
RandomVariable & operator=(const RandomVariable &r)
friend RandomVariable max(RandomVariable, const RandomVariable &)
friend RandomVariable operator/(RandomVariable, const RandomVariable &)
bool deterministic() const
void set(const Size i, const Real v)
void setTime(const Real time)
RandomVariable & operator-=(const RandomVariable &)
friend Filter operator>(const RandomVariable &, const RandomVariable &)
RandomVariable & operator*=(const RandomVariable &)
friend RandomVariable indicatorEq(RandomVariable, const RandomVariable &, const Real trueVal, const Real falseVal)
friend RandomVariable operator+(RandomVariable, const RandomVariable &)
friend RandomVariable pow(RandomVariable, const RandomVariable &)
void copyToArray(QuantLib::Array &array) const
friend RandomVariable operator-(RandomVariable, const RandomVariable &)
friend RandomVariable cos(RandomVariable)
friend RandomVariable exp(RandomVariable)
friend RandomVariable normalPdf(RandomVariable)
Real operator[](const Size i) const
friend RandomVariable conditionalResult(const Filter &, RandomVariable, const RandomVariable &)
friend RandomVariable indicatorGeq(RandomVariable, const RandomVariable &, const Real trueVal, const Real falseVal, const Real eps)
void updateDeterministic()
RandomVariable & operator/=(const RandomVariable &)
friend RandomVariable log(RandomVariable)
void setAll(const Real v)
friend RandomVariable applyInverseFilter(RandomVariable, const Filter &)
friend RandomVariable abs(RandomVariable)
friend Filter close_enough(const RandomVariable &, const RandomVariable &)
void resetSize(const Size n)
friend RandomVariable applyFilter(RandomVariable, const Filter &)
boost::timer::cpu_timer calc_timer
boost::timer::cpu_timer data_timer