SERVING THE QUANTITATIVE FINANCE COMMUNITY

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

Re: Using Quantlib

December 19th, 2017, 10:14 pm

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.
 
User avatar
Cuchulainn
Topic Author
Posts: 59949
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Using Quantlib

December 20th, 2017, 10:30 am

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?
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 20th, 2017, 11:00 am

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
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 20th, 2017, 11:04 am

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..
 
User avatar
Cuchulainn
Topic Author
Posts: 59949
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Using Quantlib

December 20th, 2017, 11:08 am

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?
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 20th, 2017, 11:10 am

QuantLib also uses BM looking at this link

https://github.com/lballabio/QuantLib/b ... ianrng.hpp
 
User avatar
Cuchulainn
Topic Author
Posts: 59949
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Using Quantlib

December 20th, 2017, 11:10 am

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
 mt.discard(2000000);
 dre.discard(2000000);
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 20th, 2017, 11:11 am

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

It's only a problem with special number and methods like low discrepancy sequences.
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 20th, 2017, 11:15 am

That correct, should give the same results.

There is no fluff in MT, you can skip that, especially since your already seeding.
 
User avatar
Cuchulainn
Topic Author
Posts: 59949
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Using Quantlib

December 20th, 2017, 11:19 am

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?
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 20th, 2017, 11:36 am

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?
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 20th, 2017, 11:37 am

Or deviate from the true analytical value? Do you have that?
 
User avatar
Cuchulainn
Topic Author
Posts: 59949
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Using Quantlib

December 20th, 2017, 11:41 am

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
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 20th, 2017, 11:43 am

..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?
 
User avatar
outrun
Posts: 4573
Joined: April 29th, 2016, 1:40 pm

Re: Using Quantlib

December 20th, 2017, 11:44 am

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?)
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...


GZIP: On