+ All Categories
Home > Documents > A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random...

A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random...

Date post: 07-Jun-2020
Category:
Upload: others
View: 8 times
Download: 0 times
Share this document with a friend
23
A toolbox for quasi-random simulation Michael Carter Quasi-random simulation uses low discrepancy or quasi-random sequences in place of pseudo-random sequences, producing faster convergence in problems of moderate dimensions. The objective of this paper is both pedagogical and practical, to provide an easily understood introduction to the construction of Sobol sequences and a toolkit for constructing and evaluating such sequences. à Introduction In the 18 th century, Georges Louis Leclerc, Comte de Buffon, proposed a novel method to estimate p - dropping a needle over and over again onto a wooden floor of parallel planks. The probability of a needle crossing a join in the floor is related to p. By counting the number of crosses, one can estimate this probability, and hence compute a value for p (see Siniksaran 2008). Buffon is said to have tried the method by tossing baguettes over his shoulder. A more direct way of estimating p is to throw darts randomly at a circular target inscribed in a square, and count the propor- tion that land inside the circle (see figure). These are simple examples of numerical integration by simulation. Estimating p by simulation Numerical integration requires evaluating a function a number of distinct points and computing an average value. There are at least three ways in which we could lay out a grid of points on which to evaluate an integral, which are illustrated below. Familiar rules of quadrature, such as Simpson's rule, use a regular grid or lattice. The short-comings of this approach is that it is difficult to compute a sufficiently dense tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08
Transcript
Page 1: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

A toolbox for quasi-random simulation

Michael Carter

Quasi-random simulation uses low discrepancy or quasi-random sequences inplace of pseudo-random sequences, producing faster convergence in problemsof moderate dimensions. The objective of this paper is both pedagogical andpractical, to provide an easily understood introduction to the construction ofSobol sequences and a toolkit for constructing and evaluating such sequences.

à Introduction

In the 18th century, Georges Louis Leclerc, Comte de Buffon, proposed a novelmethod to estimate p - dropping a needle over and over again onto a wooden floor ofparallel planks. The probability of a needle crossing a join in the floor is related to p.By counting the number of crosses, one can estimate this probability, and hencecompute a value for p (see Siniksaran 2008). Buffon is said to have tried the methodby tossing baguettes over his shoulder. A more direct way of estimating p is tothrow darts randomly at a circular target inscribed in a square, and count the propor-tion that land inside the circle (see figure). These are simple examples of numericalintegration by simulation.

Estimating p by simulation

Numerical integration requires evaluating a function a number of distinct points andcomputing an average value. There are at least three ways in which we could lay outa grid of points on which to evaluate an integral, which are illustrated below.Familiar rules of quadrature, such as Simpson's rule, use a regular grid or lattice. Theshort-comings of this approach is that it is difficult to compute a sufficiently dense

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 2: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

grid in higher dimensions. For example, a grid of four points in 250 dimensionsrequires 4250 = 3.27339μ10150 points. Furthermore, only a limited number of coordi-nate values are evaluated. Traditional Monte-Carlo simulation uses a pseudo-randomgrid, so the numerous combinations of points are evaluated. We observe that thepoints tend to cluster, with many boxes having no points while some boxes havemultiple points. Low discrepancy or quasi-random sequences attempt to combine thebest features of both a grid and pseudo-random points while overcoming the disadvan-tages of each. They are specifically constructed so that they fill the space in a "quasi"random but uniform manner. Observe that each of the boxes in the right-hand graphhas one and only one point.

0.0 0.2 0.4 0.6 0.8 1.00.0

0.2

0.4

0.6

0.8

1.0Grid

0.0 0.2 0.4 0.6 0.8 1.00.0

0.2

0.4

0.6

0.8

1.0Pseudorandom

0.0 0.2 0.4 0.6 0.80.0

0.2

0.4

0.6

0.8

1.0Quasirandom

Alternative 2D sequences

The most common pseudorandom number generator is the linear congruential gener-ator in which successive numbers are generated recursively by

(1)xn+1 = a xn + c mod mstarting with an initial seed x0. Dividing by m gives a sequence of fractionsui = xi m in the unit interval [0,1). By careful choice of a, c and m, a sequence ofperiod m can be obtained. The resulting sequence of real numbers will appear to beuniformly distributed on 0, 1. For simulation, it is not sufficient to avoid clusteringin a single dimension. Most practical problems, from estimating p to valuing anexotic financial derivative, require multi-dimensional random sequences. In theprevious diagram, we observe the clustering that is typical of pseudo-randomsequences.

Low discrepancy are known to give superior performance in low dimension prob-lems, but their relative advantage erodes as the dimension of the integral increases.One practical area in which quasi-random simulation has shown great promise isfinance, where valuation of derivative instruments requires the computation of multi-dimensional expected values. Such valuations may need to be computed daily, whichmeans that computational efficiency is extremely important. In this application, lowdiscrepancy sequences have been shown to give improved performance even in veryhigh dimensional problems.

Low discrepancy sequences have been proposed by Halton, Faure, Sobol and Nieder-reiter. Though not exhibiting the lowest asymptotic discrepancy, Sobol sequenceshave been found in practice to yield as good or better performance especially in finan-cial applications. Consequently, this paper focuses on Sobol sequences, although thetools are more generally applicable. The objective of this paper is both pedagogicaland practical, to provide an easily understood introduction to the composition ofSobol sequences and a toolkit for constructing and evaluating such sequences.

2 Michael Carter

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 3: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

The construction of Sobol sequences

A Sobol sequence is a sequence of points x1, x2, …xn in the unit hypercube 0, 1d ,which d is the dimension of the problem. In other words, each element xi of thesequence is d-dimensional vector whose components are fractions between 0 and 1.A Sobol sequence can be computed by the simple recursion

(2)xn+1 = v jn ∆ xn

Equation (2) is analogous to the linear congruential generator (1) for pseudorandomnumbers. The differences are

