Let S_n be simple random walk. I need to make simulation in Python proving that the following processess are martingales
- S_n when the random walk is symmetric
- S_n -n(p-q)
- (S_n)^2 - 2(p-q)S_n + (n(p-q))^2 - n(1-p+q)
for example my code for the second process looks like this:
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)
It returns average number of wins for n processes with ile steps and "the mean profit" - average differences between values. But as far as I know "means should be the same and not dependent of the number of steps". But thet aren't in this code. And I don't know if I calculated the right thing to prove that these processes are martingales.