Forum Navigation: Select WHO'S ON: 08:23 PM General Forum Technical Forum Economics Forum Numerical Methods Forum Trading Forum The Quantitative Finance FAQs Proje... Student Forum Book And Research Paper Forum Programming and Software Forum The Quantitative Finance Code Libra... Careers Forum Events Board Brainteaser Forum Off Topic Forum and Website Bugs and Suggesti...

 new topic
 search
 bookshop
 jobs board
 news
 help
 file share
 audio visual
 articles
 blogs
 wiki
 forums
 home

 FORUMS > The Quantitative Finance FAQs Project < refresh >
 Topic Title: How can I simulate correlated random numbers? Created On Sun Jan 12, 03 07:30 PM Topic View: Branch View Threaded (All Messages) Threaded (Single Messages) Linear

 Pages: [ 1 2 >> Next ]

Paul
Senior Member

Posts: 5249
Joined: Jul 2001

Sun Jan 12, 03 07:30 PM

Alan
Senior Member

Posts: 7146
Joined: Dec 2001

Mon Jan 13, 03 03:25 AM

For standard normals, make two draws Z1 and Z2 from your
favorite (random normal) generator.
Then, use Z1 and Z3 = rho Z1 + Sqrt ( 1 - rho^2 ) Z2,
where rho is the desired correlation.

mj
Senior Member

Posts: 3403
Joined: Dec 2001

Mon Jan 13, 03 07:53 AM

If you want n random normals with correlation matrix C then find a matrix A such that

C = AA^{t}.

Now draw n independent normals W= (W_1,... W_n) and then put

Z = AW.

NB there lots of such A s.

MJ

-------------------------
More mathematical finance is now available from amazon and Barnes and Noble.

www.markjoshi.com/more

The second edition of Quant Job Interview Questions and Answers is now out.

danchikas
Member

Posts: 22
Joined: Jan 2002

Tue Feb 04, 03 10:36 AM

most widely used being the cholesky decomposition where A is a lower triangular matrix with positive diagonal elements.

someone on the forum mentioned a link which explicitly shows how to perform cholesky decomposition: http://ikpe1101.ikp.kfa-juelich.de/briefbook_data_analysis/node33.html

d.

reza
Senior Member

Posts: 3015
Joined: Aug 2001

Tue Feb 04, 03 12:05 PM

Cholesky is indeed one popular method using triangular decomposition
however many use a spectral method using matrix Diagonalization and argue the results are better
PJ is the expert ...

James
Senior Member

Posts: 1559
Joined: Jan 2002

Tue Feb 04, 03 03:19 PM

I was taught Cholesky in grad school, but Reza wrote "spectral method using matrix Diagonalization and argue the results are better"
I have no idea what this is, PJ or Reza, please explain....please?

-------------------------
"The good Christian should beware of mathematicians and all those who make empty prophecies. The danger already exists that mathematicians have made a covenant with the devil to darken the spirit and confine man in the bonds of Hell." -- St. Augustine

reza
Senior Member

Posts: 3015
Joined: Aug 2001

Tue Feb 04, 03 03:30 PM

again the expert id PJ
but if you just replace the decmposition of the covariance matrix into triangular matrices with
diagonalization you could do the same thing, no?
x = X
y= rX + sqrt(1-r^2) Y
you would have something like
x= aX+bY
y= cX+dY

kr
Senior Member

Posts: 1887
Joined: Sep 2002

Tue Feb 04, 03 08:33 PM

James -
I'm guessing the spectral approach is as follows: Write M = ADA^-1. Take sqrts of the diagonal elements and call that S i.e. D = SS. Then M = ASA^-1 . ASA^-1. If A is orthonormal by construction (i.e. it is orthogonal by construction and we took the 'ovals' out by using D), then A^-1 = A^T. S=S^T also, so if C = ASA^-1 then M=CC^T as well.

-------------------------
Fools!
I'm Nonius!!!!

kr
Senior Member

Posts: 1887
Joined: Sep 2002

Tue Feb 04, 03 08:36 PM

i am guessing that the performance is improved because the A's are orthonormal and hence behave well when multiplied by a vector of normal random variates... all the magnification / compression is inside S, which is safely diagonal.

-------------------------
Fools!
I'm Nonius!!!!

James
Senior Member

Posts: 1559
Joined: Jan 2002

Wed Feb 05, 03 09:21 AM

Thanks Reza & kr, I am going to try this, and will be back for more advice if i screw it up (p=100%).

-------------------------
"The good Christian should beware of mathematicians and all those who make empty prophecies. The danger already exists that mathematicians have made a covenant with the devil to darken the spirit and confine man in the bonds of Hell." -- St. Augustine

mj
Senior Member

Posts: 3403
Joined: Dec 2001

Thu Feb 06, 03 02:18 PM

One issue is the performance of low-discrepancy numbers.

If you take low discrepancy numbers that work better in low dimensions than in high ones (this is true of all low-discrepancy numbers of which I am aware,) then you want the low dimensions to do more work.

Spectral pseudo-square rooting is one way to achieve this. For ordinary pseudo-randoms it shouldn't make any difference to the convergence rate.

Additionally, some people prefer the spectral method for numerical stability reasons.

The method is write

C = PDP^{t}

with P orthogonal and D diagonal. Let D^{1/2} be D with the elements square-rooted.

Put A = PD^{1/2}.

MJ

-------------------------
More mathematical finance is now available from amazon and Barnes and Noble.

www.markjoshi.com/more

The second edition of Quant Job Interview Questions and Answers is now out.

