Skip to content

Commit d776550

Browse files
committed
QPR-12140 add burley generator
1 parent db837dd commit d776550

2 files changed

Lines changed: 63 additions & 9 deletions

File tree

ql/math/randomnumbers/sobolbrownianbridgersg.cpp

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
#include <ql/math/randomnumbers/sobolbrownianbridgersg.hpp>
2626

2727
namespace QuantLib {
28+
29+
namespace {
30+
void nextSequence(const SobolBrownianGeneratorBaseG& gen, std::vector<Real>& seq) {
31+
gen.nextPath();
32+
std::vector<Real> output(gen.numberOfFactors());
33+
for (Size i = 0; i < gen.numberOfSetps(); ++i) {
34+
gen.nextStep(output);
35+
std::copy(output.begin(), output.end(), seq.begin() + i * factors_);
36+
}
37+
}
38+
}
39+
2840
SobolBrownianBridgeRsg::SobolBrownianBridgeRsg(
2941
Size factors, Size steps,
3042
SobolBrownianGenerator::Ordering ordering,
@@ -37,14 +49,7 @@ namespace QuantLib {
3749

3850
const SobolBrownianBridgeRsg::sample_type&
3951
SobolBrownianBridgeRsg::nextSequence() const {
40-
gen_.nextPath();
41-
std::vector<Real> output(factors_);
42-
for (Size i=0; i < steps_; ++i) {
43-
gen_.nextStep(output);
44-
std::copy(output.begin(), output.end(),
45-
seq_.value.begin()+i*factors_);
46-
}
47-
52+
nextSequence(gen_, seq_);
4853
return seq_;
4954
}
5055

@@ -56,4 +61,31 @@ namespace QuantLib {
5661
Size SobolBrownianBridgeRsg::dimension() const {
5762
return dim_;
5863
}
64+
65+
Burley2020SobolBrownianBridgeRsg::Burley2020SobolBrownianBridgeRsg(
66+
Size factors, Size steps,
67+
SobolBrownianGenerator::Ordering ordering,
68+
unsigned long seed,
69+
SobolRsg::DirectionIntegers directionIntegers,
70+
unsigned long scrambleSeed)
71+
: factors_(factors), steps_(steps), dim_(factors*steps),
72+
seq_(sample_type::value_type(factors*steps), 1.0),
73+
gen_(factors, steps, ordering, seed, directionIntegers, scrambleSeed) {
74+
}
75+
76+
const Burley2020SobolBrownianBridgeRsg::sample_type&
77+
Burley2020SobolBrownianBridgeRsg::nextSequence() const {
78+
nextSequence(gen_, seq_);
79+
return seq_;
80+
}
81+
82+
const Burley2020SobolBrownianBridgeRsg::sample_type&
83+
Burley2020SobolBrownianBridgeRsg::lastSequence() const {
84+
return seq_;
85+
}
86+
87+
Size Burley2020SobolBrownianBridgeRsg::dimension() const {
88+
return dim_;
89+
}
90+
5991
}

ql/math/randomnumbers/sobolbrownianbridgersg.hpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,28 @@ namespace QuantLib {
4949
mutable sample_type seq_;
5050
mutable SobolBrownianGenerator gen_;
5151
};
52-
}
52+
53+
class Burley2020SobolBrownianBridgeRsg {
54+
public:
55+
typedef Sample<std::vector<Real> > sample_type;
56+
57+
Burley2020SobolBrownianBridgeRsg(
58+
Size factors,
59+
Size steps,
60+
SobolBrownianGenerator::Ordering ordering = SobolBrownianGenerator::Diagonal,
61+
unsigned long seed = 42,
62+
SobolRsg::DirectionIntegers directionIntegers = SobolRsg::JoeKuoD7,
63+
unsigned long scrambleSeed = 43);
64+
65+
const sample_type& nextSequence() const;
66+
const sample_type& lastSequence() const;
67+
Size dimension() const;
68+
69+
private:
70+
const Size factors_, steps_, dim_;
71+
mutable sample_type seq_;
72+
mutable Burley2020SobolBrownianGenerator gen_;
73+
};
74+
}}
5375

5476
#endif

0 commit comments

Comments
 (0)