Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
multipathgeneratorbase.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file multipathgeneratorbase.hpp
20 \brief base class for multi path generators
21 \ingroup methods
22*/
23
24#pragma once
25
26#include <ql/math/randomnumbers/rngtraits.hpp>
27#include <ql/methods/montecarlo/brownianbridge.hpp>
28#include <ql/methods/montecarlo/multipath.hpp>
29#include <ql/methods/montecarlo/multipathgenerator.hpp>
30#include <ql/methods/montecarlo/sample.hpp>
31#include <ql/models/marketmodels/browniangenerators/sobolbrowniangenerator.hpp>
32#include <ql/stochasticprocess.hpp>
33
34namespace QuantExt {
35using namespace QuantLib;
36
44};
45
46//! Multi Path Generator Base
47/*! \ingroup methods
48 */
50public:
52 virtual const Sample<MultiPath>& next() const = 0;
53 virtual void reset() = 0;
54};
55
56//! Instantiation of MultiPathGenerator with standard PseudoRandom traits
57/*! \ingroup methods
58 */
60public:
61 MultiPathGeneratorMersenneTwister(const QuantLib::ext::shared_ptr<StochasticProcess>&, const TimeGrid&, BigNatural seed = 0,
62 bool antitheticSampling = false);
63 const Sample<MultiPath>& next() const override;
64 void reset() override;
65
66private:
67 const QuantLib::ext::shared_ptr<StochasticProcess> process_;
68 TimeGrid grid_;
69 BigNatural seed_;
70
71 QuantLib::ext::shared_ptr<MultiPathGenerator<PseudoRandom::rsg_type>> pg_;
72 QuantLib::ext::shared_ptr<PathGenerator<PseudoRandom::rsg_type>> pg1D_;
74 mutable bool antitheticVariate_;
75 mutable Sample<MultiPath> next_;
76};
77
79public:
80 MultiPathGeneratorMersenneTwisterAntithetic(const QuantLib::ext::shared_ptr<StochasticProcess>& p, const TimeGrid& grid,
81 BigNatural seed = 0)
82 : MultiPathGeneratorMersenneTwister(p, grid, seed, true) {}
83};
84
85//! Instantiation of MultiPathGenerator with standard LowDiscrepancy traits
86/*! no Brownian bridge provided, use MultiPathGeneratorSobolBrownianBridge for this,
87for the use of the seed, see ql/math/randomnumbers/sobolrsg.cpp
88
89 \ingroup methods
90*/
92public:
93 MultiPathGeneratorSobol(const QuantLib::ext::shared_ptr<StochasticProcess>&, const TimeGrid&, BigNatural seed = 0,
94 SobolRsg::DirectionIntegers directionIntegers = SobolRsg::JoeKuoD7);
95 const Sample<MultiPath>& next() const override;
96 void reset() override;
97
98private:
99 const QuantLib::ext::shared_ptr<StochasticProcess> process_;
100 TimeGrid grid_;
101 BigNatural seed_;
102 SobolRsg::DirectionIntegers directionIntegers_;
103
104 QuantLib::ext::shared_ptr<MultiPathGenerator<LowDiscrepancy::rsg_type>> pg_;
105 QuantLib::ext::shared_ptr<PathGenerator<LowDiscrepancy::rsg_type>> pg1D_;
106 mutable Sample<MultiPath> next_;
107};
108
109//! Instantiation of MultiPathGenerator with standard LowDiscrepancy traits
110/*! no Brownian bridge provided, use MultiPathGeneratorSobolBrownianBridge for this,
111for the use of the seed, see ql/math/randomnumbers/sobolrsg.cpp
112
113 \ingroup methods
114*/
116public:
117 MultiPathGeneratorBurley2020Sobol(const QuantLib::ext::shared_ptr<StochasticProcess>&, const TimeGrid&,
118 BigNatural seed = 42,
119 SobolRsg::DirectionIntegers directionIntegers = SobolRsg::JoeKuoD7,
120 BigNatural scrambleSeed = 43);
121 const Sample<MultiPath>& next() const override;
122 void reset() override;
123
124private:
125 const QuantLib::ext::shared_ptr<StochasticProcess> process_;
126 TimeGrid grid_;
127 BigNatural seed_;
128 SobolRsg::DirectionIntegers directionIntegers_;
129 BigNatural scrambleSeed_;
130
131 QuantLib::ext::shared_ptr<MultiPathGenerator<InverseCumulativeRsg<Burley2020SobolRsg, InverseCumulativeNormal>>> pg_;
132 QuantLib::ext::shared_ptr<PathGenerator<InverseCumulativeRsg<Burley2020SobolRsg, InverseCumulativeNormal>>> pg1D_;
133 mutable Sample<MultiPath> next_;
134};
135
136//! Base class for instantiations using brownian generators from models/marketmodels/browniangenerators
137/*! \ingroup methods
138 */
140public:
141 MultiPathGeneratorSobolBrownianBridgeBase(const QuantLib::ext::shared_ptr<StochasticProcess>&, const TimeGrid&,
142 SobolBrownianGenerator::Ordering ordering = SobolBrownianGenerator::Steps,
143 BigNatural seed = 0,
144 SobolRsg::DirectionIntegers directionIntegers = SobolRsg::JoeKuoD7);
145 const Sample<MultiPath>& next() const override;
146
147protected:
148 const QuantLib::ext::shared_ptr<StochasticProcess> process_;
149 TimeGrid grid_;
150 SobolBrownianGenerator::Ordering ordering_;
151 BigNatural seed_;
152 SobolRsg::DirectionIntegers directionIntegers_;
153 QuantLib::ext::shared_ptr<SobolBrownianGeneratorBase> gen_;
154 mutable Sample<MultiPath> next_;
155 QuantLib::ext::shared_ptr<StochasticProcess1D> process1D_;
156};
157
158//! Instantiation using SobolBrownianGenerator from models/marketmodels/browniangenerators
159/*! \ingroup methods
160 */
162public:
163 MultiPathGeneratorSobolBrownianBridge(const QuantLib::ext::shared_ptr<StochasticProcess>&, const TimeGrid&,
164 SobolBrownianGenerator::Ordering ordering = SobolBrownianGenerator::Steps,
165 BigNatural seed = 0,
166 SobolRsg::DirectionIntegers directionIntegers = SobolRsg::JoeKuoD7);
167 void reset() override final;
168};
169
170//! Instantiation using Burley2020SobolBrownianGenerator from models/marketmodels/browniangenerators
171/*! \ingroup methods
172 */
174public:
176 const QuantLib::ext::shared_ptr<StochasticProcess>&, const TimeGrid&,
177 SobolBrownianGenerator::Ordering ordering = SobolBrownianGenerator::Steps, BigNatural seed = 42,
178 SobolRsg::DirectionIntegers directionIntegers = SobolRsg::JoeKuoD7, BigNatural scrambleSeed = 43);
179 void reset() override final;
180
181protected:
182 BigNatural scrambleSeed_;
183};
184
185//! Make function for path generators
186QuantLib::ext::shared_ptr<MultiPathGeneratorBase>
187makeMultiPathGenerator(const SequenceType s, const QuantLib::ext::shared_ptr<StochasticProcess>& process,
188 const TimeGrid& timeGrid, const BigNatural seed,
189 const SobolBrownianGenerator::Ordering ordering = SobolBrownianGenerator::Steps,
190 const SobolRsg::DirectionIntegers directionIntegers = SobolRsg::JoeKuoD7);
191
192//! Output function
193std::ostream& operator<<(std::ostream& out, const SequenceType s);
194
195} // namespace QuantExt
virtual const Sample< MultiPath > & next() const =0
Instantiation using Burley2020SobolBrownianGenerator from models/marketmodels/browniangenerators.
Instantiation of MultiPathGenerator with standard LowDiscrepancy traits.
const QuantLib::ext::shared_ptr< StochasticProcess > process_
QuantLib::ext::shared_ptr< MultiPathGenerator< InverseCumulativeRsg< Burley2020SobolRsg, InverseCumulativeNormal > > > pg_
QuantLib::ext::shared_ptr< PathGenerator< InverseCumulativeRsg< Burley2020SobolRsg, InverseCumulativeNormal > > > pg1D_
const Sample< MultiPath > & next() const override
MultiPathGeneratorMersenneTwisterAntithetic(const QuantLib::ext::shared_ptr< StochasticProcess > &p, const TimeGrid &grid, BigNatural seed=0)
Instantiation of MultiPathGenerator with standard PseudoRandom traits.
const QuantLib::ext::shared_ptr< StochasticProcess > process_
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_
QuantLib::ext::shared_ptr< StochasticProcess1D > process1D_
const Sample< MultiPath > & next() const override
QuantLib::ext::shared_ptr< SobolBrownianGeneratorBase > gen_
Instantiation using SobolBrownianGenerator from models/marketmodels/browniangenerators.
Instantiation of MultiPathGenerator with standard LowDiscrepancy traits.
const QuantLib::ext::shared_ptr< StochasticProcess > process_
SobolRsg::DirectionIntegers directionIntegers_
QuantLib::ext::shared_ptr< MultiPathGenerator< LowDiscrepancy::rsg_type > > pg_
const Sample< MultiPath > & next() const override
QuantLib::ext::shared_ptr< PathGenerator< LowDiscrepancy::rsg_type > > pg1D_
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)