Quantitative Finance Interviews
115

5.2 Martingale and Random walk

Random walk: The process {Sn;n≥1}\{S_n;n\geq 1\} is called a random walk if {Xi;i≥1}\{X_i;i\geq 1\} are IID (identical and independently distributed) random variables and Sn=X1+⋯XnS_n=X_1+\cdots X_n, where n=1,2,⋯n=1,2,\cdots. The term comes from the fact that we can think of SnS_n as the position at time nn for a walker who makes successive random steps X1,X2,⋯X_1,X_2,\cdots.

If XiX_i takes values 1 and -1 with probabilities pp and 1−p1-p respectively, SnS_n is called a simple random walk with parameter pp. Furthermore, if p=12p=\frac12, the process SnS_n is a symmetric random walk. For symmetric random walk, it’s easy to show that E[Sn]=0E[S_n]=0 and var⁡(Sn)=E[Sn2]−E[Sn]2=E[Sn2]=n\operatorname{var}(S_n)=E[S_n^2]-E[S_n]^2=E[S_n^2]=n.5

Symmetric random walk is the process that is most often tested in quantitative interviews. The interview questions on random walk often revolve around finding the first nn for which SnS_n reaches a defined threshold α\alpha, or the probability that SnS_n reaches α\alpha for any given value of nn.

Martingale: a martingale {Zn;n≥1}\{Z_n;n\geq 1\} is a stochastic process with the properties that E[∣Zn∣]<∞E[|Z_n|]<\infty for all nn and E[Zn+1∣Zn=zn,Zn−1=zn−1,⋯ ,Z1=z1]=znE[Z_{n+1}\mid Z_n=z_n,Z_{n-1}=z_{n-1},\cdots,Z_1=z_1]=z_n. The property of a martingale can be extended to E[Zm;m>n∣Zn=zn,Zn−1=zn−1,⋯ ,Z1=z1]=znE[Z_m;m>n\mid Z_n=z_n,Z_{n-1}=z_{n-1},\cdots,Z_1=z_1]=z_n, which means the conditional expected value of future ZmZ_m is the current value ZnZ_n.6

