Quantitative Finance · Book 4 · Methods

Quantitative Methods

Quantitative Methods · Methods

26Monte Carlo

The overnight batch values 40 000 path-dependent trades with 100 000 paths each. The standard error on the book is 80 000 dollars, and the risk manager wants it under 20 000 by tomorrow. Monte Carlo error falls like one over the square root of the number of paths, so a factor of four in error is a factor of sixteen in paths, and sixteen times the machines is not on offer. The alternative is to make each path worth more. This chapter builds the estimator and its generators, then the variance-reduction techniques that change the constant (antithetic variates, control variates, stratification, importance sampling), the low-discrepancy points that change the rate, and the discretisation and multilevel methods that decide what a path costs.

26.1 Estimators and generators

Definition 26.1 (Monte Carlo method, variance reduction)

The Monte Carlo method estimates μ=E[f(X)]\mu = \E[f(X)] by the average μ^n=1n∑i=1nf(Xi)\hat\mu_n = \frac1n\sum_{i=1}^nf(X_i) of independent draws. Variance reduction is any change of estimator that keeps E[μ^n]=μ\E[\hat\mu_n] = \mu (or makes the bias negligible) and lowers its variance at equal cost.

Proposition 26.2 (Error and cost of the Monte Carlo estimator)

If σ2=Var⁡(f(X))<∞\sigma^2 = \Var(f(X)) < \infty, then n(μ^n−μ)⇒N(0,σ2)\sqrt n(\hat\mu_n - \mu) \Rightarrow \mathcal N(0, \sigma^2), so μ^n±1.96 sn/n\hat\mu_n \pm 1.96\,s_n/\sqrt n is an asymptotic 95% interval. If one draw costs cc, the cost of reaching standard error ϵ\epsilon is cσ2/ϵ2c\sigma^2/\epsilon^2: of two unbiased estimators, the better is the one with the smaller product of variance and cost per draw.

Proof. The first statement is the central limit theorem for independent identically distributed draws, with Slutsky’s lemma for the estimated sns_n. The second: σ/n=ϵ\sigma/\sqrt n = \epsilon needs n=σ2/ϵ2n = \sigma^2/\epsilon^2 draws. ∎

The rate n−1/2n^{-1/2} does not depend on the dimension, which is why Monte Carlo prices 64-date averages and 30-asset baskets that no grid can reach; the constant σ2c\sigma^2c is where the work is. On the batch’s representative trade, an arithmetic-average call on 64 fixings of a geometric Brownian motion (S0=K=100S_0 = K = 100, r=3%r = 3\%, σ=25%\sigma = 25\%, one year), 2142^{14} paths give 6.495 with a standard error of 0.077; the price is 6.4788.

Definition 26.3 (Pseudo-random and counter-based generators, inverse transform sampling)

A pseudo-random number generator is a deterministic recurrence sk+1=F(sk)s_{k+1} = F(s_k), uk=G(sk)u_k = G(s_k) whose outputs pass statistical tests of independent uniformity; the Mersenne Twister (Matsumoto and Nishimura, 1998) and PCG (O’Neill, 2014; NumPy’s default) are examples. A counter-based generator computes u=Gk(c)u = G_k(c) directly from a counter cc and a key kk with a bijection GkG_k, so that any draw can be produced without its predecessors; Philox (Salmon, Moraes, Dror and Shaw, 2011) is one. Inverse transform sampling turns a uniform UU into a draw F−1(U)F^{-1}(U) of the distribution function FF.

A counter-based generator is what makes a distributed batch reproducible. The engine gives path jj of trade ii the counter (b,j,i,0)(b, j, i, 0) for its bb-th block of four numbers, so the path’s numbers do not depend on how the paths are split among machines, on the order in which they run, or on how many there are: rerunning one path to debug a trade reproduces it bit for bit. The kit’s Philox4x64-10 reproduces NumPy’s implementation block for block, in Python, C++20 and Rust (the C++ version is listed in Section 26.5). Normals come from the inverse transform with Acklam’s rational approximation of Φ−1\Phi^{-1} (relative error below 1.15×10−91.15 \times 10^{-9}), which, unlike Box–Muller, maps one uniform to one normal: the property low-discrepancy points need.

26.2 Variance reduction and importance sampling

Definition 26.4 (Antithetic variates, control variate, stratified sampling)

Antithetic variates pair each draw ZZ with −Z-Z (each uniform UU with 1−U1 - U) and average 12(f(Z)+f(−Z))\frac12(f(Z) + f(-Z)). A control variate is a variable CC with known mean, used in μ^β=1n∑i(Yi−β(Ci−EC))\hat\mu_\beta = \frac1n\sum_i(Y_i - \beta(C_i - \E C)). Stratified sampling partitions the space of an input into strata of known probability psp_s and draws a fixed number ns=npsn_s = np_s in each.

Proposition 26.5 (Optimal control-variate coefficient)

Var⁡(Y−β(C−EC))\Var(Y - \beta(C - \E C)) is minimised at β∗=Cov⁡(Y,C)/Var⁡(C)\beta^* = \Cov(Y, C)/\Var(C), where it equals (1−ρ2)Var⁡(Y)(1 - \rho^2)\Var(Y) with ρ=Corr(Y,C)\rho = \mathrm{Corr}(Y, C).

Proof. Var⁡(Y−βC)=Var⁡Y−2βCov⁡(Y,C)+β2Var⁡C\Var(Y - \beta C) = \Var Y - 2\beta\Cov(Y, C) + \beta^2\Var C is a quadratic in β\beta minimised at β∗\beta^*; substituting gives Var⁡Y−Cov⁡(Y,C)2/Var⁡C=(1−ρ2)Var⁡Y\Var Y - \Cov(Y, C)^2/\Var C = (1 - \rho^2)\Var Y. ∎

For the average-price call, the geometric average G=(∏kStk)1/64G = (\prod_kS_{t_k})^{1/64} is lognormal and its call has a closed form (Kemna and Vorst, 1990): 6.1793. Its payoff has correlation 0.99941 with the arithmetic payoff’s, so 1−ρ2=0.00121 - \rho^2 = 0.0012 and, with β=1.04\beta = 1.04 estimated from the same paths, the variance falls by a factor of 853 at the same number of paths. Antithetic pairs do much less: the two payoffs of a pair have correlation −0.43-0.43, a factor of 1.8 at equal payoff evaluations. Stratification is the idea behind the next section: it removes the variance between strata, and a low-discrepancy point set stratifies every coordinate, and many of their products, at once.

Definition 26.6 (Importance sampling)

Importance sampling draws XX from a density gg instead of ff and averages h(X)f(X)/g(X)h(X)f(X)/g(X), the payoff times the likelihood ratio (a Radon–Nikodym derivative); it is unbiased whenever g>0g > 0 where hf≠0hf \ne 0.

Proposition 26.7 (Zero-variance importance density)

For h≥0h \ge 0 with μ=Ef[h(X)]>0\mu = \E_f[h(X)] > 0, the density g∗=hf/μg^* = hf/\mu makes h(X)f(X)/g∗(X)=μh(X)f(X)/g^*(X) = \mu for every draw: the estimator has zero variance.

Proof. Substitute: hf/g∗=hfμ/(hf)=μhf/g^* = hf\mu/(hf) = \mu wherever h>0h > 0, and g∗g^* puts no mass where h=0h = 0. ∎

The optimal density needs the answer, but it says where to look: sample in proportion to where the payoff lives. For a digital paying if ST>250S_T > 250 (probability 1.21×10−41.21 \times 10^{-4}, the normal driver above z∗=3.67z^* = 3.67), 100 000 plain draws produce six hits and a relative standard error of 20%. Shifting the driver’s mean to θ\theta and weighting each draw by e−θZ+θ2/2e^{-\theta Z + \theta^2/2} brings it to 0.64% at θ=3.8\theta = 3.8, a variance factor of about 1 000 (Figure 26.1); shifting too far makes it worse again, as the weights of the few draws that matter explode.

Importance sampling for a digital paying if S_T > 250 (S_0 = 100, = 25\%, one year; probability 1.21 × 10-4): relative standard error of 100 000 draws against the mean shift of the normal driver. Data: the chapter’s tutorial, seeded.
Figure 26.1. Importance sampling for a digital paying if ST>250S_T > 250 (S0=100S_0 = 100, σ=25%\sigma = 25\%, one year; probability 1.21×10−41.21 \times 10^{-4}): relative standard error of 100 000 draws against the mean shift of the normal driver. Data: the chapter’s tutorial, seeded.

26.3 Low-discrepancy sequences

Definition 26.8 (Low-discrepancy sequence, Sobol sequence, quasi-Monte Carlo)

The star discrepancy Dn∗D_n^* of points x1,…,xnx_1, \dots, x_n in [0,1)d[0, 1)^d is the largest difference, over boxes [0,a)[0, a), between the fraction of points in the box and its volume. A low-discrepancy sequence has Dn∗=O((log⁡n)d/n)D_n^* = O((\log n)^d/n). The Sobol sequence (Sobol, 1967) is a base-2 low-discrepancy sequence built coordinate by coordinate from primitive polynomials and direction numbers, by exclusive-or of binary digits. Quasi-Monte Carlo replaces the random draws of Monte Carlo by such points.

Proposition 26.9 (Koksma–Hlawka inequality)

For ff of bounded variation V(f)V(f) in the sense of Hardy and Krause, ∣1n∑if(xi)−∫[0,1)df∣≤V(f) Dn∗\bigl|\frac1n\sum_if(x_i) - \int_{[0,1)^d}f\bigr| \le V(f)\,D_n^*.

The bound gives quasi-Monte Carlo a rate close to 1/n1/n for smooth integrands of moderate effective dimension, but it is a worst-case bound that cannot be estimated from the points. Randomisation restores an error estimate.

Definition 26.10 (Randomised quasi-Monte Carlo, Brownian bridge construction)

Randomised quasi-Monte Carlo randomises a low-discrepancy set so that each point is uniform while the set keeps its structure, and estimates the error from independent replicates. The kit uses Owen’s nested uniform scrambling (1995): each binary digit of each coordinate is flipped by a random bit attached to the node of the binary tree that its leading digits define. The Brownian bridge construction assigns the first coordinate to WTW_T, the next to WT/2W_{T/2} given its ends, and so on down the levels, so that the first coordinates, where low-discrepancy points are best, carry most of the variance of the path.

