def MC_sigma_under_Q(S0, r, sigma0, rho, a, mt, T, dt):
# Generate random Brownian Motion
P = np.array([[1, rho], [rho,1]])
Copyright By PowCoder代写 加微信 powcoder
length = int(T*n_steps)
MU = np.array([0, 0])
COV = np.matrix([[1, rho], [rho, 1]])
W = np.random.multivariate_normal(MU, COV, (length, length)).T
W_S = W[0]
W_v = W[1]
# Generate paths
sigmat = np.zeros([length, length+1])
sigmat[:,0] = sigma0
St = np.zeros([length, length+1])
St[:,0] = S0
for t in range(1,length):
if t