A symmetric random walk is a martingale. From the definition of the symmetric random walk we have Sn+1={Sn+1with probability 1/2Sn−1with probability 1/2S_{n+1}=\begin{cases}S_n+1&\text{with probability }1/2\\S_n-1&\text{with probability }1/2\end{cases}, so E[Sn+1∣Sn=sn,⋯ ,S1=s1]=snE[S_{n+1}\mid S_n=s_n,\cdots,S_1=s_1]=s_n. Since E[Sn+12−(n+1)]=12[(Sn+1)2+(Sn−1)2]−(n+1)=Sn2−nE[S_{n+1}^2-(n+1)]=\frac12[(S_n+1)^2+(S_n-1)^2]-(n+1)=S_n^2-n, Sn2−nS_n^2-n is a martingale as well.

116

Stopping rule: For an experiment with a set of IID random variables X1,X2,⋯X_1,X_2,\cdots, a stopping rule for {Xi;i≥1}\{X_i;i\geq 1\} is a positive integer-value random variable NN (stopping time) such that for each n>1n>1, the event {N≤n}\{N\leq n\} is independent of Xn+1,Xn+2,⋯X_{n+1},X_{n+2},\cdots. Basically it says that whether to stop at nn depends only on X1,X2,⋯ ,XmX_1,X_2,\cdots,X_m (i.e., no look ahead).

Wald’s Equality: Let NN be a stopping rule for IID random variables X1,X2,⋯X_1,X_2,\cdots and let SN=X1+X2+⋯+XNS_N=X_1+X_2+\cdots+X_N, then E[SN]=E[X]E[N]E[S_N]=E[X]E[N].

Since it is an important—yet relatively little known—theorem, let’s briefly review its proof. Let InI_n be the indicator function of the event {N≥n}\{N\geq n\}. So SNS_N can be written as

SN=∑n=1∞XnIn, where In=1 if N≥n and In=0 if N≤n−1.S_N=\sum_{n=1}^{\infty}X_nI_n,\text{ where }I_n=1\text{ if }N\geq n\text{ and }I_n=0\text{ if }N\leq n-1.

From the definition of stopping rules, we know that InI_n is independent of Xn,Xn+1,⋯X_n,X_{n+1},\cdots (it only depends on X1,X2,⋯ ,Xn−1X_1,X_2,\cdots,X_{n-1}). So E[XnIn]=E[Xn]E[In]=E[X]E[In]E[X_nI_n]=E[X_n]E[I_n]=E[X]E[I_n] and

E[SN]=E[∑n=1∞XnIn]=∑n=1∞E[XnIn]=∑n=1∞E[X]E[In]=E[X]∑n=1∞E[In]=E[X]E[N].E[S_N]=E\left[\sum_{n=1}^{\infty}X_nI_n\right]=\sum_{n=1}^{\infty}E[X_nI_n]=\sum_{n=1}^{\infty}E[X]E[I_n]=E[X]\sum_{n=1}^{\infty}E[I_n]=E[X]E[N].7

A martingale stopped at a stopping time is a martingale.

Drunk man

A drunk man is at the 17th meter of a 100-meter-long bridge. He has a 50% probability of staggering forward or backward one meter each step. What is the probability that he will make it to the end of the bridge (the 100th meter) before the beginning (the 0th meter)? What is the expected number of steps he takes to reach either the beginning or the end of the bridge?

Solution: The probability part of the problem—often appearing in different disguises—is among the most popular martingale problems asked by quantitative interviewers. Interestingly, few people use a clear-cut martingale argument. Most candidates either use Markov chain with two absorbing states or treat it as a special version of the gambler’s ruin problem with p=1/2p=1/2. These approaches yield the correct results in the end, yet a martingale argument is not only simpler but also illustrates the insight behind the problem.

117

Let’s set the current position (the 17th meter) to 0; then the problem becomes a symmetric random walk that stops at either 83 or -17. We also know that both SnS_n and Sn2−nS_n^2-n are martingales. Since a martingale stopped at a stopping time is a martingale, SNS_N and SN2−NS_N^2-N (where SN=X1+X2+⋯+XNS_N=X_1+X_2+\cdots+X_N with NN being the stopping time) are martingales as well. Let pαp_\alpha be the probability that it stops at α=83\alpha=83, pβp_\beta be the probability it stops at −β=−17-\beta=-17 (pβ=1−pαp_\beta=1-p_\alpha), and NN be the stopping time. Then we have

E[SN]=pα×83−(1−pα)×17=S0=0E[SN2−N]=E[pα×832+(1−pα)×172]−E[N]=S02−0=0}⇒{pα=0.17E[N]=1441\left.\begin{aligned}E[S_N]&=p_\alpha\times83-(1-p_\alpha)\times17=S_0=0\\E[S_N^2-N]&=E[p_\alpha\times83^2+(1-p_\alpha)\times17^2]-E[N]=S_0^2-0=0\end{aligned}\right\}\Rightarrow\begin{cases}p_\alpha=0.17\\E[N]=1441\end{cases}

Hence, the probability that he will make it to the end of the bridge (the 100th meter) before reaching the beginning is 0.17, and the expected number of steps he takes to reach either the beginning or the end of the bridge is 1441.

We can easily extend the solution to a general case: a symmetric random walk starting from 0 that stops at either α\alpha (α>0\alpha>0) or −β-\beta (β>0\beta>0). The probability that it stops at α\alpha instead of −β-\beta is pα=β/(α+β)p_\alpha=\beta/(\alpha+\beta). The expected stopping time to reach either α\alpha or −β-\beta is E[N]=αβE[N]=\alpha\beta.

Dice game

Suppose that you roll a dice. For each roll, you are paid the face value. If a roll gives 4, 5 or 6, you can roll the dice again. If you get 1, 2 or 3, the game stops. What is the expected payoff of this game?

Solution: In Chapter 4, we used the law of total expectation to solve the problem. A simpler approach—requiring more knowledge—is to apply Wald’s Equality since the problem has clear stopping rules. For each roll, the process has 1/2 probability of stopping. So the stopping time NN follows a geometric distribution with p=1/2p=1/2 and we have E[N]=1/p=2E[N]=1/p=2. For each roll, the expected face value is E[X]=7/2E[X]=7/2. The total expected payoff is E[SN]=E[X]E[N]=7/2×2=7E[S_N]=E[X]E[N]=7/2\times2=7.

