I want to simulate two correlated Geometric Brownian Motion processes in Python. I found an implementation from Matlab (https://www.goddardconsulting.ca/matlab-monte-carlo-assetpaths-corr.html) and another one in Python (https://mikejuniperhill.blogspot.com/2019/04/python-path-generator-for-correlated.html) which both should do exactly what I'm looking for, however I noticed something different between both and I'm not sure which one is correct.
Here are the specific parts I'm talking about:
Matlab implementation:
R = chol(corr);
x = randn(steps,size(corr,2));
ep = x*R;
Python implementation:
choleskyMatrix = np.linalg.cholesky(correlation)
e = np.random.normal(size = (nProcesses, nSteps))
paths = np.dot(choleskyMatrix, e)
In both implementations the Cholesky Matrix is calculated, however then the two dimensions of the random sequence x
and e
respectively are flipped. As a result, the matrix multiplication/dot product yields to a different result caused by the different dimensions of the array. Which one of these implementations is correct?