如何证明进程在Python中是鞅?

2024-09-28 01:25:28 发布

您现在位置:Python中文网/ 问答频道 /正文

让我们做一个简单的随机行走。我需要用Python进行模拟,证明下面的过程是鞅

  1. 随机游动对称时的S_n
  2. S_n-n(p-q)
  3. (S-n)^2-2(p-q)S-n+(n(p-q))^2-n(1-p+q)

例如,我的第二个进程代码如下所示:

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步骤和“平均利润”——值之间的平均差异。但据我所知,“方法应该是相同的,不依赖于步骤的数量”。但它们不在这段代码中。我不知道我是否计算了正确的东西来证明这些过程是鞅


Tags: 代码证明return进程过程defstepnp

热门问题