Figure 26.2 shows why: 256 scrambled Sobol points in two dimensions put exactly one point in each of 256 dyadic boxes of every shape, where independent draws leave gaps and clusters. On the average-price call with 2142^{14} paths and 32 independent scrambles, scrambled Sobol points with the increments in time order reduce the variance by a factor of about 34; with the Brownian bridge construction by about 2 500; with the bridge and the control variate together by about 37 000, a standard error 190 times smaller at the same number of paths. The error also falls faster than n−1/2n^{-1/2}: fitted slopes between −0.7-0.7 and −0.8-0.8 from 262^6 to 2152^{15} paths (Figure 26.3).

256 points in the unit square: independent Philox uniforms and the first two coordinates of Owen-scrambled Sobol points. Data: the chapter’s tutorial, seeded.
Figure 26.2. 256 points in the unit square: independent Philox uniforms and the first two coordinates of Owen-scrambled Sobol points. Data: the chapter’s tutorial, seeded.
Standard error of the average-price call (64 fixings) against the number of paths: plain Monte Carlo and the control variate (slope -1/2), and scrambled Sobol points (16 independent scrambles) with increments in time order, with the Brownian bridge construction, and with the bridge and the control variate. Data: the chapter’s tutorial, seeded.
Figure 26.3. Standard error of the average-price call (64 fixings) against the number of paths: plain Monte Carlo and the control variate (slope −12-\frac12), and scrambled Sobol points (16 independent scrambles) with increments in time order, with the Brownian bridge construction, and with the bridge and the control variate. Data: the chapter’s tutorial, seeded.

26.4 Discretisation and multilevel methods

Definition 26.11 (Strong and weak orders of convergence, Milstein scheme)

A scheme with step hh has strong order of convergence γ\gamma if E∣XTh−XT∣≤Chγ\E|X_T^h - X_T| \le Ch^\gamma, and weak order of convergence β\beta if ∣Eg(XTh)−Eg(XT)∣≤Chβ|\E g(X_T^h) - \E g(X_T)| \le Ch^\beta for smooth gg. The Milstein scheme for dX=a(X) dt+b(X) dWdX = a(X)\,dt + b(X)\,dW adds to the Euler–Maruyama step the term 12b(X)b′(X)((ΔW)2−h)\frac12b(X)b'(X)((\Delta W)^2 - h).

Proposition 26.12 (Orders of Euler and Milstein)

Under Lipschitz and growth conditions (and smoothness of aa, bb for Milstein), the Euler–Maruyama scheme has strong order 12\frac12 and weak order 1, and the Milstein scheme strong order 1 (Kloeden and Platen, 1992).

Idea. The Euler step misses the double stochastic integral ∫ ⁣ ⁣∫dW dW=12((ΔW)2−h)\int\!\!\int dW\,dW = \frac12((\Delta W)^2 - h), of size hh with mean zero, times bb′bb'; these errors add like a random walk over 1/h1/h steps, h1/h=h1/2h\sqrt{1/h} = h^{1/2} pathwise, while their means cancel, leaving an O(h)O(h) bias in law. Milstein keeps that term, and the next missing terms are of order h3/2h^{3/2} per step. ∎

A price needs the weak order; a hedge simulated along the path, or a multilevel estimator, needs the strong one. On a geometric Brownian motion with σ=50%\sigma = 50\%, driven by the same increments as the exact solution, the fitted strong slopes are 0.49 for Euler and 0.89 for Milstein, and the weak error of the mean is exactly X0∣(1+μh)n−eμT∣X_0|(1 + \mu h)^n - e^{\mu T}|, slope 1.00 (Figure 26.4).

Strong error |X_Th - X_T| of the Euler and Milstein schemes (20 000 paths of a geometric Brownian motion, = 5\%, = 50\%, X_0 = 100, one year) and the exact weak error of the mean, against the time step. Data: the chapter’s tutorial, seeded.
Figure 26.4. Strong error E∣XTh−XT∣\E|X_T^h - X_T| of the Euler and Milstein schemes (20 000 paths of a geometric Brownian motion, μ=5%\mu = 5\%, σ=50%\sigma = 50\%, X0=100X_0 = 100, one year) and the exact weak error of the mean, against the time step. Data: the chapter’s tutorial, seeded.

Definition 26.13 (Multilevel Monte Carlo)

Multilevel Monte Carlo (Giles, 2008) writes the finest-level expectation as a telescoping sum EPL=EP0+∑l=1LE[Pl−Pl−1]\E P_L = \E P_0 + \sum_{l=1}^L\E[P_l - P_{l-1}], where PlP_l is the payoff computed with step hl=2−lTh_l = 2^{-l}T, and estimates each term independently, with PlP_l and Pl−1P_{l-1} in each correction computed from the same Brownian path.

Proposition 26.14 (Complexity of multilevel Monte Carlo)

