QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
sobolrsg.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2003, 2004 Ferdinando Ametrano
5 Copyright (C) 2006 Richard Gould
6 Copyright (C) 2007 Mark Joshi
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
26#ifndef quantlib_sobol_ld_rsg_hpp
27#define quantlib_sobol_ld_rsg_hpp
28
29#include <ql/methods/montecarlo/sample.hpp>
30#include <cstdint>
31#include <vector>
32
33namespace QuantLib {
34
36
110 class SobolRsg {
111 public:
118 explicit SobolRsg(Size dimensionality,
119 unsigned long seed = 0,
120 DirectionIntegers directionIntegers = Jaeckel);
122 void skipTo(std::uint_least32_t n);
123 const std::vector<std::uint_least32_t>& nextInt32Sequence() const;
124
126 const std::vector<std::uint_least32_t>& v = nextInt32Sequence();
127 // normalize to get a double in (0,1)
128 for (Size k=0; k<dimensionality_; ++k)
130 return sequence_;
131 }
132 const sample_type& lastSequence() const { return sequence_; }
133 Size dimension() const { return dimensionality_; }
134 private:
135 static const int bits_;
136 static const double normalizationFactor_;
138 mutable std::uint_least32_t sequenceCounter_ = 0;
139 mutable bool firstDraw_ = true;
141 mutable std::vector<std::uint_least32_t> integerSequence_;
142 std::vector<std::vector<std::uint_least32_t>> directionIntegers_;
143 };
144
145}
146
147#endif
Sobol low-discrepancy sequence generator.
Definition: sobolrsg.hpp:110
std::uint_least32_t sequenceCounter_
Definition: sobolrsg.hpp:138
std::vector< std::vector< std::uint_least32_t > > directionIntegers_
Definition: sobolrsg.hpp:142
static const double normalizationFactor_
Definition: sobolrsg.hpp:136
Size dimension() const
Definition: sobolrsg.hpp:133
sample_type sequence_
Definition: sobolrsg.hpp:140
void skipTo(std::uint_least32_t n)
Definition: sobolrsg.cpp:78774
static const int bits_
Definition: sobolrsg.hpp:135
const SobolRsg::sample_type & nextSequence() const
Definition: sobolrsg.hpp:125
const sample_type & lastSequence() const
Definition: sobolrsg.hpp:132
std::vector< std::uint_least32_t > integerSequence_
Definition: sobolrsg.hpp:141
const std::vector< std::uint_least32_t > & nextInt32Sequence() const
Definition: sobolrsg.cpp:78793
Sample< std::vector< Real > > sample_type
Definition: sobolrsg.hpp:112
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
weighted sample
Definition: sample.hpp:35