我尝试在x-y轴上用n= 1000 steps
时间t=1
对一维随机游动进行采样。对于每一步,助行器的位置都会增加或减少(1/1000)**0.5
。我有一个简单的代码,但我不知道如何让它随机添加或减少(1/1000)**0.5
。谢谢你的帮助
import numpy as np
import matplotlib.pyplot as plt
# Generate 500 random steps with mean=0 and standard deviation=1
steps = np.random.normal(loc=0, scale=1.0, size=500)
# Set first element to 0 so that the first price will be the starting stock price
steps[0]=0
# Simulate stock prices, P with a starting price of 100
P = 100 + np.cumsum(steps)
# Plot the simulated stock prices
plt.plot(P)
plt.title("Simulated Random Walk")
plt.show()
调整来自Random Walk (Implementation in Python)和1D Random Walk的代码
显示
进一步的代码解释
自:
这为downp和upp创造了以下可能性
要决定辞职还是辞职,我们有以下表达:
其中,步长是步长,位置[-1]是最后一个位置
(1)上述内容相当于:
这意味着我们只有在最后一个位置>;1,我们有向下标志为真(因此1成为下限)
(2)上述内容相当于:
这意味着只有在最后一个位置<;4且ipp标志为真(因此4成为上限)
在最新情况下,我们有:
这意味着:
单步步行的可能性包括:
相关问题 更多 >
编程相关推荐