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```
网友评论