If the bias of PlP_l is O(2−αl)O(2^{-\alpha l}), the variance of the correction Vl=O(2−βl)V_l = O(2^{-\beta l}) and its cost Cl=O(2γl)C_l = O(2^{\gamma l}), with α≥12min⁡(β,γ)\alpha \ge \frac12\min(\beta, \gamma), then a mean square error ϵ2\epsilon^2 costs O(ϵ−2)O(\epsilon^{-2}) if β>γ\beta > \gamma, O(ϵ−2(log⁡ϵ)2)O(\epsilon^{-2}(\log\epsilon)^2) if β=γ\beta = \gamma and O(ϵ−2−(γ−β)/α)O(\epsilon^{-2 - (\gamma - \beta)/\alpha}) if β<γ\beta < \gamma; standard Monte Carlo costs O(ϵ−2−γ/α)O(\epsilon^{-2 - \gamma/\alpha}).

Idea. Minimising the cost ∑lNlCl\sum_lN_lC_l subject to the variance constraint ∑lVl/Nl=ϵ2/2\sum_lV_l/N_l = \epsilon^2/2 gives Nl∝Vl/ClN_l \propto\sqrt{V_l/C_l} and a total cost

2ϵ−2(∑lVlCl)2;2\epsilon^{-2}\Bigl(\sum_l\sqrt{V_lC_l}\Bigr)^2;

the sum is dominated by the coarsest levels if β>γ\beta > \gamma, by the finest if β<γ\beta < \gamma, and grows like L∼log⁡ϵ−1L \sim \log\epsilon^{-1} if they are equal. The finest level LL is set by the bias, 2−αL∼ϵ2^{-\alpha L} \sim \epsilon. ∎

The strong order sets β\beta: Milstein on a Lipschitz payoff gives β=2>γ=1\beta = 2 > \gamma = 1, and the corrections’ variances in the tutorial fall by a factor of about four per level (0.23, 0.060, 0.016, 0.0045, 0.0012, 0.00030, 0.000079). For a European call (α=1\alpha = 1), the driver listed in Section 26.5 reaches a root mean square error of 0.005 with 7 levels at a cost of 3.2×1073.2 \times 10^7 time steps, where standard Monte Carlo at the same finest step would need 3.0×1093.0 \times 10^9: a factor of 94, which grows as ϵ\epsilon falls (8, 20, 45, 94 for ϵ\epsilon from 0.04 to 0.005; Figure 26.5).

Cost of pricing a European call (S_0 = K = 100, r = 3\%, = 25\%, one year) to a target root mean square error: multilevel Monte Carlo with Milstein corrections against standard Monte Carlo at the same finest step. Data: the chapter’s tutorial, seeded.
Figure 26.5. Cost of pricing a European call (S0=K=100S_0 = K = 100, r=3%r = 3\%, σ=25%\sigma = 25\%, one year) to a target root mean square error: multilevel Monte Carlo with Milstein corrections against standard Monte Carlo at the same finest step. Data: the chapter’s tutorial, seeded.

26.5 Tutorial: sixteen times fewer machines

