How do I Generate Random Numbers with Correlation Matrix?

Hi, I am trying to generate 20*10000 random numbers with Logistic distributions and a 20*20 correlation matrix, but I don't know how to do so. Could someone help me on this topic?
  Thanks!

Statistics

Look at the Statistics package.  To generate a 20x10000 matrix filled with samples of a specific Logistic distribution do, for example

with(Statistics):
X := RandomVariable(Logistic(0.1, 0.5)):
R := Sample(X,[1..20,1..10000]);

Thanks! Could you further

Thanks! Could you further tell me know to generate those random numbers with a 20*20 correlation matrix?

JacquesC's picture

Use the inverse CDF

The typical trick is to generate from a uniform[0,1] distribution and then use the inverse of the CDF to get that mapped to any other distribution.  Here you'll want to generate random vectors of length 20 and then first use the inverse of that 20*20 correlation matrix before using the inverse CDF.  Or at least, something like that should work.

Of course, one can expect such a method to be extremely badly behaved numerically, so that many guard Digits would be needed.  A more direct method could avoid this, but I could not find a decent reference in the time I had.

Thanks! But I don't get it,

Thanks! But I don't get it, could you be more specific?

acer's picture

random deviates via inversion of CDF

Just look here.

acer

Thanks acer. I think I

Thanks acer. I think I understand how to generate random number with distributions by Inverse Transformation Method. But I still don't understand the underlined part of what JacquesC mentioned: Here you'll want to generate random vectors of length 20 and then first use the inverse of that 20*20 correlation matrix before using the inverse CDF.  Do I just dot product a randomly generated 1*20 vector with standard uniform distribution by the inverse of the given 20*20 correlation matrix?

acer's picture

which comes first?

I don't understand what exactly it is that you want.

Do you want to generate samples of 10000 elements from each of 20 logistic random variables, so that their correlation matrix fits a 20x20 matrix which you know and supply in advance? Are you asking how to produce the 20 sets of random deviates, given the 20x20 matrix of desired correlation values? (I believe that is how Jacques, and consequently Robert, have responded.)

Or do you simply want (somehow) to generate (correlated in some way or not..) 20 logistic random variables and then compute their sample correlations as product-moment coefficients? If so, then do you care how it's done, so that the samples are made deliberately to not all be uncorrelated?

acer

Robert Israel's picture

Correlated random variables

Sorry, that method will not work.  If you apply the inverse correlation matrix to a vector of independent uniform random variables, they cease to be uniform.  Moreover, if you did have a vector of correlated uniform random variables, applying the inverse CDF of some non-uniform distribution to each random variable would change the correlations.

Actually, I think the first thing to think about is what you really mean by correlated logistic random variables.  What is the joint distribution?  It's not at all obvious (not like the multivariate normal distribution, where there's an obvious choice).  The second thing to do is to consult a statistician, which I am not...

 

JacquesC's picture

Thanks for the correction

My approach with the inverse correlation matrix was indeed too simplistic.  And I probably had another mental error where I had it in mind that correlation matrices were unitary [which would have preserved more properties], but that is not so!  So indeed we really need more details for the OP about the specification of the problem.  Of course, that might not help, as it may exceed the actual knowledge of statistics that many of us have!

Sorry I didn't describe the

Sorry I didn't describe the problem well. I am writing program to simulate an optimized portfolio. I've known that there are 20 asset classes with certain return distributions( or 20 ramdom variables with 20 different  distribution because each asset class is different from each other). I also know those 20 ramdom variables are correlated with each other, and I decirbe these relationship in a 20*20 correlation matrix. The ultimate goal is to generate 20 ramdom variables with 20 different  distributions and with a given 20*20 correlation matrix for 10000 iterations.

I hope this time I explain the problem clearly.

 

acer's picture

simulation

This looks like a job for simulation, to me. The sort of thing where one starts off with a set of rank correlation coefficients, and possibly a joint distribution or copula. I am not expert in this area. If you are lucky, Axel Vogt might have some good advice for you. I too am curious as to how to do this with Maple -- whether it can be done reasonably easily with the Statistics package or whether some key subtask would be facilitated with the Financial Modeling Toolbox.

acer

Axel Vogt's picture

hm ...

Do not know too much about that (and the question is a bit unclear).

Besides the certainly existing standard literature 2 links to NAG articles

http://www.nag.co.uk/doc/TechRep/Pdf/tr2_00.pdf and
http://www.nag.co.uk/Numeric/CL/financial/GLFEN27.pdf (view at the problem as a multi asset option and use quasi-random numbers)

20 items is quite high, so one way would be to put them into clusters, may be a PCA (principal component analysis) helps.

The only direct and brute way that I am aware of is for 'margin calculations', but that's on daily runs only (i.e. over-night risk)

The practical problem may be deeper: the pdf for the items usually would not be the same over livetime (except working with historical data, while a better approach might be to work with derived data). The more serious part is: the correlations are not constant and from my vague knowledge one should search for "dispersion trades" (i.e. a major risk comes from there).

For Maple I have seen some 'classical' stuff, but can not remember and just do not have Maple here to look up the Toolbox

Thanks acer and Axel. I've

Thanks acer and Axel. I've looked at some introduction on Rank Order Coefficient, but can't find any articles that explain how to use it to generate random variables with correlations. But I am sure this method will work because the software(Risk 4.5) I've used ultilizes this method to generate correlated random numbers.

To Axel: It looks like you are in the financial engineering area. The random number generating program I am working on is a part of portfolio optimization software for long term portfolio management. 20 asset classes in fact are a little bit more than what I need , but 15 for sure. The purpose of random number generation is to simulate 15-20 asset classes that correlate with each other. I've ran the distribution fit for historical return data (10 years' monthly return data) for those asset classes and got corresponding best fitted PDFs. The correlation matrix was also gotton from the same historical data as well. But I don't know how to generae random numbers based on those best fitted PDFs whle make them correlated with each other based on the  correlation  matrix  I got.

Like you said, return distribution and correlation matrix change over time. I haven't find better way to deal with this issue except using long term historical data to predict long term future data. I might add prediction to change the PDFs and correlation matrix, but I don't know whether this method will increase the simulation error.

acer's picture

in Matlab..

Is this illustrating how it might be done in Matlab?

acer

Axel Vogt's picture

yes, one way are copulas

but a fixed correlation does not make sense, it is known to by stochastic & clustered

portfolio simualtion is a field of its own, especially if one has assets of different types (say credit + equity)

it is minor a question of Maple or not ...

here some reading www.nuclearphynance.com/User%20Files/2/Dispersion%20-%20A%20guide%20for%20the%20clueless%201.1.pdf

and as a side remark: the subprime crisis shows how much it is worth to believe in models and simulation :-)

Thanks, I didn't think about

Thanks, I didn't think about this issue before. I need to learn more about quant. By the way, that website is very informative.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}