我对 Python 还很陌生,但是对于大学论文,我需要应用一些模型,最好使用 Python。我花了几天时间处理我附加的代码,但我真的帮不上忙,出了什么问题,它没有创建一个看起来像带有漂移的标准布朗运动的随机过程。我的参数,如 mu 和 sigma(预期回报或漂移和波动性)往往只会改变噪声过程的斜率。这是我的问题,一切看起来都像噪音。希望我的问题足够具体,这是我的代码:
import math
from matplotlib.pyplot import *
from numpy import *
from numpy.random import standard_normal
'''
geometric brownian motion with drift!
Spezifikationen:
mu=drift factor [Annahme von Risikoneutralitaet]
sigma: volatility in %
T: time span
dt: lenght of steps
S0: Stock Price in t=0
W: Brownian Motion with Drift N[0,1]
'''
T=1
mu=0.025
sigma=0.1
S0=20
dt=0.01
Steps=round(T/dt)
t=(arange(0, Steps))
x=arange(0, Steps)
W=(standard_normal(size=Steps)+mu*t)### standard brownian motion###
X=(mu-0.5*sigma**2)*dt+(sigma*sqrt(dt)*W) ###geometric brownian motion####
y=S0*math.e**(X)
plot(t,y)
show()
根据维基百科 http://en.wikipedia.org/wiki/Geometric_Brownian_motion#Solving_the_SDE,
所以看来
X=(mu-0.5*sigma**2)*t+(sigma*W) ###geometric brownian motion####
而不是
X=(mu-0.5*sigma**2)*dt+(sigma*sqrt(dt)*W)
Since T
我认为代表时间范围t
应该
t = np.linspace(0, T, N)
现在,根据这些 Matlab 示例(here http://www-math.bgsu.edu/z/sde/matlab/wiener.m and here http://web.iitd.ac.in/~dharmar/soft/geometric_brownian.m), 它出现
W = np.random.standard_normal(size = N)
W = np.cumsum(W)*np.sqrt(dt) ### standard brownian motion ###
not,
W=(standard_normal(size=Steps)+mu*t)
请检查数学,但是,我可能是错的。
所以,把它们放在一起:
import matplotlib.pyplot as plt
import numpy as np
T = 2
mu = 0.1
sigma = 0.01
S0 = 20
dt = 0.01
N = round(T/dt)
t = np.linspace(0, T, N)
W = np.random.standard_normal(size = N)
W = np.cumsum(W)*np.sqrt(dt) ### standard brownian motion ###
X = (mu-0.5*sigma**2)*t + sigma*W
S = S0*np.exp(X) ### geometric brownian motion ###
plt.plot(t, S)
plt.show()
yields
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)