SERVING THE QUANTITATIVE FINANCE COMMUNITY

outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

### Re: Using Quantlib

up to boots 1.55 it was box muller,
http://www.boost.org/doc/libs/1_55_0/bo ... bution.hpp

in 1.56 and onwards it's Ziggurat indeed (look at the table!).
http://www.boost.org/doc/libs/1_65_0/bo ... bution.hpp

..and some refinement after that.

Cuchulainn
Topic Author
Posts: 62171
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Using Quantlib

up to boots 1.55 it was box muller,
http://www.boost.org/doc/libs/1_55_0/bo ... bution.hpp

in 1.56 and onwards it's Ziggurat indeed (look at the table!).
http://www.boost.org/doc/libs/1_65_0/bo ... bution.hpp

..and some refinement after that.
BM suffers from Neave effect (See Jaeckal's book). Yikes, up to 1,56.
Glasserman suggests Newton to compute N(0,1) and it must be one off the easiest problems in the history of mankind to solve. I tried it and Banach fixed point iieration + Aitken acceleration for fun and they worked OK (of course, edge conditions need to be taken into consideration ...)
So, which algo does std use?

Q: Is Ziggurat a statistician's ingenious way to solve a  numerical problem?

outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

### Re: Using Quantlib

I've never seen anyone use Newton: there is an optimum to be found w.r.t speed and accuracy (of the density), do you know how it rank against BM and Ziggurat wrt speed and accuracy?

There is no "std" implementation / algorithm!

Each compiler vendor is allowed to do as they wish as long as they adhere to the requirements specified by the C++ commision. There is no required algorithm there, only "A normal_distribution random number distribution produces random numbers x distributed according to the probability density function p(x,mu,sigma) = ..."

Visual Studio e.g. used the n=16 Irwin Hall distribution approximation.

GCC seems to use the polar form of the Box Muller, here is a snippet for the SSE version that does 4 in parallel
https://github.com/gcc-mirror/gcc/blob/ ... t_random.h

outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

### Re: Using Quantlib

I bet you can inspect what VS does (it's closed source)  by comparing the intergers that go in vs the normal variates that come out..

Cuchulainn
Topic Author
Posts: 62171
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Using Quantlib

I only seen NR from Paul Glasserman. And it converges in ~ 2 iterations. I'm reading up Ziggurat, will come back to this. It uses rejection, so is convergence deterministic?

outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

### Re: Using Quantlib

QuantLib also uses BM looking at this link

https://github.com/lballabio/QuantLib/b ... ianrng.hpp

Cuchulainn
Topic Author
Posts: 62171
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Using Quantlib

I want to compare apples and apples, so is this setup good to have Boost and C++11 in the same "starting block"? If yes, then I can run MC; if not what is a better way to compare?
std::random_device rd;
auto state = rd();

boost::mt19937 mt;
mt.seed(state);

boost::normal_distribution<> distribution(0.0,1.0);
boost::variate_generator<boost::mt19937&, boost::normal_distribution<>>
normal(mt, distribution);

std::mt19937 dre;
dre.seed(state);
std::normal_distribution<double> nor(0.0, 1.0);

// Get rid of fluff
dre.discard(2000000);

outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

### Re: Using Quantlib

Yes, rejection doesn't say anything about convergence or not.

It's only a problem with special number and methods like low discrepancy sequences.

outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

### Re: Using Quantlib

That correct, should give the same results.

There is no fluff in MT, you can skip that, especially since your already seeding.

Cuchulainn
Topic Author
Posts: 62171
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Using Quantlib

That correct, should give the same results.

There is no fluff in MT, you can skip that, especially since your already seeding.
OK will do the following: compute put (20 times) Boost vs C++11 and compare values for NSIM = 10^6 and NT = 500.
A good test?

outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

### Re: Using Quantlib

That correct, should give the same results.

There is no fluff in MT, you can skip that, especially since your already seeding.
OK will do the following: compute put (20 times) Boost vs C++11 and compare values for NSIM = 10^6 and NT = 500.
A good test?
Yes, and the use the std of the 20 runs to test if the two means are more than 3std appart?

outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

### Re: Using Quantlib

Or deviate from the true analytical value? Do you have that?

Cuchulainn
Topic Author
Posts: 62171
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Using Quantlib

QuantLib also uses BM looking at this link

https://github.com/lballabio/QuantLib/b ... ianrng.hpp
Quote
1. Box-Muller transform – was listed above, and is relatively simple to implement. If you need very precise samples however, be aware that the Box-Muller transform combined with some uniform generators suffers from an anomaly called Neave Effect.
H. R. Neave, “On using the Box-Muller transformation with multiplicative congruential pseudorandom number generators,” Applied Statistics, 22, 92-97, 1973

outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

### Re: Using Quantlib

..and since the MT engines are identical (apart from speed) you'll be testing for statistical bias of functions (paths, payoffs) of the boost ziggurat normal distribution vs de unknown VS std version.

Right?

outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

### Re: Using Quantlib

QuantLib also uses BM looking at this link

https://github.com/lballabio/QuantLib/b ... ianrng.hpp
Quote
1. Box-Muller transform – was listed above, and is relatively simple to implement. If you need very precise samples however, be aware that the Box-Muller transform combined with some uniform generators suffers from an anomaly called Neave Effect.
H. R. Neave, “On using the Box-Muller transformation with multiplicative congruential pseudorandom number generators,” Applied Statistics, 22, 92-97, 1973
Does QL offer more alternatives, eg like ziggurat (besides inverse cdf?)