21#include <boost/make_shared.hpp>
28 const QuantLib::ext::shared_ptr<StochasticProcess>& process,
const TimeGrid& grid, BigNatural seed,
bool antitheticSampling)
29 : process_(process), grid_(grid), seed_(seed), antitheticSampling_(antitheticSampling), antitheticVariate_(true),
30 next_(MultiPath(process->size(), grid), 1.0) {
35 PseudoRandom::rsg_type rsg = PseudoRandom::make_sequence_generator(
process_->factors() * (
grid_.size() - 1),
seed_);
36 if (
auto tmp = QuantLib::ext::dynamic_pointer_cast<StochasticProcess1D>(
process_)) {
37 pg1D_ = QuantLib::ext::make_shared<PathGenerator<PseudoRandom::rsg_type>>(tmp,
grid_, rsg,
false);
39 pg_ = QuantLib::ext::make_shared<MultiPathGenerator<PseudoRandom::rsg_type>>(
process_,
grid_, rsg,
false);
64 const TimeGrid& grid, BigNatural seed,
65 SobolRsg::DirectionIntegers directionIntegers)
66 : process_(process), grid_(grid), seed_(seed), directionIntegers_(directionIntegers),
67 next_(MultiPath(process->size(), grid), 1.0) {
72 if (
auto tmp = QuantLib::ext::dynamic_pointer_cast<StochasticProcess1D>(
process_)) {
73 pg1D_ = QuantLib::ext::make_shared<PathGenerator<InverseCumulativeRsg<SobolRsg, InverseCumulativeNormal>>>(
75 InverseCumulativeRsg<SobolRsg, InverseCumulativeNormal>(
80 pg_ = QuantLib::ext::make_shared<MultiPathGenerator<InverseCumulativeRsg<SobolRsg, InverseCumulativeNormal>>>(
82 InverseCumulativeRsg<SobolRsg, InverseCumulativeNormal>(
97 const TimeGrid& grid, BigNatural seed,
98 SobolRsg::DirectionIntegers directionIntegers,
99 BigNatural scrambleSeed)
100 : process_(process), grid_(grid), seed_(seed), directionIntegers_(directionIntegers), scrambleSeed_(scrambleSeed),
101 next_(MultiPath(process->size(), grid), 1.0) {
106 if (
auto tmp = QuantLib::ext::dynamic_pointer_cast<StochasticProcess1D>(
process_)) {
107 pg1D_ = QuantLib::ext::make_shared<PathGenerator<InverseCumulativeRsg<Burley2020SobolRsg, InverseCumulativeNormal>>>(
109 InverseCumulativeRsg<Burley2020SobolRsg, InverseCumulativeNormal>(
114 pg_ = QuantLib::ext::make_shared<MultiPathGenerator<InverseCumulativeRsg<Burley2020SobolRsg, InverseCumulativeNormal>>>(
116 InverseCumulativeRsg<Burley2020SobolRsg, InverseCumulativeNormal>(Burley2020SobolRsg(
131 const QuantLib::ext::shared_ptr<StochasticProcess>& process,
const TimeGrid& grid,
132 SobolBrownianGenerator::Ordering ordering, BigNatural seed, SobolRsg::DirectionIntegers directionIntegers)
133 : process_(process), grid_(grid), ordering_(ordering), seed_(seed), directionIntegers_(directionIntegers),
134 next_(MultiPath(process->size(), grid), 1.0) {
135 process1D_ = QuantLib::ext::dynamic_pointer_cast<StochasticProcess1D>(process);
139 Array asset =
process_->initialValues();
140 MultiPath& path =
next_.value;
141 for (Size j = 0; j < asset.size(); ++j) {
142 path[j].front() = asset[j];
145 std::vector<Real> output(
process_->factors());
146 for (Size i = 1; i <
grid_.size(); ++i) {
147 Real t =
grid_[i - 1];
148 Real dt =
grid_.dt(i - 1);
149 gen_->nextStep(output);
151 path[0][i] = asset[0] =
process1D_->evolve(t, asset[0], dt, output[0]);
153 Array tmp(output.begin(), output.end());
154 asset =
process_->evolve(t, asset, dt, tmp);
155 for (Size j = 0; j < asset.size(); ++j) {
156 path[j][i] = asset[j];
164 const QuantLib::ext::shared_ptr<StochasticProcess>& process,
const TimeGrid& grid,
165 SobolBrownianGenerator::Ordering ordering, BigNatural seed, SobolRsg::DirectionIntegers directionIntegers)
176 const QuantLib::ext::shared_ptr<StochasticProcess>& process,
const TimeGrid& grid,
177 Burley2020SobolBrownianGenerator::Ordering ordering, BigNatural seed, SobolRsg::DirectionIntegers directionIntegers,
178 BigNatural scrambleSeed)
180 scrambleSeed_(scrambleSeed) {
189QuantLib::ext::shared_ptr<MultiPathGeneratorBase>
191 const TimeGrid& timeGrid,
const BigNatural seed,
const SobolBrownianGenerator::Ordering ordering,
192 const SobolRsg::DirectionIntegers directionIntegers) {
195 return QuantLib::ext::make_shared<QuantExt::MultiPathGeneratorMersenneTwister>(process, timeGrid, seed,
false);
197 return QuantLib::ext::make_shared<QuantExt::MultiPathGeneratorMersenneTwister>(process, timeGrid, seed,
true);
199 return QuantLib::ext::make_shared<QuantExt::MultiPathGeneratorSobol>(process, timeGrid, seed, directionIntegers);
201 return QuantLib::ext::make_shared<QuantExt::MultiPathGeneratorBurley2020Sobol>(
202 process, timeGrid, seed, directionIntegers, seed == 0 ? 0 : seed + 1);
204 return QuantLib::ext::make_shared<QuantExt::MultiPathGeneratorSobolBrownianBridge>(process, timeGrid, ordering, seed,
207 return QuantLib::ext::make_shared<QuantExt::MultiPathGeneratorBurley2020SobolBrownianBridge>(
208 process, timeGrid, ordering, seed, directionIntegers, seed == 0 ? 0 : seed + 1);
210 QL_FAIL(
"Unknown sequence type");
217 return out <<
"MersenneTwister";
219 return out <<
"MersenneTwisterAntithetic";
221 return out <<
"Sobol";
223 return out <<
"Burley2020Sobol";
225 return out <<
"SobolBrownianBridge";
227 return out <<
"Burley2020SobolBrownianBridge";
229 return out <<
"Unknown sequence type";
MultiPathGeneratorBurley2020SobolBrownianBridge(const QuantLib::ext::shared_ptr< StochasticProcess > &, const TimeGrid &, SobolBrownianGenerator::Ordering ordering=SobolBrownianGenerator::Steps, BigNatural seed=42, SobolRsg::DirectionIntegers directionIntegers=SobolRsg::JoeKuoD7, BigNatural scrambleSeed=43)
void reset() override final
const QuantLib::ext::shared_ptr< StochasticProcess > process_
Sample< MultiPath > next_
SobolRsg::DirectionIntegers directionIntegers_
MultiPathGeneratorBurley2020Sobol(const QuantLib::ext::shared_ptr< StochasticProcess > &, const TimeGrid &, BigNatural seed=42, SobolRsg::DirectionIntegers directionIntegers=SobolRsg::JoeKuoD7, BigNatural scrambleSeed=43)
QuantLib::ext::shared_ptr< MultiPathGenerator< InverseCumulativeRsg< Burley2020SobolRsg, InverseCumulativeNormal > > > pg_
QuantLib::ext::shared_ptr< PathGenerator< InverseCumulativeRsg< Burley2020SobolRsg, InverseCumulativeNormal > > > pg1D_
const Sample< MultiPath > & next() const override
const QuantLib::ext::shared_ptr< StochasticProcess > process_
Sample< MultiPath > next_
MultiPathGeneratorMersenneTwister(const QuantLib::ext::shared_ptr< StochasticProcess > &, const TimeGrid &, BigNatural seed=0, bool antitheticSampling=false)
QuantLib::ext::shared_ptr< PathGenerator< PseudoRandom::rsg_type > > pg1D_
QuantLib::ext::shared_ptr< MultiPathGenerator< PseudoRandom::rsg_type > > pg_
const Sample< MultiPath > & next() const override
Base class for instantiations using brownian generators from models/marketmodels/browniangenerators.
const QuantLib::ext::shared_ptr< StochasticProcess > process_
Sample< MultiPath > next_
QuantLib::ext::shared_ptr< StochasticProcess1D > process1D_
SobolBrownianGenerator::Ordering ordering_
SobolRsg::DirectionIntegers directionIntegers_
MultiPathGeneratorSobolBrownianBridgeBase(const QuantLib::ext::shared_ptr< StochasticProcess > &, const TimeGrid &, SobolBrownianGenerator::Ordering ordering=SobolBrownianGenerator::Steps, BigNatural seed=0, SobolRsg::DirectionIntegers directionIntegers=SobolRsg::JoeKuoD7)
const Sample< MultiPath > & next() const override
QuantLib::ext::shared_ptr< SobolBrownianGeneratorBase > gen_
void reset() override final
MultiPathGeneratorSobolBrownianBridge(const QuantLib::ext::shared_ptr< StochasticProcess > &, const TimeGrid &, SobolBrownianGenerator::Ordering ordering=SobolBrownianGenerator::Steps, BigNatural seed=0, SobolRsg::DirectionIntegers directionIntegers=SobolRsg::JoeKuoD7)
const QuantLib::ext::shared_ptr< StochasticProcess > process_
Sample< MultiPath > next_
SobolRsg::DirectionIntegers directionIntegers_
MultiPathGeneratorSobol(const QuantLib::ext::shared_ptr< StochasticProcess > &, const TimeGrid &, BigNatural seed=0, SobolRsg::DirectionIntegers directionIntegers=SobolRsg::JoeKuoD7)
QuantLib::ext::shared_ptr< MultiPathGenerator< LowDiscrepancy::rsg_type > > pg_
const Sample< MultiPath > & next() const override
QuantLib::ext::shared_ptr< PathGenerator< LowDiscrepancy::rsg_type > > pg1D_
base class for multi path generators
@ MersenneTwisterAntithetic
@ Burley2020SobolBrownianBridge
QuantLib::ext::shared_ptr< MultiPathGeneratorBase > makeMultiPathGenerator(const SequenceType s, const QuantLib::ext::shared_ptr< StochasticProcess > &process, const TimeGrid &timeGrid, const BigNatural seed, const SobolBrownianGenerator::Ordering ordering, const SobolRsg::DirectionIntegers directionIntegers)
Make function for path generators.
std::ostream & operator<<(std::ostream &out, EquityReturnType t)