Quantitative Finance · Book 4 · Methods

Quantitative Methods

Quantitative Methods · Methods

3Itô Calculus

A junior researcher backtests a trend-following rule on ten years of daily closes: hold a position proportional to the distance of the close above its 20-day moving average. The Sharpe ratio is 5.4. The rule reads the closing price and the backtest credits it with the return into that same close; shifted by one day, so that a position decided at a close earns the next day’s return, the Sharpe ratio is −0.04-0.04. The “prices” were a pure random walk, with nothing to find. The first backtest was not an Itô integral: its integrand looked at the increment it was multiplied by, and collected the covariation of the position with the price, a quantity that exists on every random path. This chapter builds the Itô integral, whose integrand is fixed before the increment arrives, proves Itô’s formula, the chain rule with a second-order term that the rest of the series uses on every page, and ends with the two structural theorems (Lévy’s characterisation and martingale representation) that underlie the pricing of One Quant Book 5.

3.1 The Itô integral

A trading strategy holds HtH_t units of an asset whose price follows a Brownian motion; its gains over [0,T][0, T] should be ∫0THt dWt\int_0^T H_t\,dW_t. The paths of WW have infinite total variation (Theorem 2.12), so the integral cannot be defined path by path as a Stieltjes integral, and the choice of evaluation point in each interval matters in the limit. The Itô integral evaluates HH at the left point, which is the only choice a trader can make.

Definition 3.1 (Simple process, Itô integral)

A simple process is Ht=∑k=0n−1hk1(tk,tk+1](t)H_t = \sum_{k=0}^{n-1}h_k\mathbf 1_{(t_k, t_{k+1}]}(t) with 0=t0<⋯<tn=T0 = t_0 < \dots < t_n = T and each hkh_k bounded and Ftk\mathcal F_{t_k}-measurable. Its Itô integral is ∫0tHs dWs=∑khk(Wtk+1∧t−Wtk∧t)\int_0^t H_s\,dW_s = \sum_k h_k(W_{t_{k+1}\wedge t} - W_{t_k\wedge t}). For an adapted HH with E∫0THs2 ds<∞\E\int_0^T H_s^2\,ds < \infty, the Itô integral is the L2L^2 limit of the integrals of simple processes H(n)H^{(n)} with E∫0T(Hs(n)−Hs)2 ds→0\E\int_0^T(H^{(n)}_s - H_s)^2\,ds \to 0.

Theorem 3.2 (Itô isometry)

For adapted HH with E∫0THs2 ds<∞\E\int_0^T H_s^2\,ds < \infty, It=∫0tHs dWsI_t = \int_0^t H_s\,dW_s is a continuous square-integrable martingale with I0=0I_0 = 0 and

E[(∫0THs dWs)2]=E∫0THs2 ds,[I]t=∫0tHs2 ds.\E\Bigl[\Bigl(\int_0^T H_s\,dW_s\Bigr)^2\Bigr] = \E\int_0^T H_s^2\,ds, \qquad [I]_t = \int_0^t H_s^2\,ds.

Proof. For a simple process, with Δk=Wtk+1−Wtk\Delta_k = W_{t_{k+1}} - W_{t_k}: the cross terms E[hjhkΔjΔk]\E[h_jh_k\Delta_j\Delta_k], j<kj < k, vanish because hjhkΔjh_jh_k\Delta_j is Ftk\mathcal F_{t_k}-measurable and Etk[Δk]=0\E_{t_k}[\Delta_k] = 0; the square terms give E[hk2]E[Δk2]=E[hk2](tk+1−tk)\E[h_k^2]\E[\Delta_k^2] = \E[h_k^2](t_{k+1} - t_k). The same computation on [s,t][s, t] gives the martingale property. The integral is therefore an isometry from simple processes into L2L^2, extends to their closure, and the martingale property passes to L2L^2 limits (Doob’s inequality, Proposition 1.9, gives a continuous version). ∎

Example 3.3 (The integral of WW against itself)

On a partition of [0,T][0, T], ∑kWtkΔk=12∑k(Wtk+12−Wtk2)−12∑kΔk2\sum_k W_{t_k}\Delta_k = \tfrac12\sum_k(W_{t_{k+1}}^2 - W_{t_k}^2) - \tfrac12\sum_k\Delta_k^2. The first sum telescopes to 12WT2\tfrac12 W_T^2 and the second tends to 12T\tfrac12 T by Theorem 2.12:

∫0TWt dWt=12(WT2−T).\int_0^T W_t\,dW_t = \tfrac12\bigl(W_T^2 - T\bigr).

The right-point sums tend to 12(WT2+T)\tfrac12(W_T^2 + T), and the midpoint sums to 12WT2\tfrac12W_T^2, the ordinary calculus answer (Figure 3.1).

Sums approximating ∈t_01 W\,dW on one path (W_1 = 2.04) sampled at 2k points. The left-point sums converge to 1/2(W_12 - 1) = 1.58, the right-point sums to 2.58 (dashed lines); the midpoint sums equal 1/2W_12 = 2.08 exactly, whatever the grid. Data: the chapter’s tutorial, seeded.
Figure 3.1. Sums approximating ∫01W dW\int_0^1 W\,dW on one path (W1=2.04W_1 = 2.04) sampled at 2k2^k points. The left-point sums converge to 12(W12−1)=1.58\tfrac12(W_1^2 - 1) = 1.58, the right-point sums to 2.582.58 (dashed lines); the midpoint sums equal 12W12=2.08\tfrac12W_1^2 = 2.08 exactly, whatever the grid. Data: the chapter’s tutorial, seeded.

Definition 3.4 (Stratonovich integral)

The Stratonovich integral ∫0TXt∘dWt\int_0^T X_t\circ dW_t is the limit of the sums ∑k12(Xtk+Xtk+1)Δk\sum_k\tfrac12(X_{t_k} + X_{t_{k+1}})\Delta_k. For a continuous semimartingale XX it equals ∫0TXt dWt+12[X,W]T\int_0^T X_t\,dW_t + \tfrac12[X, W]_T.

The Stratonovich integral obeys the ordinary chain rule, which is why physicists modelling a smooth noise by a white one use it. It averages the integrand over the interval, which a trade cannot do: the position is set before the price move. Finance uses Itô.

3.2 The integral in a backtest

A backtest on a grid t0<t1<…t_0 < t_1 < \dots with positions θti\theta_{t_i} and prices StiS_{t_i} computes gains ∑iθti(Sti+1−Sti)\sum_i\theta_{t_i}(S_{t_{i+1}} - S_{t_i}): the left-point sum, an Itô integral, when θti\theta_{t_i} uses only information available at tit_i. A backtest that credits the position computed at ti+1t_{i+1} with the move into ti+1t_{i+1} computes the right-point sum instead, and

∑iθti+1ΔSi−∑iθtiΔSi=∑iΔθi ΔSi⟶[θ,S]T:\sum_i\theta_{t_{i+1}}\Delta S_i - \sum_i\theta_{t_i}\Delta S_i = \sum_i\Delta\theta_i\,\Delta S_i \longrightarrow [\theta, S]_T:

the look-ahead profit is the covariation of the position with the price, which is not zero on a random walk whenever the position responds to the latest price. The rule of the hook, θt=(St−Sˉt(20))/c\theta_t = (S_t - \bar S^{(20)}_t)/c with Sˉ(20)\bar S^{(20)} the 20-day moving average and cc chosen so that θ\theta has unit variance, puts weight (L−1)/L=0.95(L - 1)/L = 0.95 on the last increment: Figure 3.2 shows the timing and Figure 3.3 the result.

Which price move a position may earn. A position computed from the close at t earns the move from t to t + 1 (solid): the left-point sum. Crediting it with the move into t (dashed) multiplies the position by an increment it has already seen.
Figure 3.2. Which price move a position may earn. A position computed from the close at tt earns the move from tt to t+1t + 1 (solid): the left-point sum. Crediting it with the move into tt (dashed) multiplies the position by an increment it has already seen.

Proposition 3.5 (The look-ahead Sharpe ratio on a random walk)

Let SS be a random walk with daily increments σZt\sigma Z_t, ZtZ_t independent standard normal, and θt\theta_t a unit-variance linear function of past increments with correlation aa with the latest one. Then the same-bar gains θt ΔSt\theta_t\,\Delta S_t have mean aσa\sigma and standard deviation σ1+a2\sigma\sqrt{1 + a^2}, a daily Sharpe ratio of a/1+a2a/\sqrt{1 + a^2}, while the next-bar gains have mean zero. For the moving-average rule, a=(L−1)/L(∑m=1L−1(m/L)2)1/2a = \frac{(L-1)/L}{(\sum_{m=1}^{L-1}(m/L)^2)^{1/2}}.

Proof. Write θt=aZt+1−a2 Y\theta_t = aZ_t + \sqrt{1 - a^2}\,Y with YY standard normal and independent of ZtZ_t. Then E[θtZt]=a\E[\theta_tZ_t] = a and E[θt2Zt2]=a2E[Z4]+(1−a2)=1+2a2\E[\theta_t^2Z_t^2] = a^2\E[Z^4] + (1 - a^2) = 1 + 2a^2, so the variance is 1+a21 + a^2 (in units of σ2\sigma^2). For the rule, St−Sˉt=∑i=0L−2L−1−iLΔSt−iS_t - \bar S_t = \sum_{i=0}^{L-2}\frac{L-1-i}{L}\Delta S_{t-i}, whose variance is σ2∑m=1L−1(m/L)2\sigma^2\sum_{m=1}^{L-1}(m/L)^2 and whose coefficient on ΔSt\Delta S_t is (L−1)/L(L-1)/L. Next-bar gains θt−1ΔSt\theta_{t-1}\Delta S_t have zero mean because θt−1\theta_{t-1} is independent of ΔSt\Delta S_t. ∎

