1

Let S_n be simple random walk. I need to make simulation in Python proving that the following processess are martingales

  1. S_n when the random walk is symmetric
  2. S_n -n(p-q)
  3. (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.

Thomas
  • 11
  • 2
  • Okay. So what have you tried to do this so far? – AKX Apr 08 '20 at 07:17
  • I managed to prove it in theory and I implemented the theory to Python but unfortunately I have to make a simulation. I simulated martingale strategy used in gambling and tried to modify for each process. As far as I know I have to calculate means but I don't know means of what – Thomas Apr 08 '20 at 07:22
  • Please edit your code into your question and explain what it does and why that isn’t what you want/expect. – DisappointedByUnaccountableMod Apr 08 '20 at 07:35

0 Answers0