Two correlated random variables
조회 수: 6 (최근 30일)
이전 댓글 표시
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
John D'Errico
2016년 3월 1일
편집: John D'Errico
2016년 3월 1일
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.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!