For L=20L = 20, a=0.382a = 0.382 and the annualised same-bar Sharpe ratio is 252×0.382/1.146=5.67\sqrt{252}\times 0.382/ \sqrt{1.146} = 5.67; over 400 simulated ten-year random walks it averages 5.69, and the honest backtest 0.00 with a standard deviation of 0.32, the noise one expects from ten years of a strategy with no edge.

The 20-day trend rule on one ten-year random walk with 1% daily volatility. Credited with the same bar it earns 958% of notional (Sharpe ratio 5.4), almost exactly the covariation of position and price (965%); credited with the next bar it earns -7\% (Sharpe ratio -0.04). Data: the chapter’s tutorial, seeded.
Figure 3.3. The 20-day trend rule on one ten-year random walk with 1% daily volatility. Credited with the same bar it earns 958% of notional (Sharpe ratio 5.4), almost exactly the covariation of position and price (965%); credited with the next bar it earns −7%-7\% (Sharpe ratio −0.04-0.04). Data: the chapter’s tutorial, seeded.

3.3 Itô’s formula in one and several dimensions

Definition 3.6 (Itô process, quadratic covariation)

An Itô process is Xt=X0+∫0tμs ds+∫0tσs dWsX_t = X_0 + \int_0^t\mu_s\,ds + \int_0^t\sigma_s\,dW_s, written dXt=μt dt+σt dWtdX_t = \mu_t\,dt + \sigma_t\,dW_t, with adapted μ\mu, σ\sigma such that ∫0T∣μs∣ ds\int_0^T|\mu_s|\,ds and ∫0Tσs2 ds\int_0^T\sigma_s^2\,ds are finite almost surely. The quadratic covariation of two continuous processes is the limit in probability [X,Y]t=lim⁡∑k(Xtk+1−Xtk)(Ytk+1−Ytk)[X, Y]_t = \lim\sum_k(X_{t_{k+1}} - X_{t_k})(Y_{t_{k+1}} - Y_{t_k}); for Itô processes driven by W1,W2W^1, W^2 with d⟨W1,W2⟩t=ρ dtd\langle W^1, W^2\rangle_t = \rho\,dt, d[X,Y]t=σtXσtYρ dtd[X, Y]_t = \sigma^X_t\sigma^Y_t\rho\,dt.

The bookkeeping rules are dt dt=0dt\,dt = 0, dt dW=0dt\,dW = 0, dWi dWj=ρij dtdW^i\,dW^j = \rho_{ij}\,dt: only products of two Brownian increments survive at first order in dtdt.

Theorem 3.7 (Itô’s formula)

If XX is an Itô process and f∈C1,2([0,T]×R)f \in C^{1,2}([0,T]\times\R), then

df(t,Xt)=∂tf dt+∂xf dXt+12∂xxf d[X]t=(∂tf+μt∂xf+12σt2∂xxf)dt+σt∂xf dWt.df(t, X_t) = \partial_tf\,dt + \partial_xf\,dX_t + \tfrac12\partial_{xx}f\,d[X]_t = \bigl(\partial_tf + \mu_t\partial_xf + \tfrac12\sigma_t^2\partial_{xx}f\bigr)dt + \sigma_t\partial_xf\,dW_t.

For X=(X1,…,Xd)X = (X^1, \dots, X^d) and f∈C1,2f \in C^{1,2}, df=∂tf dt+∑i∂if dXi+12∑i,j∂ijf d[Xi,Xj]df = \partial_tf\,dt + \sum_i\partial_if\,dX^i + \tfrac12\sum_{i,j}\partial_{ij}f\,d[X^i, X^j]; in particular d(XY)=X dY+Y dX+d[X,Y]d(XY) = X\,dY + Y\,dX + d[X, Y].

Partial proof. For f(x)f(x) with bounded derivatives and μ,σ\mu, \sigma simple, Taylor’s formula on a partition gives f(XT)−f(X0)=∑f′(Xtk)ΔXk+12∑f′′(ξk)(ΔXk)2f(X_T) - f(X_0) = \sum f'(X_{t_k})\Delta X_k + \tfrac12\sum f^{\prime\prime}(\xi_k)(\Delta X_k)^2. The first sum converges to ∫f′(X) dX\int f'(X)\,dX. In the second, f′′(ξk)f^{\prime\prime}(\xi_k) may be replaced by f′′(Xtk)f^{\prime\prime}(X_{t_k}) at a cost bounded by the modulus of continuity of f′′f^{\prime\prime} times ∑(ΔXk)2\sum(\Delta X_k)^2, which tends to zero, and ∑f′′(Xtk)((ΔXk)2−σtk2Δtk)\sum f^{\prime\prime}(X_{t_k})((\Delta X_k)^2 - \sigma_{t_k}^2\Delta t_k) tends to zero in L2L^2 as in Theorem 2.12. General ff, μ\mu, σ\sigma follow by localisation and approximation (Karatzas and Shreve, 1991, §3.3). ∎

Example 3.8 (The logarithm of a geometric Brownian motion)

For dS=μS dt+σS dWdS = \mu S\,dt + \sigma S\,dW, with f=ln⁡f = \ln: dln⁡S=dS/S−12d[S]/S2=(μ−12σ2)dt+σ dWd\ln S = dS/S - \tfrac12 d[S]/S^2 = (\mu - \tfrac12\sigma^2)dt + \sigma\,dW. The expected return is μ\mu but the expected log return, the rate at which the median grows, is μ−12σ2\mu - \tfrac12\sigma^2. With μ=10%\mu = 10\% and σ=40%\sigma = 40\%, the mean of S10/S0S_{10}/S_0 is e1=2.72e^{1} = 2.72 and its median e0.2=1.22e^{0.2} = 1.22 (Figure 3.4); the volatility decay of leveraged funds (One Quant Book 1, chapter 14) is the same correction applied twice.

Geometric Brownian motion with = 10\% and = 40\%: the mean grows at 10% a year, the median at 2%, and after ten years the 10th percentile (shaded band: 10th to 90th) is 0.24. Data: 100 000 paths simulated exactly, seeded.
Figure 3.4. Geometric Brownian motion with μ=10%\mu = 10\% and σ=40%\sigma = 40\%: the mean grows at 10% a year, the median at 2%, and after ten years the 10th percentile (shaded band: 10th to 90th) is 0.24. Data: 100 000 paths simulated exactly, seeded.

3.4 Local martingales and the stochastic exponential

An Itô integral ∫H dW\int H\,dW with only ∫0THs2 ds<∞\int_0^TH_s^2\,ds < \infty almost surely need not be integrable, let alone a martingale; it is one up to a sequence of stopping times.

Definition 3.9 (Local martingale)

An adapted process MM is a local martingale if there are stopping times τn↑∞\tau_n \uparrow \infty such that each stopped process Mt∧τnM_{t\wedge\tau_n} is a martingale.

Proposition 3.10 (Positive local martingales are supermartingales)

A local martingale bounded below, in particular a positive one, is a supermartingale. A local martingale MM with E[sup⁡s≤t∣Ms∣]<∞\E[\sup_{s\le t}|M_s|] < \infty for every tt is a martingale.

Proof. If M≥0M \ge 0, Fatou’s lemma gives Es[Mt]=Es[lim⁡nMt∧τn]≤lim inf⁡nMs∧τn=Ms\E_s[M_t] = \E_s[\lim_n M_{t\wedge\tau_n}] \le \liminf_n M_{s\wedge\tau_n} = M_s. Under the domination, dominated convergence replaces the inequality by an equality. ∎

The inequality can be strict: 1/∣Bt∣1/|B_t| for a three-dimensional Brownian motion started away from the origin is a positive local martingale whose expectation decreases, a strict local martingale. Such processes model price bubbles and are why chapter 5 checks that a candidate density process is a true martingale before using it to change the measure.

Definition 3.11 (Stochastic exponential)

The stochastic exponential of a continuous semimartingale XX with X0=0X_0 = 0 is E(X)t=exp⁡(Xt−12[X]t)\mathcal E(X)_t = \exp(X_t - \tfrac12[X]_t), the unique solution of dZ=Z dXdZ = Z\,dX, Z0=1Z_0 = 1.

By Itô’s formula, dexp⁡(X−12[X])=exp⁡(⋅)(dX−12d[X]+12d[X])=Z dXd\exp(X - \tfrac12[X]) = \exp(\cdot)(dX - \tfrac12 d[X] + \tfrac12 d[X]) = Z\,dX. With X=∫γ dWX = \int\gamma\,dW it is the positive local martingale exp⁡(∫γ dW−12∫γ2dt)\exp(\int\gamma\,dW - \tfrac12\int\gamma^2dt), the density process of every change of measure in chapter 5.

3.5 The representation theorem

Theorem 3.12 (Lévy’s characterisation)

