This is Argyn's blog. I comment on topics of my interests such as software, math, finance, and music. Also, I write about local events in Northern Virginia, USA and all things related to Kazakhstan

Wednesday, January 31, 2007

...generate correlated random numbers | MaplePrimes

If you want to generate correlated random sequences thenthis page how to do it in Maple. It's fairly easy to understand the principle though.

Suppose you have N uncorrelated random time series X1, X2, X3 ... Xn with standard deviation equal to 1 (for simplicity). You want to get N correlated random series Y1, Y2... Yn with a N by N correlation matrix C(i,j).

Now, let's put vectors Xi in matrix XX(i,j) where XX(i,1) is a vector X1 etc. Create a new matrix YY(i,j) = XX(i,k)*S(k,j), where S(k,j) - sqrt(C), i.e. matrix square root of a correlation matrix C.

Correlation matrix of a new set of vectors is Transpose(TT)*TT = S(i,k)*XX(k,l)*XX(l,m)*S(m,j)=C(i,j), i.e. the new vectors have required correlation matrix.

In case of two random sequences, it's very easy:

Y1 = X1, Y2 = rho*X1 + sqrt(1-rho^2)*X2

No comments: