Quantitative Finance · Book 18 · Careers

The Interview Book

The Interview Book · Careers

16Stochastic Calculus

“What is d(Wt2)d(W_t^2)?” The candidate writes 2Wt dWt2W_t\,dW_t and stops. The interviewer asks for the expectation of Wt2W_t^2, and the missing term appears on its own: integrating the candidate’s answer gives a quantity of zero expectation, while Wt2W_t^2 is non-negative and not identically zero. Stochastic calculus questions are asked mostly of bank quants and researchers, and they test a short list of reflexes: Itô’s formula with its second-order term, martingales and optional stopping, the reflection principle, a change of measure, and the link between an expectation and a partial differential equation. The theory is One Quant Book 4’s (chapters 2 to 5); this chapter is its use at the whiteboard.

16.1 Itô’s formula as a calculation rule

For a twice differentiable ff and a Brownian motion WW, df(t,Wt)=(∂tf+12∂xxf)dt+∂xf dWtdf(t, W_t) = \big(\partial_t f + \tfrac12\partial_{xx} f\big)dt + \partial_x f\,dW_t. For an Itô process dX=μ dt+σ dWdX = \mu\,dt + \sigma\,dW the second-order term is 12σ2∂xxf dt\tfrac12\sigma^2 \partial_{xx} f\,dt. The rule to remember is that (dW)2=dt(dW)^2 = dt: the quadratic variation of Brownian motion is not negligible (One Quant Book 4, chapter 3).

Method 16.1 (Is it a martingale?)

  1. Apply Itô’s formula to the process.
  2. Collect the dtdt terms: the process is a local martingale exactly when they vanish.
  3. For a true martingale check integrability (for example, bounded coefficients on [0,T][0,T], or Novikov’s condition for exponentials).
  4. If there is a drift, subtract its integral: Wt2−tW_t^2 - t and Wt3−3∫0tWs dsW_t^3 - 3\int_0^t W_s\,ds are martingales.

Example 16.2 (The exponential martingale and the lognormal median)

dexp⁡(σWt−σ2t/2)d\exp(\sigma W_t - \sigma^2 t/2) has drift −σ2/2+σ2/2=0-\sigma^2/2 + \sigma^2/2 = 0: it is a martingale, and E[eσWt]=eσ2t/2\E[e^{\sigma W_t}] = e^{\sigma^2 t/2}. For dS=μS dt+σS dWdS = \mu S\,dt + \sigma S\,dW, dlog⁡S=(μ−σ2/2) dt+σ dWd\log S = (\mu - \sigma^2/2)\,dt + \sigma\,dW, so the mean of STS_T grows at μ\mu and its median at μ−σ2/2\mu - \sigma^2/2. With μ=8%\mu = 8\% and σ=40%\sigma = 40\% over ten years the mean is 2.232.23 times the start and the median 1.001.00: half the paths end below where they began.

16.2 Martingales, hitting times and the reflection principle

Exit problems for Brownian motion reduce to optional stopping on the right martingale, exactly as for the random walk of Chapter 11.

Proposition 16.3 (Exit from an interval)

For Xt=μt+σWtX_t = \mu t + \sigma W_t from 0, the probability of hitting +a+a before −b-b is b/(a+b)b/(a+b) if μ=0\mu = 0 and (1−e2μb/σ2)/(e−2μa/σ2−e2μb/σ2)\big(1 - e^{2\mu b/\sigma^2}\big)/\big(e^{-2\mu a/\sigma^2} - e^{2\mu b/\sigma^2}\big) otherwise; for μ=0\mu = 0, σ=1\sigma = 1 the expected exit time is abab.

Proof. WtW_t and Wt2−tW_t^2 - t are martingales when μ=0\mu = 0; exp⁡(−2μXt/σ2)\exp(-2\mu X_t/\sigma^2) is one otherwise. Optional stopping at the exit time, which has finite expectation, gives the results. ∎

Proposition 16.4 (Reflection principle)

For a>0a > 0, P(max⁡s≤tWs≥a)=2 P(Wt≥a)\P(\max_{s \le t} W_s \ge a) = 2\,\P(W_t \ge a).