Ticket line

At a theater ticket office, 2n2n people are waiting to buy tickets. nn of them have only $5 bills and the other nn people have only $10 bills. The ticket seller has no change to start 118with. If each person buys one $5 ticket, what is the probability that all people will be able to buy their tickets without having to change positions?

Solution: This problem is often considered to be a difficult one. Although many can correctly formulate the problem, few can solve the problem using the reflection principle.8 This problem is one of the many cases where a broad knowledge makes a difference.

Assign +1 to the nn people with $5 bills and -1 to the nn people with $10 bills. Consider the process as a walk. Let (a,b)(a,b) represent that after aa steps, the walk ends at bb. So we start at (0,0)(0,0) and reaches (2n,0)(2n,0) after 2n2n steps. For these 2n2n steps, we need to choose nn steps as +1, so there are (2nn)=2n!n!n!\binom{2n}{n}=\frac{2n!}{n!n!} possible paths. We are interested in the paths that have the property b≥0, ∀0<a<2nb\geq0,\ \forall0<a<2n steps. It’s easier to calculate the number of complement paths that reach b=−1, ∃0<a<2nb=-1,\ \exists0<a<2n. As shown in Figure 5.6, if we reflect the path across the line y=−1y=-1 after a path first reaches -1, for every path that reaches (2n,0)(2n,0) at step 2n2n, we have one corresponding reflected path that reaches (2n,−2)(2n,-2) at step 2n2n. For a path to reach (2n,−2)(2n,-2), there are (n−1)(n-1) steps of +1 and (n+1)(n+1) steps of -1. So there are (2nn−1)=2n!(n−1)!(n+1)!\binom{2n}{n-1}=\frac{2n!}{(n-1)!(n+1)!} such paths. The number of paths that have the property b=−1, ∃0<a<2nb=-1,\ \exists0<a<2n, given that the path reaches (2n,0)(2n,0) is also (2nn−1)\binom{2n}{n-1} and the number of paths that have the property b≥0, ∀0<a<2nb\geq0,\ \forall0<a<2n is

(2nn)−(2nn−1)=(2nn)−nn+1(2nn)=1n+1(2nn).\binom{2n}{n}-\binom{2n}{n-1}=\binom{2n}{n}-\frac{n}{n+1}\binom{2n}{n}=\frac{1}{n+1}\binom{2n}{n}.

Hence, the probability that all people will be able to buy their tickets without having to change positions is 1/(n+1)1/(n+1).

119
A walk in coordinates a and b starts at (0,0) and ends at (2n,0). After first reaching b=-1, its reflected path across y=-1 ends at (2n,-2). The b-axis marks 0, -1, and -2; the a-axis ends at 2n.
Figure 5.6 Reflected paths: the dashed line is the reflection of the solid line after it reaches -1

Coin sequence

Assume that you have a fair coin. What is the expected number of coin tosses to get nn heads in a row?

Solution: Let E[f(n)]E[f(n)] be the expected number of coin tosses to get nn heads in a row. In the Markov chain section, we discussed the case where n=3n=3 (to get the pattern HHHHHH). For any integer nn, we can consider an induction approach. Using the Markov chain approach, we can easy get that E[f(1)]=2E[f(1)]=2, E[f(2)]=6E[f(2)]=6 and E[f(3)]=14E[f(3)]=14. A natural guess for the general formula is that E[f(n)]=2n+1−2E[f(n)]=2^{n+1}-2. As always, let’s prove the formula using induction. We have shown the formula is true for n=1,2,3n=1,2,3. So we only need to prove that if E[f(n)]=2n+1−2E[f(n)]=2^{n+1}-2, E[f(n+1)]=2n+2−2E[f(n+1)]=2^{n+2}-2. The following diagram shows how to prove that the equation holds for E[f(n+1)]E[f(n+1)]:

State 0 leads to nH in expected E[f(n)] tosses. From nH, an arrow with probability P=1/2 leads to (n+1)H, and a return arrow with probability P=1/2 leads to 0.