Goal. Value the batch’s representative trade five ways and measure each estimator’s variance at equal paths. End state: the factors 1.8, 853, 34, 2 500 and 37 000 and Figure 26.3.

  1. Counter-based uniforms. Philox4x64-10 in C++20, reproducing NumPy’s Philox block for block.

    inline Block philox4x64(Block c, std::array<std::uint64_t, 2> k) {
        constexpr std::uint64_t M0 = 0xD2E7470EE14C6C93ULL, M1 = 0xCA5A826395121157ULL;
        constexpr std::uint64_t W0 = 0x9E3779B97F4A7C15ULL, W1 = 0xBB67AE8584CAA73BULL;
        for (int round = 0; round < 10; ++round) {
            const unsigned __int128 p0 = static_cast<unsigned __int128>(M0) * c[0];
            const unsigned __int128 p1 = static_cast<unsigned __int128>(M1) * c[2];
            c = {static_cast<std::uint64_t>(p1 >> 64) ^ c[1] ^ k[0], static_cast<std::uint64_t>(p1),
                 static_cast<std::uint64_t>(p0 >> 64) ^ c[3] ^ k[1], static_cast<std::uint64_t>(p0)};
            k = {k[0] + W0, k[1] + W1};
        }
        return c;
    }
    Listing 26.1. Philox4x64-10: ten rounds of two wide multiplications (C++20). code/firm/mcengine/cpp/firm_mcengine.hpp
  2. Scrambled Sobol points. Gray-code Sobol points from Joe and Kuo’s direction numbers, and Owen’s scrambling by hashed tree nodes.

    def sobol_points(n: int, dim: int) -> np.ndarray:
        """The first n Sobol points as 32-bit integers, shape (n, dim), in Gray-code order (point 0 is 0)."""
        V = sobol_directions(dim)
        i = np.arange(n, dtype=np.uint64)
        g = i ^ (i >> np.uint64(1))
        X = np.zeros((n, dim), dtype=np.uint64)
        for b in range(max(1, int(n - 1).bit_length())):
            on = ((g >> np.uint64(b)) & np.uint64(1)).astype(bool)
            X[on] ^= V[:, b]
        return X
    
    
    def _mix64(z):
        z = (z ^ (z >> np.uint64(30))) * np.uint64(0xBF58476D1CE4E5B9)
        z = (z ^ (z >> np.uint64(27))) * np.uint64(0x94D049BB133111EB)
        return z ^ (z >> np.uint64(31))
    
    
    def owen_scramble(X: np.ndarray, seed: int) -> np.ndarray:
        """Nested uniform scrambling: digit l of coordinate d is flipped by a random bit attached to the node
        (d, l, first l digits) of the binary tree, drawn by hashing. Returns uniforms (y + 1/2) 2^-32."""
        Y = X.copy()
        for d in range(X.shape[1]):
            x = X[:, d]
            for lev in range(32):
                prefix = x >> np.uint64(32 - lev) if lev else np.zeros_like(x)
                node = np.uint64(d << 40) ^ np.uint64(lev << 32) ^ prefix
                bit = _mix64(np.uint64(seed & MASK) ^ _mix64(node)) >> np.uint64(63)
                Y[:, d] ^= bit << np.uint64(31 - lev)
        return (Y.astype(float) + 0.5) * 2.0**-32
    Listing 26.2. Sobol points and nested uniform scrambling (Python). code/firm/mcengine/firm_mcengine.py
  3. Estimators. Run table() in qm_mc.py: plain, antithetic, control variate, and scrambled Sobol with and without the bridge (32 scrambles of 2142^{14} points); then error_vs_cost().
  4. Multilevel. Run mlmc_study(); the driver is below.

    def mlmc(sampler, eps: float, L0: int = 2, N0: int = 10_000, alpha: float = 1.0, max_level: int = 12) -> dict:
        """Giles's multilevel Monte Carlo. sampler(l, n) returns n samples of Y_l = P_l - P_{l-1} (P_0 at l = 0)
        and the cost of one sample; the sample sizes minimise cost for variance eps^2/2, and levels are added
        until the estimated bias |E Y_L| / (2^alpha - 1) is below eps / sqrt(2)."""
        L = L0
        s1, s2, N, C = [0.0] * (L + 1), [0.0] * (L + 1), [0] * (L + 1), [0.0] * (L + 1)
        dN = [N0] * (L + 1)
        while True:
            for lev in range(L + 1):
                if dN[lev] > 0:
                    y, c = sampler(lev, dN[lev])
                    s1[lev] += float(y.sum())
                    s2[lev] += float((y * y).sum())
                    N[lev] += dN[lev]
                    C[lev] = c
            m = [s1[k] / N[k] for k in range(L + 1)]
            V = [max(s2[k] / N[k] - m[k] ** 2, 1e-300) for k in range(L + 1)]
            tot = sum(math.sqrt(V[k] * C[k]) for k in range(L + 1))
            Nopt = [math.ceil(2 / eps**2 * math.sqrt(V[k] / C[k]) * tot) for k in range(L + 1)]
            dN = [max(0, Nopt[k] - N[k]) for k in range(L + 1)]
            if any(dN):
                continue
            bias = max(abs(m[L]), abs(m[L - 1]) / 2**alpha) / (2**alpha - 1)
            if bias < eps / math.sqrt(2) or L == max_level:
                return {"est": sum(m), "N": N, "V": V, "mean": m, "C": C, "L": L,
                        "cost": sum(N[k] * C[k] for k in range(L + 1))}
            L += 1
            s1.append(0.0), s2.append(0.0), N.append(0), C.append(0.0)
            dN = [0] * L + [N0]
    Listing 26.3. Giles’s multilevel Monte Carlo driver (Python). code/firm/mcengine/firm_mcengine.py

What to change next. Put the strike at 130 and watch the control variate’s factor fall with the correlation; replace the bridge by a principal-component construction; price a barrier with the bridge crossing probability of chapter 2 inside the multilevel driver.

26.6 Build: the Monte Carlo engine, stage three

Purpose. Make each path worth more and every path reproducible: the generators, point sets and estimators that the firm’s pricing and risk batches call.

Interface. philox4x64, philox_uniforms(n, dim, seed, stream, first_path); sobol_points, owen_scramble; norm_ppf; bridge_from_normals; asian_payoffs, geometric_asian_price, control_variate; mlmc(sampler, eps). C++20 and Rust twins of philox4x64, sobol_point (eight dimensions) and owen_scramble.

Rules. Counters, not sequential state, identify paths; every estimate is reported with its standard error (from replicates for randomised quasi-Monte Carlo, never from within one point set); unscrambled Sobol points are never used for error bars; direction numbers carry their licence.

Acceptance tests. code/firm/mcengine/{tests,cpp,rust}: Philox against NumPy’s; splitting paths reproduces them; Joe and Kuo’s published first points; identical scrambled integers in the three languages; the net property after scrambling; Φ−1\Phi^{-1} against the standard library to 10−810^{-8}; bridge covariance; the geometric closed form against simulation and against Black–Scholes for one fixing; the multilevel driver on a sampler with a known answer.

Stretch. Joe and Kuo’s full 21 201 dimensions; a principal-component path construction; conditional Monte Carlo for barriers; adjoint Greeks along the paths (chapter 28).

