Consider two correlated Brownian Motions $W_{1,t}$ and $W_{2,t}$ for which it holds: $$dW_{1,t}\sim N(0, \sqrt{dt})$$ $$dW_{2,t}\sim N(0, \sqrt{dt})$$ $$Cov(dW_{1,t},dW_{2,t}) = E[dW_{1,t}dW_{2,t}] = \rho dt$$
Assuming the correlation value $\rho = -0.744755$, the time increment $dt = \frac{7}{365}$, and the same seed value of $100$, I would expect that the following two approaches in numpy would produce the same simulated figures:
Approach 1:
import numpy as np # Define parameters r = -0.744755 dt = 7/365 np.random.seed(100) x = np.random.normal(size=(100, 2)) x1 = x[:, 0] x2 = r * x[:, 0] + np.sqrt(1 - r ** 2) * x[:, 1] x1 = x1 * np.sqrt(dt) x2 = x2 * np.sqrt(dt) Approach 2:
import numpy as np # Define parameters r = -0.744755 dt = 7/365 # Approach 2 np.random.seed(100) cov = np.array([[1, r], [r, 1]]) * dt x1_, x2_ = np.random.multivariate_normal([0, 0], cov, 100).T Outcome examples (first 5 values):
x1 x1_ x2 x2_ -0.2423 0.2433 0.2121 -0.2094 0.1597 -0.1616 -0.1423 0.1367 0.1359 -0.1015 -0.0537 0.1524 0.0306 -0.0815 -0.1217 -0.0243 -0.0262 0.0371 0.0431 -0.0119 Means & standard deviations:
x1 x1_ x2 x2_ mean -0.002731633 -0.005101412 -0.012261188 -0.010204166 std 0.151998354 0.151263783 0.145546227 0.147439093 Despite the use of the same seed and the rest of the inputs, the outcomes deviate, and I would like to understand whether this is a matter of incorrect implementation of the methodology in any of the two approaches, or if it is just a matter of the algorithm generating the random figures.
np.array([[1, 0], [0, 1]])and I received identical results. $\endgroup$numpyuses the Cholesky decomposition? $\endgroup$