Serving the Quantitative Finance Community

 
User avatar
stirlitz
Topic Author
Posts: 0
Joined: August 13th, 2002, 11:57 am

Simulating Multivariate Distribution

July 11th, 2005, 2:22 pm

Hi All Experts out there,I am doing a monte-carlo. I need to simulate several random variables which are correlated. I have estimated a correlation matrix.I also have means and volatilities of the individual random variables.I am looking for a piece of computer code (math algorithm, in C++ or VBA) that would generate correlated random variables.From past life in linear algebra and stats, I remember something about eigenvalues of the var-covar mx, but I am in a total hazehow to apply this (it was so long ago... I should have read my books at school).Anyway - is it a trivial problem for some of you?Can you suggest a solution?ThanksStiz
 
User avatar
Antonio
Posts: 8
Joined: June 30th, 2004, 3:13 pm
Location: Imperial College London
Contact:

Simulating Multivariate Distribution

July 11th, 2005, 3:15 pm

There have been many threads on this topic. TypeCholesky in the search form and you will find your answer.
 
User avatar
chiranjiv
Posts: 2
Joined: July 14th, 2002, 3:00 am

Simulating Multivariate Distribution

July 11th, 2005, 3:44 pm

Quick Google Search + Quick hacking produced this one. In the first prompt use mouse to select the corr matrix. There is lot of scope for improvement e.g. routines to "correct" the corr. matrix/better random number genetaion/faster eigen vlaues.. For that use Wilmott threads and Peter Jaeckel's book!!Ciao!!
Attachments
Monte Carlo1.ZIP
(82.72 KiB) Downloaded 100 times
 
User avatar
umpbumpfizz
Posts: 0
Joined: June 10th, 2005, 12:57 pm

Simulating Multivariate Distribution

July 12th, 2005, 4:28 am

hi,use copula to generate correlated random number. any copula will do ir.for example if u have to generate correlated uniform random numbers follow the following steps-suppose correlation matrix is R and we r using gaussian copula-1) Find any suitable decomposition of R( say cholesky) R=AA'2) draw z n dimension random vector from uncorrelated standard normal distribution.3) x=z'A4)u=phi(x); phi is norm distu is n dimensional correlated unifor numbers
 
User avatar
stirlitz
Topic Author
Posts: 0
Joined: August 13th, 2002, 11:57 am

Simulating Multivariate Distribution

July 13th, 2005, 9:39 am

Thanks everybody.Particularly, thanks Chiranjiv for the VBA code. I tried it, and with enough simulations the simulated random variables have the correlation matrix close to the original.Two further questions on the file:(a) is there a limit on the size of the corr. matrix?(b) is the code using the Excel random number generator?Thx, Stiz
 
User avatar
QGenius
Posts: 0
Joined: July 4th, 2005, 6:13 pm

Simulating Multivariate Distribution

July 13th, 2005, 10:48 am

umpbumpfizz : your vector x will indeed have the desired corr. matrix R, but how about u ? this is the vector for which we want the desired R!
 
User avatar
chiranjiv
Posts: 2
Joined: July 14th, 2002, 3:00 am

Simulating Multivariate Distribution

July 13th, 2005, 3:20 pm

Hi Stiz,To answer to ur questions..1) There is no upper limit on the size of the correl matrix...but with bigger matrices you might see the programme take much longer to run...2) Yes, it uses VBA's RND function to generate Uniform Random numbers which it then converts to Normal Variates..if you are unhappy with it..consider using this implementation of Mersenne Twister Mersenne Twister in VBABonne Chance!!Manu
Last edited by chiranjiv on July 12th, 2005, 10:00 pm, edited 1 time in total.