Sources and further reading

  • N. Metropolis and S. Ulam, “The Monte Carlo method”, Journal of the American Statistical Association 44, 1949; P. P. Boyle, “Options: a Monte Carlo approach”, Journal of Financial Economics 4, 1977.
  • P. Glasserman, Monte Carlo Methods in Financial Engineering, Springer, 2003.
  • J. K. Salmon, M. A. Moraes, R. O. Dror and D. E. Shaw, “Parallel random numbers: as easy as 1, 2, 3”, SC11, 2011; M. Matsumoto and T. Nishimura, ACM TOMACS 8, 1998; M. E. O’Neill, PCG, Harvey Mudd College report HMC-CS-2014-0905, 2014.
  • I. M. Sobol’, USSR Computational Mathematics and Mathematical Physics 7, 1967; S. Joe and F. Y. Kuo, SIAM Journal on Scientific Computing 30, 2008 (direction numbers new-joe-kuo-6.21201); A. B. Owen, “Randomly permuted (t,m,s)(t, m, s)-nets and (t,s)(t, s)-sequences”, 1995; B. Moskowitz and R. E. Caflisch, Mathematical and Computer Modelling 23, 1996.
  • A. G. Z. Kemna and A. C. F. Vorst, Journal of Banking and Finance 14, 1990.
  • M. B. Giles, “Multilevel Monte Carlo path simulation”, Operations Research 56, 2008; P. E. Kloeden and E. Platen, Numerical Solution of Stochastic Differential Equations, Springer, 1992; G. N. Milstein, Theory of Probability and its Applications 19, 1975.
  • P. J. Acklam, “An algorithm for computing the inverse normal cumulative distribution function” (web note, 2004).

26.7 Exercises

Exercise 26.1 ★

A batch has standard error 80 000 dollars with 100 000 paths. How many paths reach 20 000, and what variance-reduction factor does the same at 100 000 paths?

Solution

Solution of Exercise 26.1.

Error scales as n−1/2n^{-1/2}: a factor of four needs 16×100 000=1.616 \times 100\,000 = 1.6 million paths, or a variance-reduction factor of 16 at 100 000 paths.

Exercise 26.2 ★

A control variate has correlation 0.9 with the payoff. What is the variance factor? And with 0.99?

Solution

Solution of Exercise 26.2.

1/(1−ρ2)1/(1 - \rho^2): 5.3 at ρ=0.9\rho = 0.9 and 50.3 at ρ=0.99\rho = 0.99. High correlations are needed for large factors.

Exercise 26.3 ★

Why do antithetic variates help a monotone payoff and not an even function of ZZ such as Z2Z^2?

Solution

Solution of Exercise 26.3.

Var⁡(12(f(Z)+f(−Z)))=12Var⁡f(Z)(1+Corr(f(Z),f(−Z)))\Var(\frac12(f(Z) + f(-Z))) = \frac12\Var f(Z)(1 + \mathrm{Corr}(f(Z), f(-Z))) per pair, i.e. per two evaluations; it beats plain sampling when the correlation is negative, which a monotone ff guarantees. For an even function f(Z)=f(−Z)f(Z) = f(-Z), the correlation is 1 and the pair is worth one draw at the cost of two.

Exercise 26.4 ★★

Show that proportional stratification never increases the variance: with strata ss of probability psp_s and conditional variances σs2\sigma_s^2, the stratified variance is 1n∑spsσs2≤σ2/n\frac1n\sum_sp_s\sigma_s^2 \le \sigma^2/n.

Solution

Solution of Exercise 26.4.

By the law of total variance, σ2=∑spsσs2+∑sps(μs−μ)2\sigma^2 = \sum_sp_s\sigma_s^2 + \sum_sp_s(\mu_s - \mu)^2. The stratified estimator ∑spsYˉs\sum_sp_s\bar Y_s with ns=npsn_s = np_s has variance ∑sps2σs2/ns=1n∑spsσs2\sum_sp_s^2\sigma_s^2/n_s = \frac1n\sum_sp_s\sigma_s^2, which drops the nonnegative between-strata term.

Exercise 26.5 ★★

For P(Z>z∗)P(Z > z^*) with ZZ standard normal, compute the second moment of the importance-sampling estimator with the shift θ\theta, and show that it is minimised near θ=z∗\theta = z^* for large z∗z^*.

Solution

Solution of Exercise 26.5.

The estimator is 1{Z>z∗}e−θZ+θ2/2\mathbf 1\{Z > z^*\}e^{-\theta Z + \theta^2/2} with Z∼N(θ,1)Z \sim \mathcal N(\theta, 1); its second moment is

Ef[1{Z>z∗}e−θZ+θ2/2]=eθ2Φˉ(z∗+θ).\E_f\bigl[\mathbf 1\{Z > z^*\}e^{-\theta Z + \theta^2/2}\bigr] = e^{\theta^2}\bar\Phi(z^* + \theta).

The derivative of its logarithm is 2θ−φ(z∗+θ)/Φˉ(z∗+θ)≈2θ−(z∗+θ)2\theta - \varphi(z^* + \theta)/\bar\Phi(z^* + \theta) \approx 2\theta - (z^* + \theta) for large arguments (Mills’s ratio), which vanishes at θ≈z∗\theta \approx z^*. At z∗=3.67z^* = 3.67 the exact minimiser is 3.80, where the simulation’s minimum is.