Proof. Reflect the path after it first reaches aa: by the strong Markov property the reflected path is again a Brownian motion, and it ends above aa exactly when the original ends below; the paths that reach aa split evenly between ending above and below (One Quant Book 4, chapter 2). ∎

The chance that Brownian motion on [0,1] reaches the barrier a: the reflection principle against two simulations of 20 000 paths. Monitoring at discrete steps misses crossings between steps, so simulations underestimate; dividing the step by sixteen closes most of the gap. Data: fig_iv_reflect.py.
Figure 16.1. The chance that Brownian motion on [0,1][0,1] reaches the barrier aa: the reflection principle against two simulations of 20 000 paths. Monitoring at discrete steps misses crossings between steps, so simulations underestimate; dividing the step by sixteen closes most of the gap. Data: fig_iv_reflect.py.

The reflection principle gives the law of the running maximum and of the first hitting time; it also explains why a Monte Carlo price of a barrier option monitored on a coarse grid is biased (Figure 16.1), which is the kind of observation an interviewer rewards.

16.3 Changes of measure in one line

Girsanov’s theorem (One Quant Book 4, chapter 5) says that under the measure Q\mathbb Q with density exp⁡(−θWT−θ2T/2)\exp(-\theta W_T - \theta^2 T/2) the process Wt+θtW_t + \theta t is a Brownian motion. In an interview it is used to move a drift: with dS=μS dt+σS dWdS = \mu S\,dt + \sigma S\,dW and a rate rr, the choice θ=(μ−r)/σ\theta = (\mu - r)/\sigma (the market price of risk) makes the discounted price a martingale, which is the risk-neutral measure. Choosing the stock as numeraire instead gives the measure under which the asset-or-nothing digital is priced.

Example 16.5 (Two digitals by two measures)

A cash-or-nothing digital paying 1 if ST>KS_T > K is worth e−rTΦ(d2)e^{-rT}\Phi(d_2) (the risk-neutral probability), and an asset-or-nothing digital paying STS_T if ST>KS_T > K is worth S0Φ(d1)S_0\Phi(d_1) (the probability under the stock measure). A call is the difference: asset-or-nothing minus KK cash-or-nothing, which is the Black–Scholes formula read off in one line (One Quant Book 5, chapter 3).

16.4 From an SDE to a PDE and back

The Feynman–Kac formula links expectations and PDEs: if dX=μ(t,X) dt+σ(t,X) dWdX = \mu(t,X)\,dt + \sigma(t,X)\,dW, then u(t,x)=E[g(XT)∣Xt=x]u(t,x) = \E[g(X_T) \mid X_t = x] solves ∂tu+μ∂xu+12σ2∂xxu=0\partial_t u + \mu\partial_x u + \tfrac12\sigma^2\partial_{xx} u = 0 with u(T,x)=g(x)u(T, x) = g(x) (One Quant Book 4, chapter 4, on the generator). Interviews use it in both directions: to guess a solution of a PDE as an expectation, and to check an expectation by plugging it into the PDE.

Method 16.6 (Checking a proposed expectation)

  1. Write the generator of the process: Lu=μux+12σ2uxx\mathcal L u = \mu u_x + \tfrac12\sigma^2 u_{xx}.
  2. Check that the proposed uu satisfies ut+Lu=0u_t + \mathcal L u = 0 and the terminal condition.
  3. Check a limit: at t=Tt = T, or for σ→0\sigma \to 0, the answer must reduce to the obvious one.

16.5 Worked answers

Example 16.7 (A mean-reverting spread)