è the coefficients v jn vary with the n and also with the dimension d (v jn is avector).

è the operator is bit-wise xor ∆ rather than multiplication. It is equivalent toaddition modulo-2.

The coefficients v jn are known as direction numbers. The index jn of the appro-priate element of the set of direction numbers is the rightmost zero bit in the binaryexpansion of n. Consequently, to produce a Sobol sequence of length n requires onedirection number for each bit in the binary expansion of n, a total of k = Log2 ndirection numbers for each dimension. The complicated part of computing a Sobolsequence is computing the direction numbers for each dimension. Once this is done,computing the series using (2) is straightforward and fast. First, we load the accompa-nying package, assuming that it is in the current directory or a directory in the path.

Needs "QRSToolbox`"

The sequence 1

2,

3

4,

7

8,

5

16,

7

32,

43

64 is a valid set of direction numbers for generating

the first 63 elements of a one-dimensional Sobol sequence. The first 16 elements ofthis sequence are

TableFormSobol16, 1, InitialValues 11, 1, 3, 7,Offset 0 Flatten,

TableHeadings None, Range0, 150 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 1

2

1

4

3

4

1

8

5

8

3

8

7

8

11

16

3

16

15

16

7

16

9

16

1

16

13

16

5

16

The 7th element in this sequence 7 8. The binary expansion of 7 is 0111, the right-most zero bit is 4 from the end. Therefore the appropriate direction number is thefourth, namely 5/16. From (2), the 8th element is

x8 = v4∆ x7 =5

16∆

7

8=

5

16∆

14

16=

01012

16∆

11102

16=

10112

16=

11

16

We now turn to the computation of direction numbers, the essential ingredients of aSobol sequences. A k-degree polynomial

xk + a1 xk-1 + a2 xk-2 + … ak-1 x + ak

A Toolbox for Quasi-Random Simulation 3

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 4: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

defines a unique recursive sequence of order k

x j = a1 x j-1 + a2 x j-2 +… + ak-1 x j-k+1 + ak x j-k

requiring k initial values. Direction numbers for a Sobol sequence are computed by aspecial recursive sequence

v j = a1 v j-1∆ a2 v j-2 … ∆ ak-1 v j-k+1∆ ak v j-k∆v j-k

2k

in which

æ the class of polynomials is restricted to the primitive polynomials mod 2 (definedin the next section)

æ addition (+) is replaced with bit-wise or (∆) and

æ an extra term is added.

Computationally, it is convenient to use the equivalent recursion which requires onlyinteger arithmetic

(3)m j =

2 a1 m j-1∆ 22 a2 m j-2 ∆ … ∆ 2k-1 ak-1 m j-k+1 ∆ 2k ak m j-k ∆ m j-k

Seeded with k non-negative odd integers m1, m2, m3, … with mi < 2i, subsequentvalues generated by (3) are also non-negative odd integers with m j < 2 j for all j.Direction numbers are obtained by dividing each term by 2 j, that is

v1, v2, …, vM = m1

2,

m2

4,

m3

8, …,

mM

2M

To illustrate, the direction numbers used above were generated from the 3rd degreeprimitive polynomial x3 + x + 1, in which a1 = 0 and a2 = a3 = 1. The correspondingrecurrence relation is

m j = 22 m j-2∆ 23 m j-3 ∆ m j-3

Starting with the initial values {1,3,7}, this recurrence generates the sequence

CirclePlusi_Integer, j_Integer : BitXori, j

fj_ : 4 fj 2 8 fj 3 fj 3f1 1; f2 3; f3 7;

Tablefj, j, 1, 61, 3, 7, 5, 7, 43

which are the numerators of the direction numbers used above.

Each dimension of the Sobol sequence requires a different primitive polynomial, andeach k degree polynomial requires k initial values, odd integers less than 2, 4, …, 2k

respectively. Choice of initial values is the one area of discretion left to the modeler.Indeed, choice of initial values is the most important issue in successful applicationof Sobol sequences.

4 Michael Carter

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 5: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

Consequently, a toolbox for quasi-random simulation using Sobol sequences needsto provide for

è identifying primitive polynomials modulo 2 to specify the recursions forgenerating direction numbers

è selecting appropriate initial values to seed the recursions

è computing the direction numbers

è generating the resulting multi-dimensional Sobol sequence.

These ingredients are depicted schematically in the following diagram.

Direction numbers SobPrimitive polynomials Recursive function

Initial numbers

In addition, our toolbox provides

è functions for computing the discrepancy on any sequence

which can be used to evaluate initial values for computing Sobol sequences, and tocompare the effectiveness of pseudo-random and quasi-random sequences.

à Primitive polynomials mod 2

A polynomial modulo 2 is a polynomial

xk + a1 xk-1 + … + ak-1 x + ak

whose coefficients a1, a2, ..., ak are either zero or one. The highest power is thedegree of the polynomial. There are 23 third-degree polynomials mod 2, namely

x3, x3 + 1, x3 + x2, x3 + x2 + 1, x3 + x2 + x, x3 + x2 + x + 1, x3 + x, x3 + x + 1

The term primitive polynomial has two distinct meanings in algebra (see Knuth1981: 28-30, 404). For our purposes, a polynomial mod 2 is primitive if (in binaryarithmetic)

è it is irreducible (cannot be factored)

è the smallest power q for which the polynomial divides xq + 1 is q = 2k - 1.

A Toolbox for Quasi-Random Simulation 5

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 6: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

Only two of the eight third-degree polynomials are primitive, namely

x3 + x2 + 1, x3 + x + 1

Note that a polynomial with no constant term can always be factored as follows

xk + a1 xk-1 + … + ak-1 x = x xk-1 + a1 xk-2 + … + ak-1 Therefore, every primitive polynomial has a constant term. For the rest of this paper,polynomial means polynomial modulo 2.

á Encoding

