SERVING THE QUANTITATIVE FINANCE COMMUNITY

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

Creating matrices of random numbers without their 'sticking'

March 12th, 2007, 1:59 pm

let's say I wihs to create a matrix of Rns; the rows correspond to a single path in MC simulation and the full matrix contains all the paths based on so many simulations. Question: what's the best way in the sense that; - each path is independent of the others? - the paths don't give the same nunmbers? I use rand(), RAND_MAX and srand() (basic and not really random, I know but will change it later)I have it running but sometimes the numbers from one path to the next are the same.
http://www.datasimfinancial.com
http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself
Jean Piaget
 
User avatar
quartz
Posts: 424
Joined: June 28th, 2005, 12:33 pm

Creating matrices of random numbers without their 'sticking'

March 12th, 2007, 3:55 pm

Quote"If you want a good plain non-low-discrepancy random number generator, you should use the ones in Numerical Recipes in C/C++"Albeit that being a nice one, the current state of the art for simulation (with code online) is probably WELL (and relatives like Hearty Twister/PMT), an improved child of the Mersenne Twister.But yeah, here careful initialization requires some effort so it's not that straightforward to use in parallel.Getting back to the topic: if srand comes only once for matrix then it's a really odd result, otherwise what's being used for feeding it? Obviously a timer/IO-based feed should never be used twice in a run, but alternative schemes still must be crafted with an eye to the specific generator used.
Last edited by quartz on March 11th, 2007, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Topic Author
Posts: 61168
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Creating matrices of random numbers without their 'sticking'

March 12th, 2007, 5:18 pm

Thanks for the links guys.We use MT at the moment. The RNG is in a separate component so improvements can take place locally. The seed seems to be the probem and I suspect a small bug in the code. QuoteObviously a timer/IO-based feed should never be used twice in a run, Ok, it has disasterous effects. But in a matrix case// srand()??for (i = 1...NSIMULATIONS){ // //srand()?? for (j = 1...NTIMESTEPS) { //srand()?? // calc path info }}where is the most appropriate place?
Last edited by Cuchulainn on March 11th, 2007, 11:00 pm, edited 1 time in total.
http://www.datasimfinancial.com
http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself
Jean Piaget
 
User avatar
zeta
Posts: 1952
Joined: September 27th, 2005, 3:25 pm

Creating matrices of random numbers without their 'sticking'

March 12th, 2007, 7:19 pm

QuoteWhat you shoudnt do is call srand multiple times in your program! bingo. Mersenne twister for a 64 bit machine has a huge period -> 2^19937-1. I take advantage of this by generating *once* all the numbers needed for the remainder of the code. THere's a new algo here, twice as fast as the previous
 
User avatar
Cuchulainn
Topic Author
Posts: 61168
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Creating matrices of random numbers without their 'sticking'

April 8th, 2007, 1:38 pm

Question:One way to generate normal random numbers is using an application of CLT:N = U1 + U2 + .... + Un - n/2take n = 12 is good enough?What is wrong with this if I don't case about 1) tails 2) possible performance degradation
http://www.datasimfinancial.com
http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself
Jean Piaget
 
User avatar
Traden4Alpha
Posts: 23951
Joined: September 20th, 2002, 8:30 pm

Creating matrices of random numbers without their 'sticking'

April 8th, 2007, 3:32 pm

Ignoring the clipped tails and performance issues, I see two minor issues. First, you also need to normalize to get standard deviation = 1. Second, you'll "use up" random numbers 12X faster (a minor issue if the period is long enough).
 
User avatar
quantmeh
Posts: 5974
Joined: April 6th, 2007, 1:39 pm

Creating matrices of random numbers without their 'sticking'

April 8th, 2007, 3:42 pm

QuoteOriginally posted by: CuchulainnWhat is wrong with this if I don't case about 1) tails 2) possible performance degradationone thing to consider is: how well was this studied? i havent used this method myself.you may not like linear congruental methods, but they were studied extensively. there's a lot of papers on their spectral and other characteristics. generating gaussian randoms with your method is not used much for reasons including performance issues. it may happen that there's not much research on suitability of this method to your problem. i would suggest you to look at random.org web site. there are similar services, which generate ''true" random numbers from physical sources, like radiowaves. they have APIs to different languages. i used their Java API, it works like a charm. there's also a brief research of the characteristics of their numbers. you can use uniformly distributed numbers from random.org to generate gaussian sequences using a standard trigonometric method.
 
