---
title: "Stochastic Calculus"
book: "The Interview Book"
subject: quant
language: en
chapter: 16
exercises: 0
source: https://one-course.com/books/quant/18/en/chapter/16-stochastic-calculus
---

# Chapter 16 — Stochastic Calculus

“What is $d(W_t^2)$?” The candidate writes $2W_t\,dW_t$ and stops. The interviewer asks for the expectation of $W_t^2$, and the missing term appears on its own: integrating the candidate’s answer gives a quantity of zero expectation, while $W_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 $f$ and a Brownian motion $W$, $df(t, W_t) = \big(\partial_t f + \tfrac12\partial_{xx} f\big)dt
+ \partial_x f\,dW_t$. For an Itô process $dX = \mu\,dt + \sigma\,dW$ the second-order term is $\tfrac12\sigma^2
\partial_{xx} f\,dt$. The rule to remember is that $(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 $dt$ 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]$ , or Novikov’s condition for exponentials).
4. If there is a drift, subtract its integral: $W_t^2 - t$ and $W_t^3 - 3\int_0^t W_s\,ds$ are martingales.

**Example 16.2 (The exponential martingale and the lognormal median).**

$d\exp(\sigma W_t - \sigma^2 t/2)$ has drift $-\sigma^2/2 + \sigma^2/2 = 0$: it is a martingale, and $\E[e^{\sigma W_t}] =
e^{\sigma^2 t/2}$. For $dS = \mu S\,dt + \sigma S\,dW$, $d\log S = (\mu - \sigma^2/2)\,dt + \sigma\,dW$, so the mean of $S_T$ grows at $\mu$ and its median at $\mu - \sigma^2/2$. With $\mu = 8\%$ and $\sigma = 40\%$ over ten years the mean is $2.23$ times the start and the median $1.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](https://one-course.com/books/quant/18/en/chapter/11-probability-ii#ch-iv-probability-ii).

**Proposition 16.3 (Exit from an interval).**

For $X_t = \mu t + \sigma W_t$ from 0, the probability of hitting $+a$ before $-b$ is $b/(a+b)$ if $\mu = 0$ and $\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 $\mu = 0$, $\sigma = 1$ the expected exit time is $ab$.

**Proof.** $W_t$ and $W_t^2 - t$ are martingales when $\mu = 0$; $\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 > 0$, $\P(\max_{s \le t} W_s \ge a) = 2\,\P(W_t \ge a)$.

**Proof.** Reflect the path after it first reaches $a$: by the strong Markov property the reflected path is again a Brownian motion, and it ends above $a$ exactly when the original ends below; the paths that reach $a$ 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.](https://one-course.com/images/onecourse/chapters/quant-18/iv-stochastic-calculus/fig-fad722b542a7.svg)

***Figure 16.1.** 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`.*

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](#fig-iv-stochastic-calculus-reflect)), 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 $\mathbb Q$ with density $\exp(-\theta W_T -
\theta^2 T/2)$ the process $W_t + \theta t$ is a Brownian motion. In an interview it is used to move a drift: with $dS =
\mu S\,dt + \sigma S\,dW$ and a rate $r$, the choice $\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 $S_T > K$ is worth $e^{-rT}\Phi(d_2)$ (the risk-neutral probability), and an asset-or-nothing digital paying $S_T$ if $S_T > K$ is worth $S_0\Phi(d_1)$ (the probability under the stock measure). A call is the difference: asset-or-nothing minus $K$ 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 = \mu(t,X)\,dt + \sigma(t,X)\,dW$, then $u(t,x) =
\E[g(X_T) \mid X_t = x]$ solves $\partial_t u + \mu\partial_x u + \tfrac12\sigma^2\partial_{xx} u = 0$ with $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: $\mathcal L u = \mu u_x + \tfrac12\sigma^2 u_{xx}$ .
2. Check that the proposed $u$ satisfies $u_t + \mathcal L u = 0$ and the terminal condition.
3. Check a limit: at $t = T$ , or for $\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 $dX_t = -\kappa X_t\,dt + \sigma\,dW_t$ with $\kappa = 0.1$ a day and $\sigma = 1$ basis point per square-root day. What are its half-life and its long-run standard deviation?”* The mean obeys $d\E[X_t] = -\kappa\E[X_t]\,dt$, so it decays as $e^{-\kappa t}$ and halves in $\ln 2/\kappa \approx 6.9$ days. For the variance, Itô’s formula on $X^2$ gives $d\E[X_t^2] = (-2\kappa\E[X_t^2] + \sigma^2)\,dt$, whose stationary point is $\sigma^2/(2\kappa) = 5$, a standard deviation of $\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 $\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]$ spent positive has distribution function $\tfrac2\pi\arcsin\sqrt{x}$, so the chance of at most 10% of the time positive is $\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(W_t^2)$ and use it to find $\E[W_t^2]$.

**Solution of Interview question 16.1.**

$d(W_t^2) = 2W_t\,dW_t + dt$. Integrating and taking expectations, the stochastic integral has mean zero, so $\E[W_t^2]
= t$. Without the $dt$ 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](https://one-course.com/books/quant/18/en/chapter/5-phone-and-technical-screens#def-iv-phone-and-technical-screens-sanity) that exposes its absence.*

**Interview question 16.2 ★ bank, researcher • bank.**

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

**Solution of Interview question 16.2.**

$d(W_t^3) = 3W_t^2\,dW_t + 3W_t\,dt$: the drift $3W_t$ is not zero, so it is not a martingale. $W_t^3 - 3\int_0^t
W_s\,ds$ is (its differential is $3W_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 = 1$ and $t = 2$?

**Solution of Interview question 16.3.**

$(W_1, W_2)$ is Gaussian with correlation $\sqrt{1/2}$. For a centred bivariate normal, $\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 $\int_0^T W_s\,ds$?

**Solution of Interview question 16.4.**

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

$$
\int_0^T\!\!\int_0^T \min(s,u)\,ds\,du = \frac{T^3}{3}.
$$

(Equivalently, $\int_0^T W_s\,ds = \int_0^T (T - s)\,dW_s$ by integration by parts, whose variance is $\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$ before $-2$, and how long does it take on average to hit either?

**Solution of Interview question 16.5.**

By [Proposition 16.3](#prop-iv-stochastic-calculus-exit), $\P = 2/(1 + 2) = \tfrac23$, and $\E[\tau] = 1 \times 2 = 2$.

*What the interviewer is looking for: optional stopping on $W$ and on $W^2 - t$.*

**Interview question 16.6 ★★ researcher, trader • systematic fund.**

$X_t = 0.5t + W_t$. What is the chance it hits $+1$ before $-1$?

**Solution of Interview question 16.6.**

With $\mu = 0.5$, $\sigma = 1$, $a = b = 1$: $(1 - e^{1})/(e^{-1} - e^{1}) = 1/(1 + e^{-1}) \approx 0.731$. The martingale is $e^{-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]$? A Monte Carlo with 50 steps gives a smaller number; why, and how do you fix it without more steps?

**Solution of Interview question 16.7.**

$2\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](#fig-iv-stochastic-calculus-reflect)). Fix it with a Brownian-bridge correction: between two grid values $x, y$ below the barrier, the path crosses with probability $\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 of Interview question 16.8.**

Mean $e^{0.08 \times 10} \approx 2.23$; median $e^{(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 $-\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 $W$ under it?

**Solution of Interview question 16.9.**

Take $\theta = (\mu - r)/\sigma = (0.08 - 0.03)/0.2 = 0.25$ and $d\mathbb Q/d\mathbb P = \exp(-0.25 W_T - 0.03125T)$. Under $\mathbb Q$, $W_t + 0.25t$ is a Brownian motion, so $W$ has drift $-0.25$, and $dS = 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 $S_0 = K = 100$, $\sigma = 20\%$, $T = 1$ and zero rates, price the cash-or-nothing digital paying 1 and the asset-or-nothing digital paying $S_T$ if $S_T > K$. Deduce the call price.

**Solution of Interview question 16.10.**

$d_1 = \sigma\sqrt T/2 = 0.1$, $d_2 = -0.1$. Cash-or-nothing: $\Phi(-0.1) \approx 0.4602$. Asset-or-nothing: $100\,\Phi(0.1)
\approx 53.98$. Call $= 53.98 - 100 \times 0.4602 \approx 7.97$, the Black–Scholes value (and close to $0.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 $\partial_t u + \tfrac12\partial_{xx}u = 0$ with $u(T, x) = x^2$ by writing $u$ as an expectation, and check it.

**Solution of Interview question 16.11.**

By Feynman–Kac with $dX = dW$, $u(t, x) = \E[(x + W_T - W_t)^2] = x^2 + (T - t)$. Check: $u_t = -1$, $\tfrac12 u_{xx} = 1$, sum 0; and $u(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 $X_t = \mu t + W_t$ with $\mu > 0$, what is the expected time to reach $+1$? What happens as $\mu \to 0$, and is that consistent with Brownian motion reaching $+1$ with probability one?

**Solution of Interview question 16.12.**

$X_\tau = 1$ and $X_t - \mu t$ is a martingale; optional stopping (with $\E[\tau] < \infty$ for $\mu > 0$) gives $1 - \mu\E[\tau] =
0$, so $\E[\tau] = 1/\mu$. As $\mu \to 0$ the expectation tends to infinity: driftless Brownian motion reaches $+1$ with probability one, but its hitting time has infinite mean (its density decays like $t^{-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 $W$ hits 1. Then $W_\tau = 1$, yet $W$ is a martingale started at 0. Why does optional stopping fail? Add a lower barrier at $-b$ and recover a correct statement.

**Solution of Interview question 16.13.**

$\tau$ is finite almost surely but $\E[\tau] = \infty$, and $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$, the stopped process is bounded, optional stopping holds, and $0 = \E[W_\tau] = p \times 1 - (1 - p)b$, so the chance of hitting 1 first is $b/(1 + b)$; it tends to one as $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.
