Serving the Quantitative Finance Community

 
User avatar
iamOZ
Topic Author
Posts: 0
Joined: June 19th, 2004, 4:32 pm

Non-Randomness in random number generation

June 26th, 2004, 12:57 am

Hi all, I try to simulate the stock prices for Monte Carlo simulation, and I use Box-Muller transformation for my (random) normally distributed number. However, when I plug in the same set of input parameter (i.e. same sigma, r,T,...), I obtain the same set of number 9 out of 10 times!!!! This means that the set of random number is actually not random!! Does anyone know what is the cause of this problem?Cheers,OZ
 
User avatar
silverside
Posts: 1
Joined: January 28th, 2003, 9:57 pm

Non-Randomness in random number generation

June 26th, 2004, 7:54 am

1) You should be happy that there are no hidden patterns in your random number generator. This may mean replacing the random number generator built into your system with another one such as the Mersenne Twister.2) Random number generators need to be initialised or 'seeded'. If the same seed is used each time, then they will produce the same set of numbers. This can be useful for testing purposes, but if you don't want that, reseed each time, using something like the system clock.3) Some people don't like the Box-Muller transformation as it can expose tiny patterns in a random number generator, and prefer to invert the normal CDF directly to convert uniform deviates to normal deviates.
 
User avatar
Graeme
Posts: 7
Joined: April 25th, 2003, 5:47 pm

Non-Randomness in random number generation

June 26th, 2004, 9:09 am

I you are using the uniform random number generator in microsoft (=rand() or rnd()), that may be one of your major problems. IT SUCKS. Use pseudo random numbers, such as Sobol sequences, instead. There is free stuff on the internet for Sobol. Quantlib and BRODA aretwo examples.
 
User avatar
reza
Posts: 6
Joined: August 30th, 2001, 3:40 pm

Non-Randomness in random number generation

June 26th, 2004, 2:41 pm

there is this "seed" conceptif you don't change that you will get exactly the same sequencebut that doesn't mean that the sequence is badafter all low descrepency numbers are completely known in advancebut they fill the space in a uniform way
 
User avatar
grabben
Posts: 2
Joined: August 23rd, 2002, 12:47 pm

Non-Randomness in random number generation

June 28th, 2004, 6:22 am

iamOZ, I agree with Graeme's conclusion that quasi random sequences (such as Sobol) are better than pseudo random (such as =rand() or rnd()), however I generally think they are more difficult to implement, as they generally can't be used for creating timeseries (using the standard Euler extrapolation, but require Brownian bridges, etc).I think silverside and reze are on the right track. If you get the same number 9 out of 10 times, you are probably seeding the RNG with some number, but then call the RNG with out any number or with a constant value. Some RNG's are built to require the latest random number, i.e. need to be called as:For i = 1 to n r = rnd(r) S = ...Next iAnnother common error I have seen is that the call to the RNG is done outside the loop, i.e.:r = rnd(r)For i = 1 to n S = ...Next iDon't want to imply that you are incapable of detecthing such a simple error, but still, I've learnt that it is often safest to check all bases, and as this is such a common error, I thought I would mention it all the same.
 
User avatar
David
Posts: 2
Joined: September 13th, 2001, 4:05 pm

Non-Randomness in random number generation

June 29th, 2004, 1:37 pm

In terms of entropy, how would you estimate this generator? (Try it out. It's free)
Last edited by David on June 28th, 2004, 10:00 pm, edited 1 time in total.
 
User avatar
gjlipman
Posts: 5
Joined: May 20th, 2002, 9:13 pm

Non-Randomness in random number generation

June 29th, 2004, 8:12 pm

I have been doing some monte carlo simulations in excel: I generate 11 random numbers (unform), stick them into a model, and then see the output. I started off using excel's rnd() function, but noticed that I often got the same set of 11 random numbers. So I stayed using the rnd() function, but I reseeded off the timer before every random number. I now don't get any repeats, and my combinations are evenly spread. I realise that technically speaking my numbers still aren't random, but I can't see anything wrong with my results - can anyone see anything wrong with this method?
 
User avatar
cvz
Posts: 0
Joined: January 7th, 2003, 9:20 pm

Non-Randomness in random number generation

June 30th, 2004, 8:13 pm

Interesting anecdote about the perils of forgetting to change your RNG seed:QuoteOne of gambling's great folk tales comes out of the Casino de Montreal--and it's entirely true. It is the case of a young computer whiz who, shortly after the casino opened, noticed something unusual about the keno game there. According to Andre Loubier, who currently runs the casino in Charlevoix, the fellow kept careful records of the keno numbers and fed the information into his own computer. Soon, the computer whiz observed that numbers were coming up in a predictable sequence. The astute player turned that gold-plated information into three jackpots totaling more than $600,000 before the casino called time-out and started sorting out what was happening. After all, the numbers were supposed to be drawn in an unpredictable pattern by a Random Number Generator. However, it seemed that a janitorial worker was pulling the plug on the RNG to plug in his vacuum cleaner at night. That power interruption reset the RNG's internal clock, which in turn controlled the numbers. The reset clock returned to the beginning of the sequence and generated a predictable pattern when it started operating once again.I remember when the story broke there were headlines such as "Genius Beats Casino with Chaos Theory." Unfortunately, the truth was a little more banal.
Last edited by cvz on June 29th, 2004, 10:00 pm, edited 1 time in total.