0
$\begingroup$

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.

$\endgroup$
6
  • 1
    $\begingroup$ Did you compare the raw random numbers in the first place? $\endgroup$ Commented Apr 11 at 9:46
  • $\begingroup$ If you mean without the $\rho$ and $dt$, I didn't until I saw your comment. I just checked it by using as a covariance matrix in the second approach the following: np.array([[1, 0], [0, 1]]) and I received identical results. $\endgroup$ Commented Apr 11 at 9:56
  • $\begingroup$ You are using the wrong matrix. You need to find a square root to decouple/couple the Brownian motions. $\endgroup$ Commented Apr 11 at 13:08
  • $\begingroup$ Are you assuming numpy uses the Cholesky decomposition? $\endgroup$ Commented Apr 11 at 14:22
  • 1
    $\begingroup$ Have a look at the implementation of the multivariate random number generator on line 3333 (lol!) . As you see, it uses a singular value decomposition, which is not bound to produce the same result as a cholesky ansatz, IMHO. $\endgroup$ Commented Apr 11 at 14:49

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.