QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
SobolRsg Class Reference

Sobol low-discrepancy sequence generator. More...

#include <sobolrsg.hpp>

+ Collaboration diagram for SobolRsg:

Public Types

enum  DirectionIntegers {
  Unit , Jaeckel , SobolLevitan , SobolLevitanLemieux ,
  JoeKuoD5 , JoeKuoD6 , JoeKuoD7 , Kuo ,
  Kuo2 , Kuo3
}
 
typedef Sample< std::vector< Real > > sample_type
 

Public Member Functions

 SobolRsg (Size dimensionality, unsigned long seed=0, DirectionIntegers directionIntegers=Jaeckel, bool useGrayCode=true)
 
const std::vector< std::uint32_t > & skipTo (std::uint32_t n) const
 
const std::vector< std::uint32_t > & nextInt32Sequence () const
 
const SobolRsg::sample_typenextSequence () const
 
const sample_typelastSequence () const
 
Size dimension () const
 

Private Attributes

Size dimensionality_
 
std::uint32_t sequenceCounter_ = 0
 
bool firstDraw_ = true
 
sample_type sequence_
 
std::vector< std::uint32_t > integerSequence_
 
std::vector< std::vector< std::uint32_t > > directionIntegers_
 
bool useGrayCode_
 

Detailed Description

Sobol low-discrepancy sequence generator.

A Gray code counter and bitwise operations are used for very fast sequence generation.

The implementation relies on primitive polynomials modulo two from the book "Monte Carlo Methods in Finance" by Peter Jäckel.

21 200 primitive polynomials modulo two are provided in QuantLib. Jäckel has calculated 8 129 334 polynomials: if you need that many dimensions you can replace the primitivepolynomials.cpp file included in QuantLib with the one provided in the CD of the "Monte Carlo Methods in Finance" book.

The choice of initialization numbers (also know as free direction integers) is crucial for the homogeneity properties of the sequence. Sobol defines two homogeneity properties: Property A and Property A'.

The unit initialization numbers suggested in "Numerical Recipes in C", 2nd edition, by Press, Teukolsky, Vetterling, and Flannery (section 7.7) fail the test for Property A even for low dimensions.

Bratley and Fox published coefficients of the free direction integers up to dimension 40, crediting unpublished work of Sobol' and Levitan. See Bratley, P., Fox, B.L. (1988) "Algorithm 659: Implementing Sobol's quasirandom sequence generator," ACM Transactions on Mathematical Software 14:88-100. These values satisfy Property A for d<=20 and d = 23, 31, 33, 34, 37; Property A' holds for d<=6.

Jäckel provides in his book (section 8.3) initialization numbers up to dimension 32. Coefficients for d<=8 are the same as in Bradley-Fox, so Property A' holds for d<=6 but Property A holds for d<=32.

The implementation of Lemieux, Cieslak, and Luttmer includes coefficients of the free direction integers up to dimension

  1. Coefficients for d<=40 are the same as in Bradley-Fox. For dimension 40<d<=360 the coefficients have been calculated as optimal values based on the "resolution" criterion. See "RandQMC user's guide - A package for randomized quasi-Monte Carlo methods in C," by C. Lemieux, M. Cieslak, and K. Luttmer, version January 13 2004, and references cited there (http://www.math.ucalgary.ca/~lemieux/randqmc.html). The values up to d<=360 has been provided to the QuantLib team by Christiane Lemieux, private communication, September 2004.

For more info on Sobol' sequences see also "Monte Carlo Methods in Financial Engineering," by P. Glasserman, 2004, Springer, section 5.2.3

The Joe–Kuo numbers and the Kuo numbers are due to Stephen Joe and Frances Kuo.

S. Joe and F. Y. Kuo, Constructing Sobol sequences with better two-dimensional projections, preprint Nov 22 2007

See http://web.maths.unsw.edu.au/~fkuo/sobol/ for more information.

The Joe-Kuo numbers are available under a BSD-style license available at the above link.

Note that the Kuo numbers were generated to work with a different ordering of primitive polynomials for the first 40 or so dimensions which is why we have the Alternative Primitive Polynomials.

Tests:
  • the correctness of the returned values is tested by reproducing known good values.
  • the correctness of the returned values is tested by checking their discrepancy against known good values.

Definition at line 110 of file sobolrsg.hpp.

Member Typedef Documentation

◆ sample_type

typedef Sample<std::vector<Real> > sample_type

Definition at line 112 of file sobolrsg.hpp.

Member Enumeration Documentation

◆ DirectionIntegers

Enumerator
Unit 
Jaeckel 
SobolLevitan 
SobolLevitanLemieux 
JoeKuoD5 
JoeKuoD6 
JoeKuoD7 
Kuo 
Kuo2 
Kuo3 

Definition at line 113 of file sobolrsg.hpp.

Constructor & Destructor Documentation

◆ SobolRsg()

SobolRsg ( Size  dimensionality,
unsigned long  seed = 0,
DirectionIntegers  directionIntegers = Jaeckel,
bool  useGrayCode = true 
)
explicit

The so called generating integer is chosen to be \(\gamma(n) = n\) if useGrayCode is set to false and \(\gamma(n) = G(n)\) where \(G(n)\) is the Gray code of \(n\) otherwise. The Sobol integers are then constructed using formula 8.20 resp. 8.23, see "Monte Carlo Methods in Finance" by Peter Jäckel. The default is to use the Gray code since this allows a faster sequence generation. The Burley2020SobolRsg relies on an underlying SobolRsg not using the Gray code on the other hand due to its specific way of constructing the integer sequence.

Precondition
dimensionality must be <= PPMT_MAX_DIM

Definition at line 78477 of file sobolrsg.cpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ skipTo()

const std::vector< std::uint32_t > & skipTo ( std::uint32_t  n) const

skip to the n-th sample in the low-discrepancy sequence

Definition at line 78775 of file sobolrsg.cpp.

+ Here is the caller graph for this function:

◆ nextInt32Sequence()

const std::vector< std::uint32_t > & nextInt32Sequence ( ) const

Definition at line 78807 of file sobolrsg.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nextSequence()

const SobolRsg::sample_type & nextSequence ( ) const

Definition at line 134 of file sobolrsg.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lastSequence()

const sample_type & lastSequence ( ) const

Definition at line 141 of file sobolrsg.hpp.

◆ dimension()

Size dimension ( ) const

Definition at line 142 of file sobolrsg.hpp.

Member Data Documentation

◆ dimensionality_

Size dimensionality_
private

Definition at line 144 of file sobolrsg.hpp.

◆ sequenceCounter_

std::uint32_t sequenceCounter_ = 0
mutableprivate

Definition at line 145 of file sobolrsg.hpp.

◆ firstDraw_

bool firstDraw_ = true
mutableprivate

Definition at line 146 of file sobolrsg.hpp.

◆ sequence_

sample_type sequence_
mutableprivate

Definition at line 147 of file sobolrsg.hpp.

◆ integerSequence_

std::vector<std::uint32_t> integerSequence_
mutableprivate

Definition at line 148 of file sobolrsg.hpp.

◆ directionIntegers_

std::vector<std::vector<std::uint32_t> > directionIntegers_
private

Definition at line 149 of file sobolrsg.hpp.

◆ useGrayCode_

bool useGrayCode_
private

Definition at line 150 of file sobolrsg.hpp.