Coverage Report

Created: 2025-08-05 06:45

/src/quantlib/ql/math/randomnumbers/sobolbrownianbridgersg.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2012 Klaus Spanderen
5
6
 This file is part of QuantLib, a free-software/open-source library
7
 for financial quantitative analysts and developers - http://quantlib.org/
8
9
 QuantLib is free software: you can redistribute it and/or modify it
10
 under the terms of the QuantLib license.  You should have received a
11
 copy of the license along with this program; if not, please email
12
 <quantlib-dev@lists.sf.net>. The license is also available online at
13
 <http://quantlib.org/license.shtml>.
14
15
 This program is distributed in the hope that it will be useful, but WITHOUT
16
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
 FOR A PARTICULAR PURPOSE.  See the license for more details.
18
*/
19
20
/*! \file brownianbridgersg.hpp
21
    \brief interface class to map the functionality of SobolBrownianGenerator
22
           to the "conventional" sequence generator interface
23
*/
24
25
#include <ql/math/randomnumbers/sobolbrownianbridgersg.hpp>
26
27
namespace QuantLib {
28
29
    namespace {
30
0
        void setNextSequence(SobolBrownianGeneratorBase& gen, std::vector<Real>& seq) {
31
0
            gen.nextPath();
32
0
            std::vector<Real> output(gen.numberOfFactors());
33
0
            for (Size i = 0; i < gen.numberOfSteps(); ++i) {
34
0
                gen.nextStep(output);
35
0
                std::copy(output.begin(), output.end(), seq.begin() + i * gen.numberOfFactors());
36
0
            }
37
0
        }
38
    }
39
40
    SobolBrownianBridgeRsg::SobolBrownianBridgeRsg(Size factors,
41
                                                   Size steps,
42
                                                   SobolBrownianGenerator::Ordering ordering,
43
                                                   unsigned long seed,
44
                                                   SobolRsg::DirectionIntegers directionIntegers)
45
0
    : seq_(sample_type::value_type(factors * steps), 1.0),
46
0
      gen_(factors, steps, ordering, seed, directionIntegers) {}
47
48
    const SobolBrownianBridgeRsg::sample_type&
49
0
    SobolBrownianBridgeRsg::nextSequence() const {
50
0
        setNextSequence(gen_, seq_.value);
51
0
        return seq_;
52
53
0
    }
54
55
    const SobolBrownianBridgeRsg::sample_type&
56
0
    SobolBrownianBridgeRsg::lastSequence() const {
57
0
        return seq_;
58
0
    }
59
60
0
    Size SobolBrownianBridgeRsg::dimension() const {
61
0
        return gen_.numberOfFactors() * gen_.numberOfSteps();
62
0
    }
63
64
    Burley2020SobolBrownianBridgeRsg::Burley2020SobolBrownianBridgeRsg(
65
        Size factors,
66
        Size steps,
67
        SobolBrownianGenerator::Ordering ordering,
68
        unsigned long seed,
69
        SobolRsg::DirectionIntegers directionIntegers,
70
        unsigned long scrambleSeed)
71
0
    : seq_(sample_type::value_type(factors * steps), 1.0),
72
0
      gen_(factors, steps, ordering, seed, directionIntegers, scrambleSeed) {}
73
74
    const Burley2020SobolBrownianBridgeRsg::sample_type&
75
0
    Burley2020SobolBrownianBridgeRsg::nextSequence() const {
76
0
        setNextSequence(gen_, seq_.value);
77
0
        return seq_;
78
0
    }
79
80
    const Burley2020SobolBrownianBridgeRsg::sample_type&
81
0
    Burley2020SobolBrownianBridgeRsg::lastSequence() const {
82
0
        return seq_;
83
0
    }
84
85
0
    Size Burley2020SobolBrownianBridgeRsg::dimension() const {
86
0
        return gen_.numberOfFactors() * gen_.numberOfSteps();
87
0
    }
88
89
}