Any polynomial mod 2 can be uniquely encoded in an integer by interpreting the coef-ficients (0 or 1) as bits. For example, the primitive third-degree polynomialx3 + x + 1 can be encoded as binary 1011b or decimal 11. The functions EncodePand DecodeP encode and decode polynomials.

The two primitive third-degree polynomials are encoded as

EncodePx3 x 1, x3 x2 111, 13

which can be decoded to give

DecodeP

1 x x3, 1 x2 x3For the remainder of the paper, we will call a polynomial's unique decimal code its p-number.

á Polynomials of degree k

Polynomial p is of degree k if and only if 2k § p < 2k+1. This provides a very straight-forward method for generating all the polynomials of a given degree, namely bydecoding the consecutive integers between 2k and 2k+1. For example, the third degreepolynomials are

DecodeP Range23, 231 1x3, 1 x3, x x3, 1 x x3,

x2 x3, 1 x2 x3, x x2 x3, 1 x x2 x3We note that a polynomial has a constant term if and only if it has an odd p-number.Therefore, to compute primitive polynomials we need consider only those with anodd p-number.

DecodeP Range23 1, 231 1, 21 x3, 1 x x3, 1 x2 x3, 1 x x2 x3

The function PolynomialMod2[k] generates the polynomials of degree k. By default,

6 Michael Carter

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 7: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

PolynomialMod2 gives only polynomials with a constant term, which are candidatesfor being primitive.

PolynomialMod231 x3, 1 x x3, 1 x2 x3, 1 x x2 x3

Setting the option WithConstantTerm to False, generates all polynomials of thespecified degree, including those no constant term.

á Irreducible polynomials

Suppose we attempt to factor the third degree polynomials with constant term.

TableForm, Factor, Modulus 2 & PolynomialMod23,

TableHeadings None, "Polynomial", "Factors"Polynomial Factors

1 x3 1 x 1 x x21 x x3 1 x x3

1 x2 x3 1 x2 x3

1 x x2 x3 1 x3

We observe that the first and last polynomials can be factored, while the other twoare irreducible. Now examine the Heads of the expressions after attemptedfactorization.

Head Factor, Modulus 2 & PolynomialMod23Times, Plus, Plus, Power

The irreducible polynomials have a Head of Plus, while the other two have Headsof Times or Power. We can use this to identify irreducible polynomials.

IrreducibleQpoly_ :

HeadFactorpoly, Modulus 2 Plus

The irreducible third-degree polynomials are

SelectPolynomialMod23 , IrreducibleQ1 x x3, 1 x2 x3

á Primitive polynomials

If q = 2k - 1 is prime, all the irreducible polynomials of degree k are primitive. If not,we must test each of the prime factors of q. For example, 24 - 1 = 15 is not prime.The irreducible polynomials of degree 4 are

irreducible4 SelectPolynomialMod24, IrreducibleQ1 x x4, 1 x3 x4, 1 x x2 x3 x4

A Toolbox for Quasi-Random Simulation 7

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 8: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

For each prime factor m of q = 2k - 1, we have to test whether the polynomialdivides xqm + 1. For k = 4 and q = 15, the prime factors are 3 and 5, and their cofac-tors are 5 and 3 respectively. That is, we need to check whether each polynomialdivides x5 + 1 or x3 + 1. Clearly, a 4th degree polynomial cannot divide x3 + 1. There-fore, we need only check those cofactors less than k. That is, we check whether theirreducible polynomials of degree 4 divide x5 + 1.

PolynomialRemainderx5 1, , x, Modulus 2 & irreducible4

1 x x2, x x3, 0This reveals that the third irreducible polynomial divides x5 + 1. We conclude thatthe first and second polynomials are primitive, whilst the third is not.

All 5thdegree irreducible polynomials are primitive, since 25 - 1 = 31 is prime.Considering the 6th degree polynomials, the prime factors of 26 - 1 = 63 are 3 and 7,and their cofactors are 21 and 9. Consequently, we need to consider the divisibility ofthe polynomials x21 + 1 and x9 + 1.

irreducible6 SelectPolynomialMod26, IrreducibleQ;

PolynomialRemainderx21 1, , x, Modulus 2 & irreducible6

x x3 x4 x5, 1 x3, 0, 1 x x2 x3,

x3 x4 x5, 1 x2 x3 x5, x x2 x4, x3 x4, 0PolynomialRemainderx9 1, , x, Modulus 2 &

irreducible6

1 x3 x4, 0, 1 x x2 x4, x2 x4 x5,

x x2 x3 x5, x2 x3, 1 x x2, x x2 x5, x3Removeirreducible4, irreducible6

We observe that the third and last polynomial divide x21 + 1, while the second polyno-mial divides x9 + 1. The remaining six polynomials are primitive. We summarize thistest in the function PrimitiveQ.

? PrimitiveQ

Assuming poly is a polynomial modulo 2,

PrimitiveQpoly gives True if poly primitive, and False otherwise.

The following function generates the primitive polynomials of degree k.

PrimitivePolynomialsMod2k_Integer :

SelectPolynomialMod2k, PrimitiveQPrimitivePolynomialsMod21 : 1 x

The p numbers of the 52 primitive polynomials up to degree 8 are

8 Michael Carter

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 9: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

Tablek, PrimitivePolynomialsMod2k EncodeP,

k, 8 Column

1, 32, 73, 11, 134, 19, 25, 315, 37, 41, 47, 55, 59, 616, 67, 73, 87, 91, 97, 103, 109, 115, 1177, 131, 137, 143, 145, 157, 167, 171, 185,

191, 193, 203, 211, 213, 229, 239, 241, 247, 2538, 283, 285, 299, 301, 313, 319, 333, 351, 355, 357,

361, 369, 375, 379, 391, 395, 397, 415, 419, 425,433, 445, 451, 463, 471, 477, 487, 499, 501, 505

The number N of primitive polynomials of degree k can be easily computed fromEuler's totient function f. Specifically,

Nk = f 2k - 1k

