Latticework

Command Palette

Search for a command to run...

Stochastic Processes Fundamentals

Random Walks

18 min

Explanation

A random walk takes a random step at each tick — the simplest version moves +1 or -1 with equal probability. It's the discrete-time ancestor of almost every random process used in quant finance (a stock price is often modeled as a random walk with drift, in log-return space).

import random

random.seed(0)
position = 0
for _ in range(10):
    position += 1 if random.random() < 0.5 else -1
print(position)

Despite each step being unbiased (equally likely up or down), the walk does NOT stay near 0 — it tends to wander, and how far it wanders grows with time in a specific, predictable way.

Try it

Tracking every position (not just the final one) lets you see the whole path — notice it doesn't oscillate tightly around 0, it wanders.

Loading editor…
Explanation

The expected final position of a symmetric random walk is always exactly 0 — positive and negative steps are equally likely, so they cancel out on average. But "expected value 0" doesn't mean "stays near 0": the walk's typical DISTANCE from 0 after n steps grows proportionally to √n (its variance grows linearly with n, so its standard deviation — the typical spread — grows with the square root).

That √n scaling is the exact same law behind Monte Carlo error shrinking as 1/√n from the previous course — both come from the variance of a sum of independent random steps growing linearly with the number of steps.

Exercise

Write `random_walk_position(n, seed=42)`: simulate a simple symmetric random walk of `n` steps (each step +1 or -1 with equal probability), seeded with `seed`, and return the final position.

Exercise

Write `random_walk_max_position(n, seed=42)`: simulate the same kind of walk, but return the MAXIMUM position reached at any point during the walk (including the starting position, 0), not just the final position.

Quiz

For a simple symmetric random walk (+1/-1 steps, equal probability), what is the expected value of the position after n steps?

Checkpoint

You can simulate a simple random walk and understand why its expected position stays at 0 even though it typically wanders away from 0 by an amount that grows with √n.