Coverage Report

Created: 2025-08-05 06:45

/src/quantlib/ql/math/randomnumbers/haltonrsg.hpp
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) 2003 Ferdinando Ametrano
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 haltonrsg.hpp
21
    \brief Halton low-discrepancy sequence generator
22
*/
23
24
#ifndef quantlib_halton_ld_rsg_h
25
#define quantlib_halton_ld_rsg_h
26
27
#include <ql/methods/montecarlo/sample.hpp>
28
#include <vector>
29
30
namespace QuantLib {
31
32
    //! Halton low-discrepancy sequence generator
33
    /*! Halton algorithm for low-discrepancy sequence.  For more
34
        details see chapter 8, paragraph 2 of "Monte Carlo Methods in
35
        Finance", by Peter Jäckel
36
37
        \test
38
        - the correctness of the returned values is tested by
39
          reproducing known good values.
40
        - the correctness of the returned values is tested by checking
41
          their discrepancy against known good values.
42
    */
43
    class HaltonRsg {
44
      public:
45
        typedef Sample<std::vector<Real> > sample_type;
46
        explicit HaltonRsg(Size dimensionality,
47
                           unsigned long seed = 0,
48
                           bool randomStart = true,
49
                           bool randomShift = false);
50
        const sample_type& nextSequence() const;
51
0
        const sample_type& lastSequence() const {
52
0
            return sequence_;
53
0
        }
54
0
        Size dimension() const {return dimensionality_;}
55
      private:
56
        Size dimensionality_;
57
        mutable unsigned long sequenceCounter_ = 0;
58
        mutable sample_type sequence_;
59
        std::vector<unsigned long> randomStart_;
60
        std::vector<Real>  randomShift_;
61
    };
62
}
63
64
65
#endif