Two correlated random variables
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want a formula to generate two random variables X and Y that are correlated with a certain rho and distributed (0, 1). The formula provided by all the sources I saw is (a few are provided below) is:
rho = 0.9; %for example
x = rand(); X = x;
y = rand();
Y = rho*X + sqrt(1-rho^2)*y;
However, the Y values generated are not distributed between 0 and 1 (however, the corelation is correct). Please see the attahced image. Does anyone have a better formula? Thanks.
https://www.quantstart.com/articles/Generating-Correlated-Asset-Paths-in-C-via-Monte-Carlo
4 comentarios
John D'Errico
el 1 de Mzo. de 2016
Editada: John D'Errico
el 1 de Mzo. de 2016
Yes. It is indeed valid to use the formula that you wrote to generate variables with the correlation that you desire. HOWEVER, as you found out, that will NOT leave the points living inside the unit square. Some samples will be generated that lie outside. And if you simply reject any samples that do fall outside, then you will screw up the goal correlation coefficient.
There IS an issue beyond that, one it appears that you don't appreciate.
Consider a pair of uniform random numbers over the unit square [0,1]X[0,1]. If they are indeed uniform, then ANY point is equally probable of occurrence as any other. However, if that is true, then the correlation is zero, and cannot take on any other value.
You MIGHT choose to restrict the domain that the numbers lie in. For example, suppose that you are willing to accept that samples near the point [1,0] will NEVER occur, essentially, that the samples must lie along a band of some with along the main diagonal. If you restrict the width of that band, then you can control the observed correlation. Again, if the samples within that band are equally probable (what else might uniform mean?) then it is true that the marginal distributions of these samples will not be uniform. Similarly, if you require uniform marginal distributions for the samples, then the 2-d distribution of the points within that band in the square cannot have them as equally probable.
Alternatively, I think that one should be able to create a 2-d dimensional distribution of points that lie entirely in the unit square, where any point has non-zero probability, AND the points have the desired correlation coefficient, AND the points have uniform marginal distributions. (This is conjecture on my part at the moment, and probably irrelevant, since I don't think it is what you desire.) Anyway, if you do that, then the points will not be uniform in the 2-d domain.
Yes, I know that people always say what you did: "I just need...". The fact is, there are questions that need to be answered in order to gain a valid solution. So far, your need as stated is an ambiguous one.
Respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!