There are a some published sources for primitive polynomials. Numerical Recipes(Press et al. 1992) lists all 160 primitive polynomials of degree 10 or less (but notethat they use a different encoding). Joe and Kuo (2003) provide a list of the 1111primitive polynomials through degree 13, which they have recently extended todegree 18 (Joe and Kuo 2007). The CD accompanying Jäckel (2002) lists all primi-tive polynomials up to degree 27, a mammoth 8 million primitive polynomials.

à Implementation

We now give details of the Mathematica implementation of these components.

á Direction numbers

Recall that direction numbers are computed by the recursive sequence (3)

m j = 2 a1 m j-1∆ 22 a2 m j-2 ∆ … ∆ 2k-1 ak-1 m j-k+1 ∆ 2k m j-k ∆ m j-k

where a1, a2, ..., ak-1 are the coefficients of a k-degree primitive polynomialsak = 1). Each recursion of order k requires k initial values, which are arbitrary oddintegers less than 2, 4, …, 2k respectively. To implement this, we extract the binarydigits from the p number of the specified polynomial, use them to define an appro-priate recursive function, initialize the function with the vector M of initial valuesand them map this function over the integers 1, 2, …, n. The resulting function iscalled DirectionNumbers.

A Toolbox for Quasi-Random Simulation 9

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 10: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

? DirectionNumbers

DirectionNumbersp,M,n computes n direction numbers

for polynomial p using the initial values M. DirectionNumbersp,ncomputes n direction numbers for polynomial p using unit initial values.

The first six direction numbers for the 3rd primitive polynomial x3 + x2 + 1 withinitial values {1,3,7} are

DirectionNumbers11, 1, 3, 7, 61, 3, 7, 5, 7, 43

Note that DirectionNumbers returns the (integer) numerators of the directionnumber sequence, which is the form in which they will be used for generating theSobol sequence. If no direction numbers are specified, the function assumes all initialvalues are one (unit initialization).

á Recursive Sobol sequence

It is most efficient to compute all d dimensions of a Sobol sequence in parallel,which is especially convenient in Mathematica. To illustrate, we take the primitivepolynomials and initial values listed in Numerical Recipes, which are sufficient togenerate a 6 dimensional sequence.

NRInitialValues

3 17 1, 1

11 1, 3, 713 1, 3, 319 1, 1, 3, 1325 1, 1, 5, 9

;

SetOptionsSobol, InitialValues NRInitialValues;

To generate 10 points requires k = 4 sets of direction numbers, each set containingdirection numbers for 6 dimensions.

TransposeDirectionNumbers, 4 & NRInitialValues1, 1, 1, 1, 1, 1, 3, 1, 3, 3, 1, 1,5, 7, 7, 3, 3, 5, 15, 11, 5, 15, 13, 9

To enable integer computation, it is convenient to scale the first set of directionnumbers by 2k-1 = 23 = 8, the second by 2k-2 = 22 = 4 and so on.

Withk 4,

scaledDN Table2j, j, k 1, 0, 1 TransposeDirectionNumbers, k & NRInitialValues

8, 8, 8, 8, 8, 8, 12, 4, 12, 12, 4, 4,10, 14, 14, 6, 6, 10, 15, 11, 5, 15, 13, 9

The sequence can then be computed efficiently using FoldList to implement (2)across all dimensions in parallel, then converted to fractions by multiplying each

10 Michael Carter

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 11: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

result by 2-k = 24 = 16. This is the first 10 points of the 6-dimensional Sobolsequence using the initial values listed in Numerical Recipes are:

Withn 10, k 4,

2k FoldListBitXor, scaledDN1,

scaledDNRightMostZero Range1, n 1

1

2,

1

2,

1

2,

1

2,

1

2,

1

2, 1

4,

3

4,

1

4,

1

4,

3

4,

3

4,

3

4,

1

4,

3

4,

3

4,

1

4,

1

4, 3

8,

5

8,

1

8,

5

8,

1

8,

7

8,

7

8,

1

8,

5

8,

1

8,

5

8,

3

8, 1

8,

3

8,

3

8,

7

8,

7

8,

1

8,

5

8,

7

8,

7

8,

3

8,

3

8,

5

8, 5

16,

5

16,

11

16,

9

16,

11

16,

3

16,

13

16,

13

16,

3

16,

1

16,

3

16,

11

16, 1

16,

9

16,

15

16,

13

16,

7

16,

15

16

Sobol[{n,s}] generates a Sobol sequence of n points of dimension s. We give the argu-ments n, s as a list to conform with the pseudorandom generator RandomReal, andalso to suggest that the result is an nμs matrix of real numbers.

We now describe a number of useful variants of the basic function.

á Nonrecursive Sobol sequence

The recursive construction of the Sobol sequence (2) was proposed by Antonov andSaleev (1979). The original construction of Sobol is

(4)xn = b1 v1∆ b2 v2 ∆ … ∆ bk vk

where b1, b2, …, bk are the binary digits of n, that isn = b1 20 + b2 21 + b3 22 + … + bk 2k-1. The recursive definition (2) is obtainedfrom (4) using a Gray code encoding of n. This alters the order of the sequencewithout changing the asymptotic discrepancy. The original definition is useful forconstructing single elements of the sequence.

Sobol[n,s] gives the nth element in the (recursive) Sobol sequence. Sobol[n,s, Gray-Code-> False] gives the nth element in the original Sobol sequence. For example, the10th element in the recursive sequence we computed in the previous subsection is

Sobol10, 6

1

16,

9

16,

15

16,

13

16,

7

16,

15

16

This is the 15th element in the sequence constructed using (4).

A Toolbox for Quasi-Random Simulation 11

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 12: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

Sobol15, 6, GrayCode False

1

16,

9

16,

15

16,

13

16,

7

16,

15

16

Equation (4) is useful for initiating the sequence at an arbitrary starting point.

á Initial offset

