让我们做一个简单的随机行走。我需要用Python进行模拟,证明下面的过程是鞅
例如,我的第二个进程代码如下所示:
def step(p):
a = np.random.rand()
if a < p:
return 1
else:
return -1
p=np.random.rand()
print(p)
def runMartingale(ile):
proces=0
profit=0
win=0
for i in range(ile):
result = step(p)
if result == 1:
profit += 1
win += 1
proces += profit-i*(p-1+p)
else:
profit -= 1
proces += profit-i*(p-1+p)
return(proces, win)
def simulateMartingale(n, ile):
averageProces, averageWin = 0, 0
for _ in range(n):
proces, win = runMartingale(ile)
averageProces += proces
averageWin += win
averageProces /= n
averageWin /= n
return(averageProces, averageWin)
它返回n个进程的平均赢数,包括ile步骤和“平均利润”——值之间的平均差异。但据我所知,“方法应该是相同的,不依赖于步骤的数量”。但它们不在这段代码中。我不知道我是否计算了正确的东西来证明这些过程是鞅
目前没有回答
相关问题 更多 >
编程相关推荐