“A spread follows dXt=−κXt dt+σ dWtdX_t = -\kappa X_t\,dt + \sigma\,dW_t with κ=0.1\kappa = 0.1 a day and σ=1\sigma = 1 basis point per square-root day. What are its half-life and its long-run standard deviation?” The mean obeys dE[Xt]=−κE[Xt] dtd\E[X_t] = -\kappa\E[X_t]\,dt, so it decays as e−κte^{-\kappa t} and halves in ln⁡2/κ≈6.9\ln 2/\kappa \approx 6.9 days. For the variance, Itô’s formula on X2X^2 gives dE[Xt2]=(−2κE[Xt2]+σ2) dtd\E[X_t^2] = (-2\kappa\E[X_t^2] + \sigma^2)\,dt, whose stationary point is σ2/(2κ)=5\sigma^2/(2\kappa) = 5, a standard deviation of 5≈2.24\sqrt5 \approx 2.24 basis points. The two numbers are what a pairs trader sizes and times entries with: a spread two standard deviations out, 4.5 basis points, is expected to be halfway back in a week. Check: as κ→0\kappa \to 0 the stationary variance blows up, as it must for a random walk.

Example 16.8 (How long a driftless P&L stays under water)

“A strategy’s cumulative P&L is a driftless Brownian motion started at zero. What is the chance it spends at least 90% of the year below zero?” By Lévy’s arcsine law, the fraction of [0,1][0, 1] spent positive has distribution function 2πarcsin⁡x\tfrac2\pi\arcsin\sqrt{x}, so the chance of at most 10% of the time positive is 2πarcsin⁡0.1≈0.20\tfrac2\pi\arcsin\sqrt{0.1} \approx 0.20. One in five worthless strategies, or skilful strategies with no edge this year, spend nine-tenths of the year under water, and as many spend nine-tenths above it. The density piles up at the ends, not in the middle: long spells on one side are the rule for a random walk, which is why a run of good months says less than it feels.

16.6 Question bank

Interview question 16.1 ★ bank, researcher • bank

Compute d(Wt2)d(W_t^2) and use it to find E[Wt2]\E[W_t^2].

Solution

Solution of Interview question 16.1.

d(Wt2)=2Wt dWt+dtd(W_t^2) = 2W_t\,dW_t + dt. Integrating and taking expectations, the stochastic integral has mean zero, so E[Wt2]=t\E[W_t^2] = t. Without the dtdt term the answer would be zero, which is impossible for a non-negative variable.

What the interviewer is looking for: the second-order Itô term and the sanity check that exposes its absence.

Interview question 16.2 ★ bank, researcher • bank

Is Wt3W_t^3 a martingale? If not, what must be subtracted to make it one?

Solution

Solution of Interview question 16.2.

d(Wt3)=3Wt2 dWt+3Wt dtd(W_t^3) = 3W_t^2\,dW_t + 3W_t\,dt: the drift 3Wt3W_t is not zero, so it is not a martingale. Wt3−3∫0tWs dsW_t^3 - 3\int_0^t W_s\,ds is (its differential is 3Wt2 dWt3W_t^2\,dW_t, and the integrand is square-integrable).

What the interviewer is looking for: reading the drift off Itô’s formula and compensating it.

Interview question 16.3 ★ researcher, trader • systematic fund

What is the probability that a Brownian motion is positive at both t=1t = 1 and t=2t = 2?

Solution

Solution of Interview question 16.3.

(W1,W2)(W_1, W_2) is Gaussian with correlation 1/2\sqrt{1/2}. For a centred bivariate normal, P(X>0,Y>0)=14+arcsin⁡(ρ)/(2π)=14+π/42π=38\P(X > 0, Y > 0) = \tfrac14 + \arcsin(\rho)/(2\pi) = \tfrac14 + \tfrac{\pi/4}{2\pi} = \tfrac38. A simulation of 400 000 pairs agrees.

What the interviewer is looking for: the correlation of Brownian values and the orthant probability.

Interview question 16.4 ★ bank • bank

What is the distribution of ∫0TWs ds\int_0^T W_s\,ds?

Solution

Solution of Interview question 16.4.

It is a linear functional of a Gaussian process, so Gaussian, with mean 0 and variance

∫0T ⁣ ⁣∫0Tmin⁡(s,u) ds du=T33.\int_0^T\!\!\int_0^T \min(s,u)\,ds\,du = \frac{T^3}{3}.

