python实现简单蒙特卡洛模拟
2020-05-27 本文已影响0人
从纽约到深圳
import numpy as np
import random
def monte_carlo(start_price,days,mu,sigma):
dt=1/days
price = np.zeros(days)
price[0] = start_price
shock = np.zeros(days)
drift = np.zeros(days)
for i in range(1,days):
shock[i] = np.random.normal(loc=mu * dt, scale=sigma * np.sqrt(dt))
drift[i] = mu * dt
price[i] = price[i-1] + (price[i-1] * (drift[i] + shock[i]))
return price```