21#include <boost/make_shared.hpp>
28 : dimension_(dimension), timeSteps_(timeSteps) {}
33 Sample<std::vector<Array>> result(std::vector<Array>(
timeSteps_, Array(
dimension_)), sequence.weight);
37 std::copy(sequence.value.begin() + offset, sequence.value.begin() + offset +
dimension_,
38 result.value[i].begin());
47 bool antitheticSampling)
49 antitheticVariate_(true) {
54 rsg_ = QuantLib::ext::make_shared<
55 InverseCumulativeRsg<RandomSequenceGenerator<MersenneTwisterUniformRng>, InverseCumulativeNormal>>(
57 InverseCumulativeNormal());
65 auto tmp =
rsg_->lastSequence();
66 std::transform(tmp.value.begin(), tmp.value.end(), tmp.value.begin(), std::negate<Real>());
69 return rsg_->nextSequence();
72 return rsg_->nextSequence();
77 SobolRsg::DirectionIntegers directionIntegers)
83 rsg_ = QuantLib::ext::make_shared<InverseCumulativeRsg<SobolRsg, InverseCumulativeNormal>>(
90 const Size dimension,
const Size timeSteps, BigNatural seed, SobolRsg::DirectionIntegers directionIntegers,
91 BigNatural scrambleSeed)
93 scrambleSeed_(scrambleSeed) {
98 rsg_ = QuantLib::ext::make_shared<InverseCumulativeRsg<Burley2020SobolRsg, InverseCumulativeNormal>>(
103 return rsg_->nextSequence();
107 const Size dimension,
const Size timeSteps, SobolBrownianGenerator::Ordering ordering, BigNatural seed,
108 SobolRsg::DirectionIntegers directionIntegers)
110 directionIntegers_(directionIntegers) {}
114 return Sample<std::vector<Real>>(std::vector<Real>(), 0.0);
118 Real weight =
gen_->nextPath();
123 std::copy(tmp.begin(), tmp.end(), output[i].begin());
125 return Sample<std::vector<Array>>(output, weight);
129 const Size dimension,
const Size timeSteps, SobolBrownianGenerator::Ordering ordering, BigNatural seed,
130 SobolRsg::DirectionIntegers directionIntegers)
140 const Size dimension,
const Size timeSteps, SobolBrownianGenerator::Ordering ordering, BigNatural seed,
141 SobolRsg::DirectionIntegers directionIntegers, BigNatural scrambleSeed)
143 scrambleSeed_(scrambleSeed) {
152QuantLib::ext::shared_ptr<MultiPathVariateGeneratorBase>
154 const SobolBrownianGenerator::Ordering ordering,
155 const SobolRsg::DirectionIntegers directionIntegers) {
158 return QuantLib::ext::make_shared<QuantExt::MultiPathVariateGeneratorMersenneTwister>(dimension, timeSteps, seed,
161 return QuantLib::ext::make_shared<QuantExt::MultiPathVariateGeneratorMersenneTwister>(dimension, timeSteps, seed,
true);
163 return QuantLib::ext::make_shared<QuantExt::MultiPathVariateGeneratorSobol>(dimension, timeSteps, seed,
166 return QuantLib::ext::make_shared<QuantExt::MultiPathVariateGeneratorBurley2020Sobol>(dimension, timeSteps, seed,
167 directionIntegers, seed + 1);
169 return QuantLib::ext::make_shared<QuantExt::MultiPathVariateGeneratorSobolBrownianBridge>(
170 dimension, timeSteps, ordering, seed, directionIntegers);
172 return QuantLib::ext::make_shared<QuantExt::MultiPathVariateGeneratorBurley2020SobolBrownianBridge>(
173 dimension, timeSteps, ordering, seed, directionIntegers, seed + 1);
175 QL_FAIL(
"Unknown sequence type");
virtual Sample< std::vector< Real > > nextSequence() const =0
virtual Sample< std::vector< Array > > next() const
MultiPathVariateGeneratorBase(const Size dimension, const Size timeSteps)
MultiPathVariateGeneratorBurley2020SobolBrownianBridge(const Size dimension, const Size timeSteps, SobolBrownianGenerator::Ordering ordering=SobolBrownianGenerator::Steps, BigNatural seed=42, SobolRsg::DirectionIntegers directionIntegers=SobolRsg::JoeKuoD7, BigNatural scrambleSeed=43)
void reset() override final
QuantLib::ext::shared_ptr< InverseCumulativeRsg< Burley2020SobolRsg, InverseCumulativeNormal > > rsg_
SobolRsg::DirectionIntegers directionIntegers_
Sample< std::vector< Real > > nextSequence() const override
MultiPathVariateGeneratorBurley2020Sobol(const Size dimension, const Size timeSteps, BigNatural seed=42, SobolRsg::DirectionIntegers directionIntegers=SobolRsg::JoeKuoD7, BigNatural scrambleSeed=43)
MultiPathVariateGeneratorMersenneTwister(const Size dimension, const Size timeSteps, BigNatural seed=0, bool antitheticSampling=false)
Sample< std::vector< Real > > nextSequence() const override
QuantLib::ext::shared_ptr< PseudoRandom::rsg_type > rsg_
MultiPathVariateGeneratorSobolBrownianBridgeBase(const Size dimension, const Size timeSteps, SobolBrownianGenerator::Ordering ordering=SobolBrownianGenerator::Steps, BigNatural seed=0, SobolRsg::DirectionIntegers directionIntegers=SobolRsg::JoeKuoD7)
SobolBrownianGenerator::Ordering ordering_
SobolRsg::DirectionIntegers directionIntegers_
Sample< std::vector< Array > > next() const override
Sample< std::vector< Real > > nextSequence() const override
QuantLib::ext::shared_ptr< SobolBrownianGeneratorBase > gen_
void reset() override final
MultiPathVariateGeneratorSobolBrownianBridge(const Size dimension, const Size timeSteps, SobolBrownianGenerator::Ordering ordering=SobolBrownianGenerator::Steps, BigNatural seed=42, SobolRsg::DirectionIntegers directionIntegers=SobolRsg::JoeKuoD7)
SobolRsg::DirectionIntegers directionIntegers_
MultiPathVariateGeneratorSobol(const Size dimension, const Size timeSteps, BigNatural seed=0, SobolRsg::DirectionIntegers directionIntegers=SobolRsg::JoeKuoD7)
Sample< std::vector< Real > > nextSequence() const override
QuantLib::ext::shared_ptr< LowDiscrepancy::rsg_type > rsg_
multi path generators returning the generating N(0,1) variates, this is very much in parallel to the ...
@ MersenneTwisterAntithetic
@ Burley2020SobolBrownianBridge
QuantLib::ext::shared_ptr< MultiPathVariateGeneratorBase > makeMultiPathVariateGenerator(const SequenceType s, const Size dimension, const Size timeSteps, const BigNatural seed, const SobolBrownianGenerator::Ordering ordering, const SobolRsg::DirectionIntegers directionIntegers)