(Equivalently, ∫0TWs ds=∫0T(T−s) dWs\int_0^T W_s\,ds = \int_0^T (T - s)\,dW_s by integration by parts, whose variance is ∫0T(T−s)2 ds\int_0^T (T - s)^2\,ds.)

What the interviewer is looking for: Gaussianity and the covariance integral, or the integration-by-parts representation.

Interview question 16.5 ★★ bank, researcher • market maker

Starting from 0, what is the chance that a Brownian motion hits +1+1 before −2-2, and how long does it take on average to hit either?

Solution

Solution of Interview question 16.5.

By Proposition 16.3, P=2/(1+2)=23\P = 2/(1 + 2) = \tfrac23, and E[τ]=1×2=2\E[\tau] = 1 \times 2 = 2.

What the interviewer is looking for: optional stopping on WW and on W2−tW^2 - t.

Interview question 16.6 ★★ researcher, trader • systematic fund

Xt=0.5t+WtX_t = 0.5t + W_t. What is the chance it hits +1+1 before −1-1?

Solution

Solution of Interview question 16.6.

With μ=0.5\mu = 0.5, σ=1\sigma = 1, a=b=1a = b = 1: (1−e1)/(e−1−e1)=1/(1+e−1)≈0.731(1 - e^{1})/(e^{-1} - e^{1}) = 1/(1 + e^{-1}) \approx 0.731. The martingale is e−2μXt=e−Xte^{-2\mu X_t} = e^{-X_t}.

What the interviewer is looking for: the exponential martingale for a drifted walk.

Interview question 16.7 ★★ bank, risk • bank

What is the probability that a standard Brownian motion exceeds 1 at some time in [0,1][0, 1]? A Monte Carlo with 50 steps gives a smaller number; why, and how do you fix it without more steps?

Solution

Solution of Interview question 16.7.

2P(W1≥1)=2(1−Φ(1))≈0.3172\P(W_1 \ge 1) = 2(1 - \Phi(1)) \approx 0.317. A discrete simulation checks the maximum only at the grid points and misses excursions between them, so it underestimates (Figure 16.1). Fix it with a Brownian-bridge correction: between two grid values x,yx, y below the barrier, the path crosses with probability exp⁡(−2(a−x)(a−y)/Δt)\exp(-2(a - x)(a - y)/\Delta t); draw that event, and the estimate is unbiased on any grid.

What the interviewer is looking for: the reflection principle, the direction of the discretisation bias and the bridge correction.

Interview question 16.8 ★★ trader, risk • asset manager

A stock follows geometric Brownian motion with drift 8% and volatility 40%. Over ten years, find the expected value and the median of its price relative to today. What do you tell an investor who hears only the first number?

Solution

Solution of Interview question 16.8.

Mean e0.08×10≈2.23e^{0.08 \times 10} \approx 2.23; median e(0.08−0.08)×10=1.00e^{(0.08 - 0.08) \times 10} = 1.00. The mean is carried by a minority of very good paths; the typical investor ends where she started. Quote the median and a range, not the mean.

What the interviewer is looking for: the −σ2/2-\sigma^2/2 correction and its practical meaning.

Interview question 16.9 ★★ bank • bank

A stock has drift 8% and volatility 20% and the rate is 3%. What change of measure makes the discounted stock a martingale, and what is the drift of WW under it?

Solution

Solution of Interview question 16.9.

Take θ=(μ−r)/σ=(0.08−0.03)/0.2=0.25\theta = (\mu - r)/\sigma = (0.08 - 0.03)/0.2 = 0.25 and dQ/dP=exp⁡(−0.25WT−0.03125T)d\mathbb Q/d\mathbb P = \exp(-0.25 W_T - 0.03125T). Under Q\mathbb Q, Wt+0.25tW_t + 0.25t is a Brownian motion, so WW has drift −0.25-0.25, and dS=rS dt+σS dWQdS = rS\,dt + \sigma S\,dW^{\mathbb Q}.

What the interviewer is looking for: the market price of risk as the Girsanov kernel.

Interview question 16.10 ★★★ bank, trader • bank