Exercise 26.6 ★★

Derive the Milstein step for geometric Brownian motion and show that it is the second-order expansion of the exact step Xe(μ−σ2/2)h+σΔWX e^{(\mu - \sigma^2/2)h + \sigma\Delta W} in ΔW\Delta W.

Solution

Solution of Exercise 26.6.

With a(x)=μxa(x) = \mu x and b(x)=σxb(x) = \sigma x, bb′=σ2xbb' = \sigma^2x: Xk+1=Xk(1+μh+σΔW+12σ2(ΔW2−h))X_{k+1} = X_k(1 + \mu h + \sigma\Delta W + \frac12\sigma^2(\Delta W^2 - h)). Expanding the exact step, e(μ−σ2/2)h+σΔW=1+σΔW+(μ−12σ2)h+12σ2ΔW2+O(h3/2)e^{(\mu - \sigma^2/2)h + \sigma\Delta W} = 1 + \sigma\Delta W + (\mu - \frac12\sigma^2)h + \frac12\sigma^2\Delta W^2 + O(h^{3/2}), the same terms.

Exercise 26.7 ★★★

Coding. Compute the variance factor of the control variate at strikes 80, 100 and 130, and explain the trend.

Solution

Solution of Exercise 26.7.

With 2142^{14} paths: correlation 0.99953, 0.99941 and 0.99425, variance factors 1 071, 853 and 87 at strikes 80, 100 and 130. Far out of the money the geometric average (always below the arithmetic one) finishes in the money less often than the arithmetic one, and the two payoffs decouple near the strike: the control is worth less where both are rare.

Exercise 26.8 ★★★

Find the flaw. “We moved the batch to Sobol points, 100 000 per trade, and report the standard error s/ns/\sqrt n from the points as before; it fell by a factor of ten.”

Solution

Solution of Exercise 26.8.

Sobol points are not independent, so s/ns/\sqrt n is not the standard error of their average: it measures the spread of the payoffs, not of the estimate, and says nothing about the error, which may be smaller or, with a poor path construction, larger. The error must come from independent scrambles (replicates), and unscrambled points give no error estimate at all.

26.8 Problem: Sixteen Times Fewer Machines

Problem 26.1

Weekend problem — a factor of four in error, without sixteen times the paths

The representative trade is an arithmetic-average call on 64 fixings (S0=K=100S_0 = K = 100, r=3%r = 3\%, σ=25%\sigma = 25\%, one year), valued with 2142^{14} paths; the batch needs a factor of four in standard error.

Part I — The plain estimator.

  1. What are the plain estimate, its standard error and the reference price?
  2. What variance factor does the target require?
  3. What does the cost-variance product say about comparing estimators?
  4. Why does the counter-based generator make the batch reproducible across machines?
  5. Why is the inverse transform, rather than Box–Muller, used to feed low-discrepancy points?

Part II — Variance reduction.

  1. What factor do antithetic pairs give, and why so little?
  2. What is the control variate, its closed-form value, its correlation and its factor?
  3. What is the optimal coefficient, and what was estimated?
  4. Where does importance sampling help, and by how much on the deep out-of-the-money digital?
  5. Why does too large a shift make it worse?

Part III — Points and paths.

  1. What factor do scrambled Sobol points give with the increments in time order, and with the bridge?
  2. Why does the bridge matter so much?
  3. What do the two together give, and what is the error’s slope in the number of paths?
  4. How is the error of randomised quasi-Monte Carlo estimated?
  5. What do the strong and weak orders measure, and what are their fitted values here?

Part IV — Judgement.

  1. What does multilevel Monte Carlo save on the European call at ϵ=0.005\epsilon = 0.005, and why?
  2. Would the factor of 37 000 hold across the batch?
  3. What must the batch log so that one trade’s paths can be regenerated?
  4. State the named result: the variance-reduction factor of the control variate plus randomised quasi-Monte Carlo on the representative trade, against the 16 required.
  5. In one sentence: where does the work of a Monte Carlo engine go?
Solution

Solution of Problem 26.1.