A continuous local martingale MM with M0=0M_0 = 0 and [M]t=t[M]_t = t is a Brownian motion.

Proof. Admitted here. ∎

Theorem 3.13 (Martingale representation)

Let F\mathbb F be the filtration generated by a Brownian motion WW. Every square-integrable F\mathbb F-martingale MM has the form Mt=M0+∫0tHs dWsM_t = M_0 + \int_0^tH_s\,dW_s for a unique adapted HH with E∫0THs2 ds<∞\E\int_0^TH_s^2\,ds < \infty.

Proof. Admitted here. ∎

Both are proved in Karatzas and Shreve (1991, §3.3 and §3.4). The representation theorem is the mathematics of replication: if the only randomness is WW, every payoff’s conditional expectation is a stochastic integral against WW, and HH is the position that reproduces it. One Quant Book 5, chapter 1, builds on it the notions of a replicating portfolio and a complete market; it fails as soon as there are jumps (chapter 6) or more sources of risk than traded assets.

3.6 Tutorial: Itô sums and an honest backtest

Goal. See the left point of the Itô integral in numbers, check Itô’s formula on one path, and measure the look-ahead profit of a same-bar backtest. End state: Figures 3.1, 3.3 and 3.4 and the Sharpe ratios 5.4 and −0.04-0.04.

  1. The integrals. The running project’s gains are left-point sums; the same-bar version and the covariation that separates them are one line each.

    def gains(theta: np.ndarray, s: np.ndarray) -> np.ndarray:
        """Adapted (Ito) gains: position theta[i], chosen at t_i, earns s[i+1] - s[i].
    
        theta and s have the same length n + 1; the result has length n + 1 and starts at zero."""
        th, x = np.asarray(theta, dtype=float), np.asarray(s, dtype=float)
        if th.shape != x.shape:
            raise ValueError("theta and s must be aligned on the same times")
        return np.concatenate([[0.0], np.cumsum(th[:-1] * np.diff(x))])
    
    
    def same_bar_gains(theta: np.ndarray, s: np.ndarray) -> np.ndarray:
        """Anticipating gains: the position chosen at t_{i+1} is credited with the move into t_{i+1}."""
        th, x = np.asarray(theta, dtype=float), np.asarray(s, dtype=float)
        return np.concatenate([[0.0], np.cumsum(th[1:] * np.diff(x))])
    
    
    def covariation(x: np.ndarray, y: np.ndarray) -> np.ndarray:
        """Realised covariation [x, y] accumulated along the grid (quadratic variation when x is y)."""
        return np.concatenate([[0.0], np.cumsum(np.diff(np.asarray(x, float)) * np.diff(np.asarray(y, float)))])
    Listing 3.1. Adapted gains, same-bar gains and the covariation between them. code/firm/stochint/firm_stochint.py
  2. The rule: the distance of the close from its moving average, scaled to unit variance under a random walk, and the look-ahead mean of Proposition 3.5.

    def trend_signal(s: np.ndarray, L: int = LOOKBACK) -> np.ndarray:
        """theta_t = (S_t - MA_L(t)) / sd, scaled to unit variance under a random walk; zero while
        the window fills."""
        c = np.cumsum(np.concatenate([[0.0], s]))
        ma = np.full(s.size, np.nan)
        ma[L - 1:] = (c[L:] - c[:-L]) / L
        scale = SIG_D * math.sqrt(sum((m / L) ** 2 for m in range(1, L)))
        th = (s - ma) / scale
        th[: L - 1] = 0.0
        return th
    
    
    def spurious_mean(L: int = LOOKBACK, sig: float = SIG_D) -> float:
        """E[theta_t dS_t] for the same-bar rule on a random walk: (L-1)/L sig / sqrt(sum (m/L)^2)."""
        return (L - 1) / L * sig / math.sqrt(sum((m / L) ** 2 for m in range(1, L)))
    Listing 3.2. The trend signal and the expected look-ahead gain. code/methods/03-ito-calculus/python/qm_ito.py
  3. Run sums_table(), ito_check() (on a GBM path with 2142^{14} steps, ln⁡S1=0.70040\ln S_1 = 0.70040 against 0.700390.70039 from Itô’s formula and 0.781790.78179 without the −12 d[S]/S2-\tfrac12\,d[S]/S^2 term), backtest() and fig_ito.py.

What to change next. Replace the trend rule by a mean-reversion rule and predict the sign of the look-ahead bias; add a one-tick bid–ask bounce to the prices and see what the honest backtest of a mean-reversion rule then reports.

3.7 Build: discrete stochastic integrals

Purpose. Every backtest of the miniature firm computes its P&L through these functions, so that a position can earn only the price move after it is decided, and a look-ahead leaves a measurable trace.

