Forum Navigation:

magazine

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:

Pages: [ 1 2 >> Next ]
View thread in raw text format


Paul
Senior Member

Posts: 5421
Joined: Jul 2001

Sun Jan 12, 03 07:30 PM
User is offline View users profile

 
Reply
   
Quote
   
Top
   
Bottom
     



Alan
Senior Member

Posts: 7532
Joined: Dec 2001

Mon Jan 13, 03 03:25 AM
User is offline View users profile

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.
 
Reply
   
Quote
   
Top
   
Bottom
     



mj
Senior Member

Posts: 3422
Joined: Dec 2001

Mon Jan 13, 03 07:53 AM
User is offline View users profile

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


-------------------------
Course on Kooderive -- GPU programming with 100 times speed up in February 2015. www.markjoshi.com
 
Reply
   
Quote
   
Top
   
Bottom
     



danchikas
Member

Posts: 22
Joined: Jan 2002

Tue Feb 04, 03 10:36 AM
User is offline

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.
 
Reply
   
Quote
   
Top
   
Bottom
     



reza
Senior Member

Posts: 3015
Joined: Aug 2001

Tue Feb 04, 03 12:05 PM
User is offline View users profile

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 ...
 
Reply
   
Quote
   
Top
   
Bottom
     



James
Senior Member

Posts: 1559
Joined: Jan 2002

Tue Feb 04, 03 03:19 PM
User is offline View users profile

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
 
Reply
   
Quote
   
Top
   
Bottom
     



reza
Senior Member

Posts: 3015
Joined: Aug 2001

Tue Feb 04, 03 03:30 PM
User is offline View users profile

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?
instead of
x = X
y= rX + sqrt(1-r^2) Y
you would have something like
x= aX+bY
y= cX+dY
 
Reply
   
Quote
   
Top
   
Bottom
     



kr
Senior Member

Posts: 1887
Joined: Sep 2002

Tue Feb 04, 03 08:33 PM
User is offline

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!!!!
 
Reply
   
Quote
   
Top
   
Bottom
     



kr
Senior Member

Posts: 1887
Joined: Sep 2002

Tue Feb 04, 03 08:36 PM
User is offline

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!!!!
 
Reply
   
Quote
   
Top
   
Bottom
     



James
Senior Member

Posts: 1559
Joined: Jan 2002

Wed Feb 05, 03 09:21 AM
User is offline View users profile

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
 
Reply
   
Quote
   
Top
   
Bottom
     



mj
Senior Member

Posts: 3422
Joined: Dec 2001

Thu Feb 06, 03 02:18 PM
User is offline View users profile

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




-------------------------
Course on Kooderive -- GPU programming with 100 times speed up in February 2015. www.markjoshi.com
 
Reply
   
Quote
   
Top
   
Bottom
     



WaaghBakri
Senior Member

Posts: 732
Joined: Mar 2002

Sat Feb 08, 03 06:32 AM
User is offline View users profile

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?

 
Reply
   
Quote
   
Top
   
Bottom
     



sloth
Junior Member

Posts: 7
Joined: Feb 2002

Thu Feb 13, 03 03:46 PM
User is offline View users profile

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




 
Reply
   
Quote
   
Top
   
Bottom
     



Mano
Member

Posts: 87
Joined: Oct 2001

Wed Feb 26, 03 12:18 PM
User is offline View users profile

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))


 
Reply
   
Quote
   
Top
   
Bottom
     



mj
Senior Member

Posts: 3422
Joined: Dec 2001

Wed Feb 26, 03 04:08 PM
User is offline View users profile

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

MJ


-------------------------
Course on Kooderive -- GPU programming with 100 times speed up in February 2015. www.markjoshi.com
 
Reply
   
Quote
   
Top
   
Bottom
     



challenged
Member

Posts: 55
Joined: Feb 2003

Thu Feb 27, 03 12:00 AM
User is offline

There is a VBA example for use in excel at?

http://www.geocities.com/WallStreet/9245/vba11.htm
 
Reply
   
Quote
   
Top
   
Bottom
     



bluesea
Junior Member

Posts: 10
Joined: Dec 2002

Sun Nov 09, 03 05:17 AM
User is offline View users profile

searching choleskey decomposition in google lead me to this page.
I have such topic this quarter and what my instructor`s 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), it`s the same to the one of mine(Mu)? I also wonder if it converts the mean properties to the X with such addition.

I appreciate your all inputs.

Hai

-------------------------
Seek brightness
 
Reply
   
Quote
   
Top
   
Bottom
     



nastradamus
Junior Member

Posts: 13
Joined: Nov 2003

Wed Nov 12, 03 06:12 AM
User is offline

Quote

Originally posted by: bluesea
searching choleskey decomposition in google lead me to this page.
I have such topic this quarter and what my instructor`s 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), it`s the same to the one of mine(Mu)? I also wonder if it converts the mean properties to the X with such addition.

I appreciate your all inputs.

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.
 
Reply
   
Quote
   
Top
   
Bottom
     



bluesea
Junior Member

Posts: 10
Joined: Dec 2002

Thu Nov 13, 03 06:59 AM
User is offline View users profile

Thank you!

-------------------------
Seek brightness
 
Reply
   
Quote
   
Top
   
Bottom
     



xyzyang
Junior Member

Posts: 4
Joined: Feb 2004

Thu Feb 12, 04 04:26 PM
User is offline

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



 
Reply
   
Quote
   
Top
   
Bottom
     

Pages: [ 1 2 >> Next ]
View thread in raw text format
FORUMS > The Quantitative Finance FAQs Project < refresh >

Forum Navigation:

© All material, including contents and design, copyright Wilmott Electronic Media Limited - FuseTalk 4.01 © 1999-2014 FuseTalk Inc. Terms & Conditions