1. 6.495 with standard error 0.077 from 2142^{14} paths; reference 6.4788 (control variate plus scrambled Sobol, 32 replicates of 2142^{14}, standard error 0.00007). 2. 16. 3. At equal accuracy the cost is cσ2/ϵ2c\sigma^2/\epsilon^2, so estimators are compared by variance times cost per draw; all the factors here are at equal payoff evaluations. 4. Each path’s numbers are a function of (seed, trade, path, block), not of a sequential state, so any split of the paths reproduces them. 5. It maps one uniform coordinate to one normal monotonically, so the structure of the point set survives; Box–Muller mixes two coordinates through a cosine. 6. 1.8: the two payoffs of a pair have correlation −0.43-0.43; the payoff is monotone in the path but convex, and its positive part discards the down paths. 7. The geometric-average call, 6.1793 in closed form; correlation 0.99941; factor 853. 8. β∗=Cov⁡(Y,C)/Var⁡C\beta^* = \Cov(Y, C)/\Var C; estimated from the same paths as 1.04 (the bias this introduces is of order 1/n1/n). 9. Where the payoff lives in a small region of the driver’s space: at θ=3.8\theta = 3.8 the relative standard error falls from 20% to 0.64%, a factor of about 1 000 in variance. 10. The likelihood ratio e−θZ+θ2/2e^{-\theta Z + \theta^2/2} becomes very variable: the second moment eθ2Φˉ(z∗+θ)e^{\theta^2}\bar\Phi(z^* + \theta) grows again beyond the optimum. 11. About 34 with the increments in time order and about 2 500 with the bridge. 12. Low-discrepancy points are most uniform in their first coordinates; the bridge puts WTW_T and the coarse shape of the path there, the directions that carry most of the payoff’s variance. 13. About 37 000 (standard error 190 times smaller); fitted slopes between −0.7-0.7 and −0.8-0.8 against −0.5-0.5 for Monte Carlo. 14. From the spread of independent scrambles: RR replicates give RR independent unbiased estimates, whose sample standard deviation divided by R\sqrt R is the standard error. 15. Strong: the pathwise error, slopes 0.49 (Euler) and 0.89 (Milstein); weak: the error in law, slope 1.00 for the mean. 16. Cost 3.2×1073.2 \times 10^7 time steps against 3.0×1093.0 \times 10^9, a factor of 94: most samples are drawn on coarse, cheap levels, and the fine corrections have small variance because Milstein’s strong order 1 makes VlV_l fall by four per level. 17. No: it relies on a smooth payoff with a closed-form control and a low effective dimension. Barriers, digitals and early exercise break the smoothness, and most trades have no control as good; each trade class must be measured. 18. Seed, trade and path counters, generator and version, scrambling seeds, the path construction, and the point-set size. 19. Named result: sixteen times fewer machines: on the representative trade, the control variate alone reduces the variance by 853 and with scrambled Sobol points and the Brownian bridge by about 37 000, against the 16 required; the target is met at today’s number of paths, with the generation overhead to be measured in the production engine. 20. Into the constant in front of n−1/2n^{-1/2}: what each path is worth, and what it costs.

26.9 Interview questions

Interview question 26.1 ★ researcher, developer

How does the Monte Carlo error scale with the number of paths and with the dimension?

Solution

Solution of Interview question 26.1.

The standard error is σ/n\sigma/\sqrt n whatever the dimension: the dimension enters only through σ\sigma and the cost of a path, which is why Monte Carlo wins in high dimension and loses to grids in one or two.

What the interviewer is looking for: n−1/2n^{-1/2}, dimension-free, the constant.

Interview question 26.2 ★★ researcher

Name three variance-reduction techniques and when each works.

Solution

Solution of Interview question 26.2.

Antithetic variates (monotone payoffs, cheap, small gains); control variates (a correlated quantity with known mean: the geometric Asian, the underlying, a Black–Scholes price); importance sampling (rare events: shift the drift towards the region that matters); stratification or quasi-Monte Carlo (smooth payoffs in a few important directions).

What the interviewer is looking for: When each works, not just names.

Interview question 26.3 ★★ developer

How do you make a distributed Monte Carlo batch reproducible regardless of the number of machines?

Solution

Solution of Interview question 26.3.

Use a counter-based generator (Philox, Threefry) keyed by the seed, with the counter built from trade, path and block indices, so that numbers are a function of their coordinates, not of the order of generation; reduce partial sums in a fixed order.

What the interviewer is looking for: Counters over sequential streams, and a fixed reduction order.

Interview question 26.4 ★★ researcher

Why might quasi-Monte Carlo do badly on a 250-step path, and what fixes it?

Solution

Solution of Interview question 26.4.

Its uniformity is good only in the first coordinates, and in time order the path’s variance is spread evenly over 250 of them. Fix it with a Brownian bridge or principal-component construction that puts the important directions first, and scramble to get error estimates.

What the interviewer is looking for: Effective dimension and path construction.

Interview question 26.5 ★★ researcher, risk

How would you estimate the probability of a loss beyond a very high threshold by simulation?

Solution

Solution of Interview question 26.5.

Importance sampling: tilt the distribution (shift the mean of the drivers, or exponentially tilt the loss) so that the loss beyond the threshold is common, and weight by the likelihood ratio; choose the tilt near the most likely point of the rare region; check the weights’ spread. Splitting or conditional Monte Carlo are alternatives.

What the interviewer is looking for: A change of measure with the likelihood ratio, and a sensible choice of tilt.

Interview question 26.6 ★★★ researcher

Explain multilevel Monte Carlo and why the strong order of the scheme matters for it.

Solution

Solution of Interview question 26.6.

Write the finest-level expectation as a telescoping sum of corrections between successive step sizes, simulate the fine and coarse paths of each correction from the same Brownian path, and allocate samples in proportion to Vl/Cl\sqrt{V_l/C_l}. The correction’s variance VlV_l is governed by the strong error, so a higher strong order makes the fine levels need very few samples; with VlV_l falling faster than the cost rises, the total cost is O(ϵ−2)O(\epsilon^{-2}), as for an unbiased estimator.

What the interviewer is looking for: Telescoping sum, coupling, and the variance of corrections from the strong order.

Terms defined in this chapter

See all 2333 terms in the glossary