Interface. gains(theta, s); same_bar_gains(theta, s); covariation(x, y); lookahead_test(theta, s) returning the same-bar excess, the covariation it equals, a tt-statistic and the identity error; riemann_sums(h, x, point).

Rules. Positions and prices are aligned on the same timestamps and the function, not the caller, shifts them; the identity same-bar −- adapted == covariation holds to rounding.

Acceptance tests. code/firm/stochint/tests/: on random walks the adapted gains of any rule have mean zero; the same-bar gains of the trend rule have the mean of Proposition 3.5; the identity holds to 10−1210^{-12}; the three Riemann sums of ∫W dW\int W\,dW converge to their limits.

Stretch. Timestamps with latencies (a position becomes live some microseconds after its signal); transaction costs as a function of ∣Δθ∣|\Delta\theta|.

Sources and further reading

  • K. Itô, “Stochastic integral”, Proceedings of the Imperial Academy, Tokyo 20, 1944.
  • K. Itô, “On a formula concerning stochastic differentials”, Nagoya Mathematical Journal 3, 1951.
  • R. L. Stratonovich, “A new representation for stochastic integrals and equations”, SIAM Journal on Control 4, 1966.
  • I. Karatzas and S. E. Shreve, Brownian Motion and Stochastic Calculus, Springer, 2nd ed., 1991.

3.8 Exercises

Exercise 3.1 ★

Compute E[(∫01Wt dWt)2]\E[(\int_0^1W_t\,dW_t)^2] with the isometry and check it with Example 3.3.

Solution

Solution of Exercise 3.1.

E∫01Wt2 dt=∫01t dt=12\E\int_0^1W_t^2\,dt = \int_0^1t\,dt = \tfrac12. With Example 3.3, Var⁡(12(W12−1))=14Var⁡(W12)=14×2=12\Var(\tfrac12(W_1^2 - 1)) = \tfrac14\Var(W_1^2) = \tfrac14 \times 2 = \tfrac12, and the mean is zero.

Exercise 3.2 ★

Write d(Wt3)d(W_t^3) with Itô’s formula, and deduce E[Wt3]\E[W_t^3] and a martingale built from W3W^3.

Solution

Solution of Exercise 3.2.

d(W3)=3W2 dW+3W dtd(W^3) = 3W^2\,dW + 3W\,dt. Taking expectations, E[Wt3]=3∫0tE[Ws] ds=0\E[W_t^3] = 3\int_0^t\E[W_s]\,ds = 0, and Wt3−3∫0tWs dsW_t^3 - 3\int_0^tW_s\,ds is a martingale.

Exercise 3.3 ★

A stock follows a geometric Brownian motion with μ=10%\mu = 10\% and σ=40%\sigma = 40\%. What are the mean and the median of S10/S0S_{10}/S_0, and at what volatility would the median not grow at all?

Solution

Solution of Exercise 3.3.

Mean e1=2.72e^{1} = 2.72, median e(0.10−0.08)×10=1.22e^{(0.10 - 0.08) \times 10} = 1.22. The median is flat when σ2=2μ\sigma^2 = 2\mu, σ=0.2=44.7%\sigma = \sqrt{0.2} = 44.7\%.

Exercise 3.4 ★★

Show that eWt−t/2e^{W_t - t/2} is a martingale and compute E[e2W1]\E[e^{2W_1}].

Solution

Solution of Exercise 3.4.

It is E(W)t\mathcal E(W)_t: dZ=Z dWdZ = Z\,dW, and E∫0tZs2 ds=∫0tes ds<∞\E\int_0^tZ_s^2\,ds = \int_0^te^s\,ds < \infty, so the Itô integral is a true martingale. E[e2W1]=e2=7.39\E[e^{2W_1}] = e^{2}= 7.39 (the moment generating function of N(0,1)\mathcal N(0,1) at 2).

Exercise 3.5 ★★

Use the product rule on tWttW_t to write ∫01Wt dt\int_0^1 W_t\,dt as a stochastic integral, and compute its variance.

Solution

Solution of Exercise 3.5.

d(tWt)=Wt dt+t dWtd(tW_t) = W_t\,dt + t\,dW_t, so ∫01Wt dt=W1−∫01t dWt=∫01(1−t) dWt\int_0^1W_t\,dt = W_1 - \int_0^1t\,dW_t = \int_0^1(1 - t)\,dW_t, with variance ∫01(1−t)2dt=13\int_0^1(1 - t)^2dt = \tfrac13 by the isometry.

Exercise 3.6 ★★

X=W1X = W^1 and Y=2W1+W2Y = 2W^1 + W^2 with W1,W2W^1, W^2 independent. Compute [X,Y]t[X, Y]_t, [Y]t[Y]_t and the instantaneous correlation of XX and YY.

