如何通过Python对参数sigma=1,mu=-1的两条布朗运动路径进行采样?

How to sample two paths of Brownian motion with parameter sigma=1, mu=-1 by Python?

我尝试采样两条相同参数的路径,分别是sigma=1mu=-1,初始位置是2。但我不知道如何同时对两条路径进行采样。这是我的布朗运动单路径代码 Python:

import numpy as np
import matplotlib.pyplot as plt

np.random.seed(5)
fig = plt.figure()
T = 1
N = 501 # Number of points, number of subintervals = N-1
dt = T/(N-1) # Time step
t = np.linspace(0,T,N)

# Preallocate arrays for efficiency:
dX = [0]*N
X = [0]*N

# Initialization:
dX[0] = np.sqrt(dt)*(1*np.random.randn(0,1)-1) # Eq. (3)
X[0] = 2

for i in range(1,N):
    dX[i] = np.sqrt(dt)*(1*np.random.randn()) # Eq. (3)
    X[i] = X[i-1] + dX[i] # Eq. (4)

plt.plot(t, X)
plt.xlabel('Time $t$', fontsize=14)
plt.ylabel('Random Variable $X(t)$', fontsize=14)
plt.title('1D Brownian Path', fontsize=14)
axes = plt.gca()
axes.set_xlim([0,T])
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
plt.tight_layout()
plt.show()

# Uncomment to save the image
#fig.savefig('brownian_1d.png', dpi=600)

这里有一个简洁的方法:

mu = -1
sigma = 1
X0 = 2
K = 2 # number of paths
dX = np.sqrt(T/(N-1)) * (sigma*np.random.randn(N, K)+mu)
X = np.cumsum(dX, axis=0) + X0