美文网首页
python实现简单蒙特卡洛模拟

python实现简单蒙特卡洛模拟

作者: 从纽约到深圳 | 来源:发表于2020-05-27 13:02 被阅读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```

    相关文章

      网友评论

          本文标题:python实现简单蒙特卡洛模拟

          本文链接:https://www.haomeiwen.com/subject/xolwahtx.html