Note the repetition of coordinates in the initial points of the sequence. For example,in the first 10 points of 3-dimensional sequence, many of the coordinates appearthree times.

Sobol10, 3 Flatten Sort

1

16,

1

8,

1

8,

1

8,

3

16,

1

4,

1

4,

1

4,

5

16,

5

16,

3

8,

3

8,

3

8,

1

2,

1

2,

1

2,

9

16,

5

8,

5

8,

5

8,

11

16,

3

4,

3

4,

3

4,

13

16,

13

16,

7

8,

7

8,

7

8,

15

16

To avoid this repetition, many authors recommend discarding the first m points in aSobol sequence, although the chosen m is arbitrary. To this end, we redefine the defi-nition to allow setting an initial offset as an option. Setting this option Offset Ø mwill utilize (4) to generate the first point of the sequence, and then use (2) to generatethe remaining points of the sequence.

Strictly speaking, the Sobol sequence begins with the point 0, 0, …, 0, althoughmost implementations exclude this point. A sequence beginning with zero can beobtained by setting the Offset Ø 0.

Sobol4, 6, Offset 0

0, 0, 0, 0, 0, 0, 1

2,

1

2,

1

2,

1

2,

1

2,

1

2,

1

4,

3

4,

1

4,

1

4,

3

4,

3

4, 3

4,

1

4,

3

4,

3

4,

1

4,

1

4

The default value of Offset is 1, generating the a sequence beginning with 1

2,

1

2, …,

1

2. That is, Offset specifies the ordinal number of the first element in the

sequence.

á Specifying the polynomials and initial values

We will show below that selection of the initial values is important in determiningthe quality of the Sobol sequence. We next allow for the initial values to be specifiedas an option. This is useful for selecting particular dimensions, such as portraying 2Dprojections. Initial values are specified as a list, each element of which is a polyno-mial p-number followed by a list of initial values equal in number the degree of thepolynomial.

12 Michael Carter

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 13: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

The following is the 2-dimensional sequence extracted from the 3rd and 4th coordi-nates of the Numerical Recipes implementation.

Sobol10, 2, InitialValues 11 1, 3, 713 1, 3, 3

1

2,

1

2, 1

4,

1

4, 3

4,

3

4, 1

8,

5

8, 5

8,

1

8,

3

8,

7

8, 7

8,

3

8, 11

16,

9

16, 3

16,

1

16, 15

16,

13

16

The alternative initial values proposed by Joe and Kuo 2007 give a differentsequence.

Sobol10, 2, InitialValues 11 1, 3, 113 1, 1, 1

1

2,

1

2, 1

4,

3

4, 3

4,

1

4, 7

8,

3

8, 3

8,

7

8,

5

8,

5

8, 1

8,

1

8, 7

16,

9

16, 15

16,

1

16, 3

16,

5

16

á Specifying the polynomials

For some purposes, it will be useful to select only the primitive polynomials andhave the initial values supplied by default value of the InitialValues option. Thefollowing input gives the 3rd and 4th coordinates of the Numerical Recipes sequence.

Sobol10, 2, Polynomials 11, 13

1

2,

1

2, 1

4,

1

4, 3

4,

3

4, 1

8,

5

8, 5

8,

1

8,

3

8,

7

8, 7

8,

3

8, 11

16,

9

16, 3

16,

1

16, 15

16,

13

16

This gives a 2-dimensional sequence based on the same polynomials, but withdifferent starting values.

Sobol10, 2, Polynomials 11, 13,

InitialValues 11 1, 3, 113 1, 1, 1

1

2,

1

2, 1

4,

3

4, 3

4,

1

4, 7

8,

3

8, 3

8,

7

8,

5

8,

5

8, 1

8,

1

8, 7

16,

9

16, 15

16,

1

16, 3

16,

5

16

A Toolbox for Quasi-Random Simulation 13

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 14: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

á Unit initialization

Recall that kth order recursion for building direction numbers requires k initial valueswhich are odd integers less than 2, 4, …, 2k respectively. The simplest valid choicefor the initial values is to set them all equal to one, which we will call unit initializa-tion. We add this as an option. We will demonstrate in the next section that unit initialization does not produce sequences with the lowest discrepancy.

Sobol10, 2, Polynomials 11, 13,InitialValues Unit

1

2,

1

2, 3

4,

3

4, 1

4,

1

4, 3

8,

3

8, 7

8,

7

8,

5

8,

5

8, 1

8,

1

8, 15

16,

9

16, 7

16,

1

16, 3

16,

5

16

á Summary

We summarize our implementation. Sobol[{n,s}] generates a Sobol sequence of npoints of dimension s, while Sobol[n,s] gives the nth element in the same sequence.The function Sobol has the following options, which are listed with their defaultvalues

Option Default

InitialValues JK2007InitialValues

Offset 1

Polynomials Automatic

GrayCode True

The initial values listed in Numerical Recipes are only sufficient to generate asequence of six dimensions. Consequently, we adopt the initial values provided byJoe and Kuo (2007) as the default option for generating Sobol sequences.

Joe and Kuo provide optimized initial values sufficient for 7800 dimensions on their web sitehttp://web.maths.unsw.edu.au/~fkuo/sobol/index.html. For economy, we have incorporatedonly the first 100 values into this package.

SetOptionsSobol, InitialValues JK2007InitialValues;

à Evaluation

There are at least three ways in which the performance of low-discrepancy sequencescan be evaluated, namely

æ viewing two-dimensional projections

æ measuring discrepancy

14 Michael Carter

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 15: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

evaluating performance in application

We illustrate each in turn.

á Projections

A graphic way to explore the discrepancy of pseudo- and quasi-random sequences isto plot 2-dimensional projections. The following graph shows a striking example ofthe failure of a Sobol sequence to approximate a uniform distribution in particulardimensions. The left hand graph shows that the clustering of the first 4096 points inthe sequence. The right hand graph shows that the distribution of the next 4096points exactly complements the distribution of the first 4096 points.