WaaghBakri
Senior Member

Posts: 732
Joined: Mar 2002

Sat Feb 08, 03 06:32 AM

A naive question ...... to create n correlated or independent RV's, must we worry about non-sequential drawing that results when we use the same generator? Or equivalently, if I choose every nth. sample from a single stream output from a random number generator, will I ruin the random number generators properties?

sloth
Junior Member

Posts: 7
Joined: Feb 2002

Thu Feb 13, 03 03:46 PM

The whole discussion on this topic so far has been concerned with normal distributions.

More generally, you might want to simulate correlated numbers from an arbitrary collection of marginal distributions.

This is the basic problem that insurance companies face all the time: estimating their total p+l distribution, when the individual parts of their business (different classes of insurance, investments, and so on) are correlated, and have weird and wonderful marginal distributions.

The only 'derivatives' application I know is for modelling portfolios of weather derivatives, some of which may have very non-normal distributions (e.g. the number of days it snows in winter).

Even given the correlations, there is no unique answer, unlike for the normal case.

The standard method used in practice is due to Iman and Connover.

My understanding of it is that it works as follows:
1)calculate rank correlations
2)convert them to linear correlations using a cunning formula
3)simulate (using Choleski or SVD) from a multivariate normal with these correlations
4)convert the normally distributed simulations to the right marginal distributions using the CDF of the normal distribution and the inverse CDF of the marginal distribution.

To go further than this, you could start looking at copulas.

Sloth

Mano
Member

Posts: 87
Joined: Oct 2001

Wed Feb 26, 03 12:18 PM

I think that to generate correlated multivariate normal random variables, one would do the Cholesky or Spectral method on the CORRELATION matrix. Some people here talk about the COVARIANCE matrix.

Will using the Covariance matrix (X*sqrt(t), where X is N(0,1)) be same as using the correlation matrix and then multiplying by the individual volatilities (sigma*Z*sqrt(t))

mj
Senior Member

Posts: 3403
Joined: Dec 2001

Wed Feb 26, 03 04:08 PM

why do two mults when you can get away with one.

MJ

-------------------------
More mathematical finance is now available from amazon and Barnes and Noble.

www.markjoshi.com/more

The second edition of Quant Job Interview Questions and Answers is now out.

challenged
Member

Posts: 55
Joined: Feb 2003

Thu Feb 27, 03 12:00 AM

There is a VBA example for use in excel at?

http://www.geocities.com/WallStreet/9245/vba11.htm

bluesea
Junior Member

Posts: 10
Joined: Dec 2002

Sun Nov 09, 03 05:17 AM

I have such topic this quarter and what my instructors equation is X=chol(cov())*randn()+Mu()
I have no idea why it is the product of chol, not directly of covariance? Cholesky decoposition remain the properties of the original covariance?
and what is the second term in your folks description(Sqrt ( 1 - rho^2 ) Z2), its the same to the one of mine(Mu)? I also wonder if it converts the mean properties to the X with such addition.

Hai

-------------------------
Seek brightness

Junior Member

Posts: 13
Joined: Nov 2003

Wed Nov 12, 03 06:12 AM

Quote

Originally posted by: bluesea
I have such topic this quarter and what my instructors equation is X=chol(cov())*randn()+Mu()
I have no idea why it is the product of chol, not directly of covariance? Cholesky decoposition remain the properties of the original covariance?
and what is the second term in your folks description(Sqrt ( 1 - rho^2 ) Z2), its the same to the one of mine(Mu)? I also wonder if it converts the mean properties to the X with such addition.

Hai

You can do the math ... If x = sqrt(var)*randn(), then x~N(0,var). Likewise, if X=chol(cov())*randn(), then X ~N(0, Cov()). You can think of chol as a square root function for matrix.

bluesea
Junior Member

Posts: 10
Joined: Dec 2002

Thu Nov 13, 03 06:59 AM

Thank you!

-------------------------
Seek brightness

xyzyang
Junior Member

Posts: 4
Joined: Feb 2004

Thu Feb 12, 04 04:26 PM

A more challenging question on how to generate correlated random nubmers.
From the discussion it is quite simple, at least theoretically, to generate correlated random numbers in N(0,1), Chol would suffice.
In my work, we need to generate correlated random numbers that also correlated to a given set of random numbers.

For specifically, we have a set of random numbers x1, x2, x3, (say just 3 to make it simple), that could be from history. We can not
or do not want to, change them. The question is to find y1, y2, y3, y4 ( 4 is not equal to 3), such as x1, x2, x3, y1, y2, y3, y4 satisfy
certain variance-covariance matrix, say, A. Let's analyze it a little more. A must be a 7 by 7 matrix (positive defnite). We also notice
that x1, x2, x3 are fixed, we can not generate them any more, so the upper left submatrix (3 by 3) of A is exactly the variance
covariance matrix of x1, x2, x3. Then A is decompose into A = (A11, A12; A21, A22). A22 is the variance covariance matrix of y1, y2, y3, y4
while A12 is the correlation matrix of X's and Y's. That is great, so far.
Now the problem is:
1. design a algorithm to solve for and simulate y1, y2, y3, y4, prove it theoretically correct
2. practical issue. I have not seen any algorithm or programs that give me truly independent random numbers.
not sure if any body has one ---- if you do, please share.
3. as the sizes increase, that is, not 3 or 4, instead, N and M, it quickly become a challenge to see the number of
simulations we have to do in order to truly get what we expected
Any good ideas?

Thanks
XYZ