python - Brownian motion keeps returning np.complex128(0j) - Stack Overflow

I'm trying to write code for a geometric brownian motion using data instead of just randomly gener

I'm trying to write code for a geometric brownian motion using data instead of just randomly generated numbers based on 0. The data comes in as either a pandas series, or numpy array. No matter what data set I feed the code I keep getting back npplex128(0j) as the last couple thousand variables in the array. It's supposed to be randomized, so it shouldn't keep returning to 0. Where is the mistake in my code, or math?

def geometric_brownian_motion(data):
    mu = data.mean()
    sigma = data.std()
    S0 = data[len(data) - 1]
    T = 1
    dt = T / len(data)
    n = len(data)

    t = np.linspace(0, T, n)
    W = np.random.standard_normal(size=n)
    S = []
    S.append(S0)
    for i in range(1, n):
        S_temp = S[0] * np.exp((mu - 0.5 * sigma ** 2) * dt + sigma * np.sqrt(dt) * W[i - 1])
        S.append(S_temp)
    S = np.array(S)
    return S

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744382196a4571486.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信