0.2 0.4 0.6 0.8 1.0

0.2

0.4

0.6

0.8

1.0

First 212 points

0.2 0.4 0.6 0.8 1.0

0.2

0.4

0.6

0.8

1.0

Next 212 points

Dimensions 19 and 28 of a standard Sobol sequence

This particular example, taken from Joe and Kuo (2007), uses the initial values givenby Bratley and Fox (1988) in their well-known implementation. Below, we depicttwo other examples drawn from the former paper.

0.2 0.4 0.6 0.8 1.0

0.2

0.4

0.6

0.8

1.0

0.2 0.4 0.6 0.8 1.0

0.2

0.4

0.6

0.8

1.0

Figures 1 and 4 from Joe and Kuo 2007

These examples underline the importance of the choice of initial values. Joe and Kuo(2007) select the initial values specifically to improve these 2-dimensional projec-tions. We restore these as the default.

SetOptionsSobol, InitialValues JK2007InitialValues;

á Measuring discrepancy

Discrepancy is a measure of the difference between the actual distribution of pointsand a uniform distribution in which the number of points in any set A is proportionalto its size. Specifically, let A be a collection of subsets of the hypercube 0, 1d . Thediscrepancy of the sequence x1, x2, …, xn relative to A is

(5)D = supAœA

Ò xi œ An

- mA

A Toolbox for Quasi-Random Simulation 15

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 16: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

where Ò xi œ A denotes the number of points in A and mA is the measure of A.Different collections A of sets give rise to different measures. Taking A to be thecollection of all rectangles j=1

d u j, v j in 0, 1dgives the ordinary discrepancy;

taking A to be the collection of all rectangles j=1d 0, v j in 0, 1dgives the star

discrepancy. The L¶ norm in (5) is useful in theoretical evaluation, but impracticalfor measuring the discrepancy of specific sequences. If we substitute the EuclideanL2 norm, it is possible to derive explicit formulae for both ordinary Tn and the starTn* discrepancy of a given sequence (Morokoff and Caflisch, 1994)

(6)

Tn2 =1

n2S

i=1

nSj=1

nP

k=1

d 1 -maxxi,k , x j,k ÿ minxi,k , x j,k -

21-d

nS

i=1

nP

k=1

dxi,k 1 - xi,k + 12-d

Tn*2

=1

n2S

i=1

nSj=1

nP

k=1

d 1 -maxxi,k , x j,k -21-d

nS

i=1

nP

k=1

d 1 - xi,k2 + 3-d

These calculations are implemented in the functions DiscrepancySqd and StarDis-crepancySqd.

? DiscrepancySqd

DiscrepancySqdX, computes the discrepancy

squared of X, a sequence of n points in the d dimensional

unit hypercube 0,1d, where n μ d are the dimensions of X.

We can also calculate the expected value of these quantities for a genuinely randomsequence (Morokoff and Caflisch, 1994)

(7)ETN2 = 1

N6-d 1 - 2-d ETN

* 2 = 1

N2-d - 3-d

These formulae are implemented in the corresponding functions EDiscrepancySqdand EStarDiscrepancySqd.

To illustrate, the following computation shows the discrepancy of a three-dimen-sional Sobol sequence relative to that expected of a purely random sequence.Remember that discrepancy measures the degree of non-uniformity in the distribu-tion of the sequence. By this measure, we observe that the quasi-random sequence isthree to six times more uniform than what would be expected of a purely randomsequence. However, the advantage of the quasi-random sequence erodes as thenumber of dimensions is increased.

WithX Sobol1024, 3,

DiscrepancySqdNXEDiscrepancySqdX ,

StarDiscrepancySqdNXEStarDiscrepancySqdX

0.295287, 0.14947

16 Michael Carter

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 17: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

Since computing discrepancy using (6) requires combining every pair of randomvectors xi, x j, the time required increases linearly with the dimension s but quadrati-cally with n. Computation of (6) in Mathematica will run significantly faster if weensure that floating-point rather than exact arithmetic is used, which is why we applyN to the arguments of DiscrepancySqd and StarDiscrepancySqd in the previouscalculation.

Our implementation of DiscrepancySqd and StarDiscrepancySqd is a straightfor-ward translation of the expressions in (6). These functions can be written more effi-ciently and then compiled to improve their execution speed by an order of magni-tude. (I am grateful to the referee for demonstrating this.) However, the compiledfunctions are still too slow to be practical for large values of n. Consequently, weprovide much faster functions MLDiscrepancySqd and MLStarDiscrepancySqdimplemented in C++ and accessible through Mathlink. Because of the way in whichdata transfer is implemented in Mathlink, it is vital to ensure that the arguments tothese functions are converting to floating point before being passed to the executable.(If unreasonable results are returned, failure to apply N to the arguments of MLDis-crepancySqd or MLStarDiscrepancySqd should be the prime suspect.) Details ofhow to install and use the executable are given in the appendix.

mlink Install"discrepancy.exe";

WithX Sobol1024, 3,

MLDiscrepancySqdNXEDiscrepancySqdX ,

MLStarDiscrepancySqdNXEStarDiscrepancySqdX

0.295287, 0.14947The following graph compares the discrepancy of Sobol sequences of varying lengthrelative to the expected discrepancy of a purely random sequence, using the twomeasures of discrepancy. We observe that the two measures are broadly consistent,both indicating that the relative advantage of the quasi-random sequence dissipateswith increasing dimension. (The horizontal axis is scaled in binary thousands, that is1024). Star discrepancy has generally been favored as a measure because it can beused to bound integration error (see Morokoff and Caflisch, 1994: 4-13, Glasserman,2003: 287-290).

A Toolbox for Quasi-Random Simulation 17

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 18: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

2 4 6 8 10 12n 000

0.05

0.10

0.15

0.20

0.25

0.30d = 3

Star discrepancy

Ordinary discrepancy

2 4 6 8 10 12