User avatar
Cuchulainn
Topic Author
Posts: 61168
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Creating matrices of random numbers without their 'sticking'

April 8th, 2007, 4:42 pm

This method is well-known and documented in the finance literature and it is mentioned in Hammersley and Handscomb 1964. It is based on the Central Limit Theorem which is reassuring. Quoteyou may not like linear congruental methods, but they were studied extensivelyI am a user and am considering all possibilities. With these generators I wish to use the numbers that are correlated, so they should be random. A guess is the CLT method gives more representative results thans LCM which is indeed a kind of difference scheme, yes??Quoteyou can use uniformly distributed numbers from random.org to generate gaussian sequences using a standard trigonometric method. Is this the Box Muller you use?I had a look at the site; how do I access the data? API?
Last edited by Cuchulainn on April 7th, 2007, 10:00 pm, edited 1 time in total.
http://www.datasimfinancial.com
http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself
Jean Piaget
 
User avatar
Cuchulainn
Topic Author
Posts: 61168
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Creating matrices of random numbers without their 'sticking'

April 8th, 2007, 5:26 pm

QuoteOriginally posted by: Traden4Alpha First, you also need to normalize to get standard deviation = 1. Second, you'll "use up" random numbers 12X faster (a minor issue if the period is long enough).With N = 12 we get indeed a standard N(0,1) since var(U) = 1/12. For other values we normalise by 12/n?
http://www.datasimfinancial.com
http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself
Jean Piaget
 
User avatar
quantmeh
Posts: 5974
Joined: April 6th, 2007, 1:39 pm

Creating matrices of random numbers without their 'sticking'

April 8th, 2007, 5:26 pm

QuoteOriginally posted by: CuchulainnThis method is well-known and documented in the finance literature and it is mentioned in Hammersley and Handscomb 1964. It is based on the Central Limit Theorem which is reassuring. I didnt use it, 'cause it seemed to have to be slow. I would think that CLT works here only if your uniform generators aren't too bad. If you have a deficient uniform RNG, then sum their values to form Gaussian wouldn't be that good either, imho. again, i dont know much about this method, anyways.QuoteIs this the Box Muller you use?yes, one of its versions. it's described in Knuth's TAOCP 2nd volume.QuoteI had a look at the site; how do I access the data? API?huh.. apparently, they changed everything since I used them last time! there used to be a link to clients in Java, C etc. Now it's gone, and the whole server is "beta" plus they have "quotas". I wonder if they are going to commercialize this service. i'll figure out what happened.in the mean time, there are other true random number services, such as LavaRnd. they are actually listed in http://random.org/randomness/ page
 
User avatar
Cuchulainn
Topic Author
Posts: 61168
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Creating matrices of random numbers without their 'sticking'

April 8th, 2007, 5:34 pm

QuoteI didnt use it, 'cause it seemed to have to be slow. I would think that CLT works here only if your uniform generators aren't too bad. If you have a deficient uniform RNG, then sum their values to form Gaussian wouldn't be that good either, imhoOn the other hand, very fast methods that give wong answers are also not good. Performance: we should benchmark but these days we could use some super-duper hardware.I am assuming the Uniforms are reliable, otherwise it is GIGO.And we can use these numbers as well?10^6 random numbers
Last edited by Cuchulainn on April 7th, 2007, 10:00 pm, edited 1 time in total.
http://www.datasimfinancial.com
http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself
Jean Piaget
 
User avatar
quantmeh
Posts: 5974
Joined: April 6th, 2007, 1:39 pm

Creating matrices of random numbers without their 'sticking'

April 8th, 2007, 7:46 pm

Ok, I found my old link to a Java client for random.org service, it's at http://www.cs.duke.edu/csed/talks/stone ... Org.javaIt uses a very simple HTTP interface to random.org, which is described on their web site. Alos, it's easy to figure it out just by looking at the Java code.cheers!
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