Solution

Solution of Exercise 3.6.

[X,Y]t=2t[X, Y]_t = 2t, [Y]t=5t[Y]_t = 5t, correlation 2/5=0.8942/\sqrt5 = 0.894.

Exercise 3.7 ★★★

Coding. Repeat the backtest with a 60-day moving average: compute the look-ahead Sharpe ratio from Proposition 3.5 and its average over 100 simulated ten-year walks.

Solution

Solution of Exercise 3.7.

L=60L = 60 gives a=0.223a = 0.223 and a look-ahead Sharpe ratio of 3.45; the average over 100 seeded walks is 3.47. A slower average puts less weight on the last increment, so the bias is smaller, but it is still enormous.

Exercise 3.8 ★★★

Find the flaw. “Our rule decides from the closing price and trades in the closing auction; the backtest credits it with the next day’s return, so there is no look-ahead.”

Solution

Solution of Exercise 3.8.

The signal uses the closing price, which is not known until the closing auction in which the rule claims to trade has printed: the decision is not adapted to the information available when the order must be sent. Compute the signal from the auction’s indicative price published before the order deadline (chapter 1), or trade at the next open.

3.9 Problem: The Look-Ahead in the Backtest

Problem 3.1

Weekend problem — a Sharpe ratio of 5.4 on a random walk

The log price is a random walk with 1% daily volatility. The rule holds θt=(St−Sˉt(20))/c\theta_t = (S_t - \bar S^{(20)}_t)/c, with cc making θ\theta of unit variance; the flawed backtest credits θt\theta_t with St−St−1S_t - S_{t-1}, the honest one with St+1−StS_{t+1} - S_t.

Part I — The rule.

  1. What is cc?
  2. What is the correlation aa of θt\theta_t with the day’s increment?
  3. What are the mean and standard deviation of the same-bar gain per day?
  4. What is the annualised same-bar Sharpe ratio?
  5. What does the honest backtest earn on average, and why?

Part II — The simulation.

  1. What Sharpe ratios does the seeded ten-year history give for the two backtests?
  2. Over 400 histories, what are the mean and standard deviation of each?
  3. Check the identity same-bar −- honest == covariation on the seeded history.
  4. What tt-statistic does lookahead_test report for the seeded history?
  5. Why is the honest Sharpe ratio’s standard deviation about 1/101/\sqrt{10}?

Part III — The Itô view.

  1. Write the same-bar P&L as an Itô integral plus a covariation.
  2. Why is the expectation of the Itô part zero?
  3. What are the look-ahead Sharpe ratios for windows of 5, 10 and 60 days?
  4. If the flawed backtest ran on five-minute bars, 78 a day, with the same rule in bars, what would its annualised Sharpe ratio be?
  5. Would trading at the next day’s open instead of the close remove the bias?

Part IV — Judgement.

  1. How would you detect this error in someone else’s backtest?
  2. Is look-ahead bias always positive?
  3. On real prices with a bid–ask bounce, what else can produce a covariation between position and price?
  4. State the named result: the look-ahead Sharpe ratio of the same-bar trend rule on a random walk.
  5. In one sentence: what makes a backtest an Itô integral?
Solution

Solution of Problem 3.1.

1. c=0.01 (∑m=119(m/20)2)1/2=0.01×2.485=0.0248c = 0.01\,(\sum_{m=1}^{19}(m/20)^2)^{1/2} = 0.01 \times 2.485 = 0.0248. 2. a=0.95/2.485=0.382a = 0.95/2.485 = 0.382. 3. Mean aσ=0.0038a\sigma = 0.0038 and standard deviation σ1+a2=0.0107\sigma\sqrt{1 + a^2} = 0.0107 per day, per unit of position. 4. 252×0.382/1.070=5.67\sqrt{252} \times 0.382/1.070 = 5.67. 5. Zero: θt\theta_{t} is independent of St+1−StS_{t+1} - S_t. 6. 5.43 same-bar, −0.04-0.04 next-bar. 7. Same-bar 5.69±0.135.69 \pm 0.13; next-bar 0.00±0.320.00 \pm 0.32. 8. Both equal 9.653 (965% of notional); the difference is 2×10−142 \times 10^{-14}. 9. 34.9. 10. With no edge the annualised Sharpe ratio estimated over TT years has a standard error of about 1/T1/\sqrt T (chapter 11): 0.320.32 for ten years. 11. ∑θtΔSt=∑θt−1ΔSt+∑ΔθtΔSt\sum\theta_t\Delta S_t = \sum\theta_{t-1}\Delta S_t + \sum\Delta\theta_t\Delta S_t: an Itô sum plus the covariation [θ,S][\theta, S]. 12. Its integrand is adapted, so it is a martingale started at zero. 13. 9.36, 7.47 and 3.45. 14. The daily Sharpe ratio per bar is unchanged, and annualising over 252×78252 \times 78 bars multiplies it by 78\sqrt{78}: 50. 15. Yes, if the signal uses only the close and the gains start at the next open; the position then misses the overnight move, which the honest backtest must also leave out. 16. Shift the positions by one bar and see whether the performance collapses; run lookahead_test, or regress the daily P&L on ΔθtΔSt\Delta\theta_t\Delta S_t; and read the timestamps of the signal’s inputs. 17. No: its sign is the sign of [θ,S][\theta, S]; a mean-reversion rule, which sells as the price rises, has a negative look-ahead bias. 18. The bounce between bid and ask makes last-trade prices mean-revert; an honest mean-reversion rule on those prices “earns” the bounce, which costs the spread to capture (One Quant Book 10). 19. Named result: the look-ahead in the backtest: on a random walk the same-bar backtest of a unit-variance rule with correlation aa to the latest increment has a daily Sharpe ratio a/1+a2a/\sqrt{1 + a^2}; for the 20-day trend rule, a=0.382a = 0.382 and the annualised Sharpe ratio is 5.67 (5.69 in simulation), against zero for the Itô sum. 20. Each position is fixed from information available before the price move it is multiplied by.