0.2

0.4

0.6

0.8

1.0

d = 15

Star discrepancy

Ordinary discrepancy

Relative discrepancy: Sobol sequence

The following graph compares the discrepancy of pseudo- and quasi-randomsequences relative to the expected discrepancy of a purely random sequence as wevary the dimension d. This confirms the conventional wisdom that low-discrepancysequences (blue) out-perform pseudo-random sequences (red) for low dimensions,but that their advantage is eroded as the dimension is increased, with the cross-overaround d = 12 (Galanti and Jung 1997:75). The measured discrepancy of the pseudo-random sequence (red) hovers around its expected value, so its relative discrepancyis close to the horizontal axis located at 1.The dashed curve shows the discrepancy ofa Sobol sequence constructed using unit initialization.

5 10 15 20 25 30s

0.0

0.5

1.5

2.0

2.5

3.0

3.5

n = 8K

5 10 15 20 25

0.5

1.5

n = 32K

Relative discrepancy: Sobol v. pseudo random

The next graph makes the same comparison using star discrepancy. Under thismeasure, the quasi-random sequence (blue) appears to remain competitive with thepseudo-random sequence (red) for higher dimensions. We conclude that the evalua-tion of the relative performance of quasi- versus pseudo-random sequences at higherdimensions depends upon the measure of discrepancy used. This graph emphasizesthe importance of initial values. The dashed curve shows the relative star discrepancyof a Sobol sequence constructed with unit initialization deteriorates dramatically athigher dimensions.

18 Michael Carter

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 19: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

5 10 15 20 25 30s

0.0

0.5

1.5

2.0

n = 8K

5 10 15 20 25

0.0

0.5

1.5

2.0n = 32K

Relative star discrepancy: Sobol v. pseudo random

Jäckel (2002) includes a more extensive range of comparisons, covering a greatervariety of dimensions and other low-discrepancy sequences.

Uninstallmlink;

á Performance in practice

The following graph compares three methods of estimating p by simulation. The blueline shows the estimate of p from a low-discrepancy sequence of varying sizes, brack-eted by the estimates from a rectangular grid (green) and a pseudorandom sequence(red) of identical size. We observe that the low-discrepancy sequence generallyprovides a more accurate estimate than the rectangular grid, and a significantly betterestimate than the pseudorandom sequence.

10 20 30 40

3.10

3.12

3.16

3.18

Estimating p by simulation 1000s

The estimation of p is a one-dimensional problem, where the advantage of low-discrepancy sequences is most pronounced. The world of finance provides a host ofmulti-dimensional problems of immense practical importance. A derivative is a finan-cial instrument whose value depends upon the evolution of the price of some under-lying asset. Estimating its current value by simulation requires calculating its hypo-thetical value for each realization, averaging and discounting back to the currenttime. In the case of a vanilla European option, the payoff of the derivative dependsonly on the price of the underlying asset at the maturity of the option. For an Asianoption, in contrast, the payoff of the derivative depends upon the average price overthe term of the option. In effect, estimating the value of an Asian option by simula-tion amounts to computing a multi-dimensional integral, with the number of dimen-sions equal to number of prices included in the average.

A Toolbox for Quasi-Random Simulation 19

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 20: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

Specifically, the payoff of an Asian option depends upon the average price S of theunderlying asset during the life of the option. For example, the payoff at maturity ofan average price call option is max S - K, 0, where K is the strike price. There are

two ways of calculating the average S - arithmetic and geometric.

A =1

m + 1S0 + S2 + … + Sm ¥ G = S0äS1ä… äSm

1

m+1

Arithmetic averaging is almost universal in practice. However, geometric averagingis more tractable; indeed, the value of a geometric Asian option is given by an analyt-ical formula. One of the most successful techniques for valuing arithmetic Asianoptions is simulation, using the known value of a corresponding geometric averageoption to reduce the simulation error. Consequently, geometric Asian option providea useful financial test bed for evaluating different simulation methods.

The following graph compares pseudo-random and quasi-random simulations of aone-year geometric average Asian option for varying sample sizes. In the left-handpanel, the number of dimensions s = 12, corresponding to monthly averaging. In theright-hand panel, s = 52 simulating weekly averaging. The axes are drawn at the truevalue. The law of large numbers ensures that simulated value will converge to thetrue value eventually. However, as we observe in this diagram, this convergence maybe very slow. In both cases, the quasi-random simulation (blue) convergences fasterthan the pseudo-random simulation (red), though the advantage erodes as the numberof dimensions increases. We find that the superiority of Sobol sequences in practicalapplications extends to higher dimensions than might be suggested by considerationof discrepancy alone. In this example, quasi-random simulation based on a Sobolsequence shows markedly better convergence than pseudo-random simulation, evenin a problem of 52 dimensions. Galanti and Jung (1997) report extensive compar-isons of pseudo- and quasi-random simulation in financial applications. Theyobserve that quasi-random simulation remains competitive with pseudo-random simu-lation up to at least 250 dimensions, which would correspond to daily averaging in aone-year option.

50000 100 000 150 000 200 000n

16.35

16.40

16.45

16.50

Values = 12

50000 100 000 150 000 200

16.55

16.60

16.65

16.75

16.80

16.85

Values = 52

Evaluation of a geometric Asian option

20 Michael Carter

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 21: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

à Selection of initial values

The preceding section emphasized that initial values must be selected cautiously.Sobol proposed Property A to guide the selection of initial values. To understandproperty A, consider the following diagram which shows the unit square divided into4 sub-squares. The blue points are four successive points in a Sobol sequence(starting at n = 64), and the red points are the next four points. In the left hand panel,we observe that the blue points belong to different sub-squares, as do the red points.This conforms with Property A. This is not the case in the right-panel, which isconstructed from analogous points in a sequence with unit initialization. The secondsequence does not satisfy Property A.

0 1

2

10

1

2

10

1

2 1

0

1

2

1

Standard initialization