The state before (n+1)(n+1) heads in a row (denoted as (n+1)H(n+1)H) must be nn heads in a row (denoted as nHnH). It takes an expected E[f(n)]=2n+1−2E[f(n)]=2^{n+1}-2 tosses to reach nHnH. Conditioned on state nHnH, there is a 1/2 probability it will go to (n+1)H(n+1)H (the new toss yields HH) and the process stops. There is also a 1/2 probability that it will go to the 120starting state 0 (the new toss yields TT) and we need another expected E[f(n+1)]E[f(n+1)] tosses to reach (n+1)H(n+1)H. So we have

E[f(n+1)]=E[F(n)]+12×1+12×E[f(n+1)]⇒E[f(n+1)]=2×E[F(n)]+2=2n+2−2.\begin{aligned}E[f(n+1)]&=E[F(n)]+\frac12\times1+\frac12\times E[f(n+1)]\\\Rightarrow E[f(n+1)]&=2\times E[F(n)]+2=2^{n+2}-2.\end{aligned}

General Martingale approach: Let’s use HH⋯HnHH\cdots H_n to explain a general approach for the expected time to get any coin sequence by exploring the stopping times of martingales.9 Imagine a gambler has $1 to bet on a sequence of nn heads (HH⋯HnHH\cdots H_n) in a fair game with the following rule: Bets are placed on up to nn consecutive games (tosses) and each time the gambler bets all his money (unless he goes bankrupt). For example, if HH appears at the first game, he will have $2 and he will put all $2 into the second game. He stops playing either when he loses a game or when he wins nn games in a roll, in which case he collects $2n2^n (with probability 1/2n1/2^n). Now let’s imagine, instead of one gambler, before each toss a new gambler joins the game and bets on the same sequence of nn heads with a bankroll of $1 as well. After the ii-th game, ii gamblers have participated in the game and the total amount of money they have put in the game should be $ii. Since each game is fair, the expected value of their total bankroll is $ii as well. In other words, if we denote xix_i as the amount of money all the participating gamblers have after the ii-th game, then (xi−i)(x_i-i) is a martingale.

Now, let’s add a stopping rule: the whole game will stop if one of the gamblers becomes the first to get nn heads in a roll. A martingale stopped at a stopping time is a martingale. So we still have E[(xi−i)]=0E[(x_i-i)]=0. If the sequence stops after the ii-th toss (i≥ni\geq n), the (i−n+1)(i-n+1)-th player is the (first) player who gets nn heads in a roll with payoff 2n2^n. So all the (i−n)(i-n) players before him went bankrupt; the (i−n+2)(i-n+2)-th player gets (n−1)(n-1) heads in a roll with payoff 2n−12^{n-1}; ⋯\cdots; the ii-th player gets one head with payoff 2. So the total payoff is fixed and xi=2n+2n−1+⋯+21=2n+1−2x_i=2^n+2^{n-1}+\cdots+2^1=2^{n+1}-2.

Hence, E[(xi−i)]=2n+1−2−E[i]=0⇒E[i]=2n+1−2E[(x_i-i)]=2^{n+1}-2-E[i]=0\Rightarrow E[i]=2^{n+1}-2.

This approach can be applied to any coin sequences—as well as dice sequences or any sequences with arbitrary number of elements. For example, let’s consider the sequence HHTTHHHHTTHH. We can again use a stopped martingale process for sequence HHTTHHHHTTHH. The gamblers join the game one by one before each toss to bet on the same sequence HHTTHHHHTTHH until one gambler becomes the first to get the sequence HHTTHHHHTTHH. If the sequence stops after the ii-th toss, the (i−5)th(i-5)th gambler gets the HHTTHHHHTTHH with payoff 121262^6. All the (i−6)(i-6) players before him went bankrupt; the (i−4)th(i-4)th player loses in the second toss (HT); the (i−3)th(i-3)th player and the (i−2)th(i-2)th player lose in the first toss (TT); the (i−1)th(i-1)th player gets sequence HHHH with payoff 222^2 and the ii-th player gets HH with payoff 2.

Hence, E[(xi−i)]=26+22+21−E[i]=0⇒E[i]=70E[(x_i-i)]=2^6+2^2+2^1-E[i]=0\Rightarrow E[i]=70.