3.10 Interview questions

Interview question 3.1 ★ researcher

Compute ∫0TWt dWt\int_0^TW_t\,dW_t. Why is it not 12WT2\tfrac12W_T^2?

Solution

Solution of Interview question 3.1.

12(WT2−T)\tfrac12(W_T^2 - T). The left-point sums differ from 12∑Δ(W2)\tfrac12\sum\Delta(W^2) by 12∑(ΔW)2\tfrac12\sum(\Delta W)^2, which tends to TT: the quadratic variation does not vanish.

What the interviewer is looking for: the telescoping identity and the quadratic variation.

Interview question 3.2 ★ trader, researcher

A stock has an expected return of 10% and a volatility of 40%. What is its expected log return, and what does a typical holder earn over ten years?

Solution

Solution of Interview question 3.2.

μ−σ2/2=2%\mu - \sigma^2/2 = 2\% a year. The mean of S10/S0S_{10}/S_0 is e1=2.72e^{1} = 2.72 but the median is 1.221.22, and a tenth of holders end below 0.24: the mean is carried by a few large outcomes.

What the interviewer is looking for: Itô’s correction and mean versus median.

Interview question 3.3 ★★ researcher

Is Wt2W_t^2 a martingale? Find the process you must subtract, and the variance of ∫0TW dW\int_0^TW\,dW.

Solution

Solution of Interview question 3.3.

No: d(W2)=2W dW+dtd(W^2) = 2W\,dW + dt, so Wt2−tW_t^2 - t is the martingale. Var⁡(∫0TW dW)=∫0Tt dt=T2/2\Var(\int_0^TW\,dW) = \int_0^Tt\,dt = T^2/2.

What the interviewer is looking for: Itô’s formula and the isometry.

Interview question 3.4 ★★ developer, researcher

How would you design a backtesting engine that cannot commit look-ahead by construction?

Solution

Solution of Interview question 3.4.

Drive it by events in time order: every datum carries the time it became available, the strategy sees an as-of view, and an order it emits at tt can fill only against prices after tt plus a latency. The engine, not the strategy, applies positions to the next interval, and a test compares every run with a shifted run and flags covariation between positions and concurrent returns.

What the interviewer is looking for: availability timestamps, as-of joins, and a structural shift.

Interview question 3.5 ★★ researcher, bank

What is a local martingale that is not a martingale, and why should a pricing quant care?

Solution

Solution of Interview question 3.5.

A process that is a martingale only up to a sequence of stopping times; a positive one is a supermartingale and may lose expectation, like 1/∣Bt∣1/|B_t| for a three-dimensional Brownian motion. A candidate density for a change of measure, or a deflated price, that is a strict local martingale gives prices that violate put–call parity or a measure that is not a probability.

What the interviewer is looking for: localisation, Fatou, and the pricing consequence.

Interview question 3.6 ★★★ researcher, mle

Itô or Stratonovich: which does finance use, which does physics use, and why?

Solution

Solution of Interview question 3.6.

Finance uses Itô: a position must be set before the price move, which is the left point, and the resulting gains are martingales under the right measure. Physics often uses Stratonovich, the limit of smooth noise, because it keeps the ordinary chain rule. They differ by 12[X,W]\tfrac12[X,W].

What the interviewer is looking for: non-anticipation versus smooth-noise limits.

Terms defined in this chapter

See all 2333 terms in the glossary