0 1

2

10

1

2

10

1

2 1

Unit initialization

Generalizing to d dimensions, divide the hypercube 0, 1d into 2d equally-sizedsubcubes and partition a sequence of points in 0, 1d into blocks of 2dpoints. Thesequence satisfies Property A if each of the points in any block belongs to a differentsubcube. An analogous Property A' applies when each dimension is divided into quar-ters. These properties can be verified by evaluating determinants.

Bratley and Fox (1988) give initial values for 40 dimensions which are claimed tosatisfy Property A; Joe and Kuo (2003) extend this to 1111 dimensions. However,Property A is of limited value in high dimensions, since it is computationally infea-sible to use sufficient points to reap an advantage. To benefit from Property A in aproblem with 250 dimensions would require utilizing 2250 = 1075 points of thesequence, which is bigger than the estimated number of particles in the knownuniverse!

Joe and Kuo (2007) provide a set of initial values designed to minimize bad projec-tions between pairs of variables. They provide values for initial values for all polyno-mials up to degree 18 (21200 dimensions), and claim that they satisfy Property A upto 1111 dimensions. The implementation of Lemieux, Cieslak and Luttmer (2002)give values for 360 dimensions selected on the basis of an optimization. The British-Russian Offshore Development Agency (BRODA) - with which Sobol is affiliated -sell proprietary software to generate sequences with up to 1024 dimensions. Alterna-

A Toolbox for Quasi-Random Simulation 21

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 22: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

tively, Jäckel (2002) advocates a randomization procedure to select initial values inhigher dimensions.

Starting with version 6, Mathematica includes an option for producing Sobol andNiederreiter sequences as part of its random number generation facility. This comescourtesy of the Intel MKL libraries, which are available for Microsoft Windows (32-bit, 64-bit), Linux x86 (32-bit, 64-bit), and Linux Itanium systems. Specifics of theimplementation, such as choice of initial values, are not documented. Evaluation ofthis implementation in terms of discrepancy, projections and performance in applica-tion remains for future work.

à Acknowledgments

I gratefully acknowledge the very helpful comments of two anonymous referees. Thesection on primitive polynomials was inspired by Mathematica notebook on Primi-tive Polynomials Mod[2] by Ted Ersek.

à References

Antonov, I. A. and Saleev, V. M. (1979) "An economic method of computing LPtsequences." USSR Journal of Computational Mathematics and Mathematical Physics19: 252-256. (English translation)

Bratley, Paul and Bennett L. Fox (1988) "Algorithm 659: Implementing Sobol'squasirandom sequence generator." ACM Transactions on Mathematical Software 14,no. 1: 88-100.

Galanti, Silvio and Alan Jung (1997) "Low-discrepancy sequences: Monte Carlosimulation of option prices." Journal of Derivatives 5, no. 5: 63-83.

Glasserman, Paul (2003) Monte Carlo Methods in Financial Engineering. NewYork: Springer.

Joe, Stephen and Frances Y. Kuo (2003) "Remarks on algorithm 659: ImplementingSobol's quasirandom sequence generator." ACM Transactions on Mathematical Soft-ware 29, no. 1: 49-57.

Joe, Stephen and Frances Y. Kuo (2007) "Constructing Sobol' sequences with bettertwo-dimensional projections".

Jäckel, Peter (2002) Monte Carlo Methods in Finance. Chichester: Wiley.

Knuth, Donald (1981) The Art of Computer Programming Volume 2: SeminumericalAlgorithms. Second edition. Reading, MA: Addison-Wesley

Lemieux, Christiane, Mikolaj Cieslak, and Kristopher Luttmer (2002) RandQMCUser's Guide. University of Calgary

Morokoff, William J. and Russel E. Caflisch (1994) "Quasi-random sequences andtheir discrepancies." SIAM Journal on Scientific Computing 15: 1251-1279.

Press, William H., Saul A. Teukolsky, William T. Vetterling, and Brian P. Flannery(1992) Numerical Recipes in C: The Art of Scientific Computing. Cambridge:

22 Michael Carter

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08

Page 23: A toolbox for quasi-random simulationpu/seminar/17_11_2009_Paper.pdfA toolbox for quasi-random simulation ... Traditional Monte-Carlo simulation uses a pseudo-random grid, so the numerous

Cambridge University Press.

Siniksaran, Enis (2008) "Throwing Buffon's needle with Mathematica", Mathe-matica Journal, 11 (1)

à Appendix: The discrepancy package

To measure the discrepancy of pseudo- and quasi-random sequences, we provide asupplementary package implemented in C++. To utilize the discrepancy package in aWindows environment, place the executable file discrepancy.exe in an accessibledirectory. Install the package using the command

mlink Install"PATHdiscrepancy.exe"where PATH is either the full path of discrepancy.exe or its path relative to thecurrent Mathematica working directory. The current working directory can be foundby executing the function Directory[].

The package provides two functions MLDiscrepancySqd[X] and MLStarDiscrepancySqd[X] which measure respectively the ordinary discrepancy and the star discrep-ancy squared of the multidimensional sequence X . It is implicitly assumed that theelements of X belong to the unit hypercube 0, 1d . Because of the way in whichMathLink is implemented, it is necessary to ensure that the elements of the sequenceX are passed to these functions as real (e.g. 0.5) rather than as rational (e.g. 1/2)numbers. This can be achieved simply by applying the function N[] to the input, as isdone in the paper. The package will remain in memory and accessible to the Mathe-matica kernel until it is explicitly uninstalled with the command

UninstallmlinkTo use in a non-Windows environment, the package will need to be compiled for thetarget machine using the supplied source files Discrepancy.cpp and Discrepancy.tm.Please refer to the appropriate Mathematica C API Developer Guide for explicitinstructions on compiling under different operating systems.

A Toolbox for Quasi-Random Simulation 23

tmj-submission: [WR #1245952];Toolbox_Carter.nb7/18/08


Recommended