With S0=K=100S_0 = K = 100, σ=20%\sigma = 20\%, T=1T = 1 and zero rates, price the cash-or-nothing digital paying 1 and the asset-or-nothing digital paying STS_T if ST>KS_T > K. Deduce the call price.

Solution

Solution of Interview question 16.10.

d1=σT/2=0.1d_1 = \sigma\sqrt T/2 = 0.1, d2=−0.1d_2 = -0.1. Cash-or-nothing: Φ(−0.1)≈0.4602\Phi(-0.1) \approx 0.4602. Asset-or-nothing: 100 Φ(0.1)≈53.98100\,\Phi(0.1) \approx 53.98. Call =53.98−100×0.4602≈7.97= 53.98 - 100 \times 0.4602 \approx 7.97, the Black–Scholes value (and close to 0.4×100×0.2=80.4 \times 100 \times 0.2 = 8).

What the interviewer is looking for: digitals under two measures and their difference as the call.

Interview question 16.11 ★★★ bank, researcher • bank

Solve ∂tu+12∂xxu=0\partial_t u + \tfrac12\partial_{xx}u = 0 with u(T,x)=x2u(T, x) = x^2 by writing uu as an expectation, and check it.

Solution

Solution of Interview question 16.11.

By Feynman–Kac with dX=dWdX = dW, u(t,x)=E[(x+WT−Wt)2]=x2+(T−t)u(t, x) = \E[(x + W_T - W_t)^2] = x^2 + (T - t). Check: ut=−1u_t = -1, 12uxx=1\tfrac12 u_{xx} = 1, sum 0; and u(T,x)=x2u(T, x) = x^2.

What the interviewer is looking for: writing the solution as an expectation and verifying it in the PDE.

Interview question 16.12 ★★★ researcher, bank • systematic fund

For Xt=μt+WtX_t = \mu t + W_t with μ>0\mu > 0, what is the expected time to reach +1+1? What happens as μ→0\mu \to 0, and is that consistent with Brownian motion reaching +1+1 with probability one?

Solution

Solution of Interview question 16.12.

Xτ=1X_\tau = 1 and Xt−μtX_t - \mu t is a martingale; optional stopping (with E[τ]<∞\E[\tau] < \infty for μ>0\mu > 0) gives 1−μE[τ]=01 - \mu\E[\tau] = 0, so E[τ]=1/μ\E[\tau] = 1/\mu. As μ→0\mu \to 0 the expectation tends to infinity: driftless Brownian motion reaches +1+1 with probability one, but its hitting time has infinite mean (its density decays like t−3/2t^{-3/2}). Certain and fast are different things.

What the interviewer is looking for: Wald for Brownian motion with drift and the heavy tail of the driftless hitting time.

Interview question 16.13 ★★★ researcher, bank • any

Let τ\tau be the first time WW hits 1. Then Wτ=1W_\tau = 1, yet WW is a martingale started at 0. Why does optional stopping fail? Add a lower barrier at −b-b and recover a correct statement.

Solution

Solution of Interview question 16.13.

τ\tau is finite almost surely but E[τ]=∞\E[\tau] = \infty, and Wt∧τW_{t \wedge \tau} is not uniformly integrable (it can go arbitrarily negative before hitting 1), so the optional stopping theorem does not apply. With a lower barrier −b-b, the stopped process is bounded, optional stopping holds, and 0=E[Wτ]=p×1−(1−p)b0 = \E[W_\tau] = p \times 1 - (1 - p)b, so the chance of hitting 1 first is b/(1+b)b/(1 + b); it tends to one as b→∞b \to \infty while the loss in the other case grows, which reconciles the two statements.

What the interviewer is looking for: the conditions of optional stopping and a bounded version that works.

Sources and further reading

  • One Quant Book 4, chapters 2–5 (Brownian motion, Itô calculus, SDEs, Girsanov); One Quant Book 5, chapter 3 (Black–Scholes).
  • I. Karatzas and S. E. Shreve, Brownian Motion and Stochastic Calculus, Springer, 1988.