5D Library › Macro-Liquidity Regime Switching, Extreme Tail Dependence and Barbell Asset Allocation · 中文

Chapter 2 Extreme Value Theory: From Tail Index to Expected Shortfall

Why the normal distribution cannot estimate tails

Risk management is usually concerned not with the average day but with the day that comes once in a hundred or a thousand. The normal distribution is a poor tool for this: its tail decays like e−x2/2e^{-x^2/2}, far faster than the empirical distribution of almost any financial return. Books 20 and 38 discussed fat tails and volatility clustering in returns; this chapter’s question is narrower. If only the tail matters, can it be estimated from the tail data alone, with the help of a limiting distribution that has a theoretical basis? Extreme value theory answers yes, under fairly broad conditions, but the word “limit” must be taken seriously.

Block maxima and the generalized extreme value distribution

Divide the data into blocks of length nn (for instance, years) and take the largest loss MnM_n in each. The Fisher–Tippett–Gnedenko theorem says that if there are constants an>0a_n > 0 and bnb_n such that (Mn−bn)/an(M_n – b_n)/a_n converges in distribution to a non-degenerate limit, that limit must be a generalized extreme value (GEV) distribution

Gξ(x)=exp⁡{−(1+ξx)−1/ξ},1+ξx>0,G_\xi(x) = \exp\!\left\{-(1 + \xi x)^{-1/\xi}\right\}, \qquad 1 + \xi x > 0,

read as exp⁡(−e−x)\exp(-e^{-x}) when ξ=0\xi = 0. The shape parameter ξ\xi sets the type of tail: ξ>0\xi > 0 is the Fréchet type (power-law fat tails, as for the Student t), ξ=0\xi = 0 the Gumbel type (exponential-type tails, as for the normal) and ξ<0\xi < 0 the bounded Weibull type (Embrechts et al. 1997; Coles 2001). The weakness of block maxima is waste: each block contributes only one number.

Threshold exceedances and the Pickands–Balkema–de Haan theorem

The alternative is to take a high threshold uu and study the part above it, Y=X−uY = X – u.

Evidence

The Pickands–Balkema–de Haan theorem (Pickands 1975; Balkema and Haan 1974): a distribution FF lies in the maximum domain of attraction of some GξG_\xi if and only if there is a positive function β(u)\beta(u) such that the excess distribution Fu(y)=P(X−u≤y∣X>u)F_u(y) = P(X – u \le y \mid X > u) converges uniformly, as uu approaches the right end of FF, to the generalized Pareto distribution (GPD)

Hξ,β(y)=1−(1+ξyβ)−1/ξ,y≥0.H_{\xi,\beta}(y) = 1 – \left(1 + \frac{\xi y}{\beta}\right)^{-1/\xi}, \qquad y \ge 0.

The shape parameter ξ\xi is the same in both approaches. Davison and Smith developed statistical models for threshold exceedances systematically on this basis (Davison and Smith 1990).

Two conditions of the theorem are often left out. First, FF must lie in the domain of attraction of an extreme value law; most continuous distributions do, but not all. Second, it is a limit result: the higher the threshold, the better the approximation and the fewer the data. In finite samples, choosing the threshold is a trade-off between bias and variance.

The Hill estimator is the most widely used estimate when ξ>0\xi > 0 (Hill 1975): order the losses from largest to smallest, X(1)≥X(2)≥⋯X_{(1)} \ge X_{(2)} \ge \cdots, and take the top kk:

ξ̂k=1k∑i=1kln⁡X(i)X(k+1),α̂k=1/ξ̂k.\hat\xi_k = \frac{1}{k}\sum_{i=1}^{k} \ln\frac{X_{(i)}}{X_{(k+1)}}, \qquad \hat\alpha_k = 1/\hat\xi_k .

The mean-excess function e(u)=E[X−u∣X>u]e(u) = E[X – u \mid X > u] is another diagnostic: if the excesses follow a GPD with ξ<1\xi < 1, then e(u)=(β+ξu)/(1−ξ)e(u) = (\beta + \xi u)/(1 – \xi) is linear in uu with slope ξ/(1−ξ)\xi/(1-\xi), whereas for the normal distribution e(u)e(u) falls roughly like 1/u1/u. The author’s framework proposes choosing the threshold from the mean-excess plot, where the plot starts to look linear.

Calculation

# Reading a tail: the Hill estimator of the tail index, the mean-excess function, and a
# GEV fit to block maxima by probability-weighted moments (Hosking, Wallis & Wood 1985).
# SIMULATED losses: Student t with 3 d.f. (true tail index alpha = 3, xi = 1/3) and the
# normal (xi = 0: no power tail at all). 5,000 observations each.
import math, random, statistics

def sample(kind, n, rng):
    if kind == "t3":
        return [rng.gauss(0, 1) / math.sqrt(rng.gammavariate(1.5, 2) / 3)
                for _ in range(n)]
    return [rng.gauss(0, 1) for _ in range(n)]

def hill(x, k):
    s = sorted(x, reverse=True)
    h = sum(math.log(s[i] / s[k]) for i in range(k)) / k
    return 1 / h                                   # estimated tail index alpha = 1/xi

def mean_excess(x, u):
    e = [v - u for v in x if v > u]
    return sum(e) / len(e), len(e)

def gev_pwm(m):
    m = sorted(m); n = len(m)
    b0 = sum(m) / n
    b1 = sum(i * m[i] for i in range(n)) / (n * (n - 1))
    b2 = sum(i * (i - 1) * m[i] for i in range(n)) / (n * (n - 1) * (n - 2))
    c = (2 * b1 - b0) / (3 * b2 - b0) - math.log(2) / math.log(3)
    k = 7.8590 * c + 2.9554 * c * c                # Hosking's k = -xi
    return -k

if __name__ == "__main__":
    rng = random.Random(1975)
    data = {kind: sample(kind, 5000, rng) for kind in ("t3", "normal")}
    print("Hill estimate of the tail index alpha (top k of 5,000 losses)")
    ks = (25, 50, 100, 200, 400, 800, 1600)
    print("   k     " + "".join(f"{k:7d}" for k in ks))
    for kind, x in data.items():
        print(f"   {kind:7s}" + "".join(f"{hill(x, k):7.2f}" for k in ks)
              + ("   (true 3)" if kind == "t3" else "   (true: infinite)"))
    print("mean excess e(u) = E[X - u | X > u] at empirical quantiles of the losses")
    qs = (0.80, 0.90, 0.95, 0.975, 0.99)
    print("   quantile" + "".join(f"{q:9.3f}" for q in qs))
    for kind, x in data.items():
        s = sorted(x); row = ""
        for q in qs:
            u = s[int(q * len(s))]; e, n = mean_excess(x, u)
            row += f"  {u:4.2f}:{e:4.2f}"
        print(f"   {kind:7s} " + row + "   (u:e)")
    print("   a GPD with xi = 1/3 has e(u) linear with slope xi/(1 - xi) = 0.5;")
    print("   the normal's e(u) falls like 1/u")
    print("GEV shape xi from maxima of blocks (probability-weighted moments)")
    for kind in ("t3", "normal"):
        est = []
        for _ in range(200):
            x = sample(kind, 5000, rng)
            est.append(gev_pwm([max(x[i:i + 100]) for i in range(0, 5000, 100)]))
        q = statistics.quantiles(est, n=20)
        print(f"   {kind:7s}: 50 blocks of 100, 200 samples: median xi {q[9]:+.3f},"
              f" 5-95 % {q[0]:+.3f} to {q[-1]:+.3f}")
# Hill estimate of the tail index alpha (top k of 5,000 losses)
#    k          25     50    100    200    400    800   1600
#    t3        3.40   3.22   2.84   2.42   2.27   1.82   1.14   (true 3)
#    normal   10.06   9.17   6.60   5.18   3.74   2.60   1.29   (true: infinite)
# mean excess e(u) = E[X - u | X > u] at empirical quantiles of the losses
#    quantile    0.800    0.900    0.950    0.975    0.990
#    t3        0.97:1.08  1.62:1.23  2.32:1.47  3.24:1.66  4.66:1.95   (u:e)
#    normal    0.86:0.54  1.27:0.49  1.66:0.40  1.95:0.39  2.36:0.27   (u:e)
#    a GPD with xi = 1/3 has e(u) linear with slope xi/(1 - xi) = 0.5;
#    the normal's e(u) falls like 1/u
# GEV shape xi from maxima of blocks (probability-weighted moments)
#    t3     : 50 blocks of 100, 200 samples: median xi +0.290, 5-95 % +0.066 to +0.572
#    normal : 50 blocks of 100, 200 samples: median xi -0.109, 5-95 % -0.277 to +0.071

For the Student t with 3 degrees of freedom (true α=3\alpha = 3), the Hill estimate is 3.40, 3.22 and 2.84 for k=25k = 25 to 100, then falls steadily to 1.14 at k=1,600k = 1{,}600: take too many data and the centre of the distribution is treated as tail. For normal data the Hill estimate falls from 10.06 to 1.29, and its value of 3.74 at k=400k = 400 looks just like a power-law tail with index about 3.7, not far from the t distribution’s estimates at small kk (3.22 to 3.40) or its true value of 3, although the normal has no power-law tail at all. A Hill estimate at a single kk can therefore mistake a thin tail for a fat one, and cannot by itself give the true tail index; one needs to see whether the whole “Hill plot” has a stable plateau, together with the mean-excess plot. Figure 2 shows both: the t distribution’s e(u)e(u) rises from 1.08 to 1.95, roughly linearly (theoretical slope 0.5); the normal’s falls from 0.54 to 0.27. Estimating the GEV shape from 50 block maxima (by probability-weighted moments (Hosking et al. 1985)) gives a median of 0.290 with a 90 % interval of 0.066 to 0.572 for the t distribution, and −0.109 with an interval of −0.277 to 0.071 for the normal: the direction is right, but 50 data points leave great uncertainty.

Left: mean-excess function e(u); right: Hill estimate against the number k of tail observations used. Solid: Student t with 3 degrees of freedom; dashed: normal; 5,000 simulated losses each.

From the tail distribution to VaR and ES

At level pp, value at risk VaRp\mathrm{VaR}_p is the pp-quantile of the loss distribution and expected shortfall ESp=E[X∣X>VaRp]\mathrm{ES}_p = E[X \mid X > \mathrm{VaR}_p] is the average of the losses beyond it. After fitting a GPD to the kk exceedances of the threshold (sample size nn),

VaRp=u+βξ[(nk(1−p))−ξ−1],ESp=VaRp1−ξ+β−ξu1−ξ(ξ<1).\mathrm{VaR}_p = u + \frac{\beta}{\xi}\left[\left(\frac{n}{k}(1-p)\right)^{-\xi} – 1\right], \qquad \mathrm{ES}_p = \frac{\mathrm{VaR}_p}{1 – \xi} + \frac{\beta – \xi u}{1 – \xi} \quad (\xi < 1).

Evidence

Artzner and co-authors proposed four axioms for “coherent risk measures”; VaR fails one of them, subadditivity: the VaR of two positions combined can exceed the sum of their separate VaRs (Artzner et al. 1999). Acerbi and Tasche proved that ES is a coherent risk measure (Acerbi and Tasche 2002). But Gneiting proved that ES is not “elicitable” (no scoring function makes reporting the true ES optimal), which makes backtesting ES harder than backtesting VaR (Gneiting 2011); Fissler and Ziegel proved that VaR and ES are jointly elicitable (Fissler and Ziegel 2016). The Basel Committee’s 2016 market-risk framework replaced 99 % VaR with 97.5 % ES as the main measure for internal models (Basel Committee on Banking Supervision 2016).

The program below tests how these formulas behave in finite samples: true losses are Student t with 4 degrees of freedom (standard deviation 1, true ξ=0.25\xi = 0.25), each sample has 2,500 days, and the exercise is repeated 200 times.

Calculation

# Peaks over threshold: fit a generalized Pareto distribution (GPD) to the losses above
# a high threshold by maximum likelihood and turn it into VaR and expected shortfall (ES).
# SIMULATED daily losses (in %): Student t with 4 d.f. scaled to sd 1, 2,500 days (about
# ten years); 200 independent samples. Compared with the normal fit and with historical
# simulation (the empirical quantile), against the true values of the t distribution.
import math, random, statistics

S = 1 / math.sqrt(2)                                  # t4 has variance 2

def t4_cdf(t):
    u = t / math.sqrt(t * t + 4)
    return 0.5 + 0.75 * (u - u ** 3 / 3)

def t4_q(p):
    lo, hi = 0.0, 100.0
    for _ in range(100):
        mid = (lo + hi) / 2
        lo, hi = (mid, hi) if t4_cdf(mid) < p else (lo, mid)
    return lo

def true_var_es(p):
    q = t4_q(p); f = 0.375 * (1 + q * q / 4) ** -2.5
    return S * q, S * f / (1 - p) * (4 + q * q) / 3

def search(f, x, step, tol=1e-4):               # compass (pattern) search minimizer
    fx, step = f(x), list(step)
    while max(step) > tol:
        moved = False
        for j in range(len(x)):
            for sg in (1, -1):
                y = x[:]; y[j] += sg * step[j]; fy = f(y)
                if fy < fx:
                    x, fx, moved = y, fy, True; break
        if not moved:
            step = [v / 2 for v in step]
    return x

def gpd_fit(y):
    def nll(p):
        xi, s = p[0], math.exp(p[1]); tot = len(y) * math.log(s)
        for v in y:
            z = 1 + xi * v / s
            if z <= 0:
                return 1e10
            tot += (1 + 1 / xi) * math.log(z) if abs(xi) > 1e-9 else v / s
        return tot
    xi, ls = search(nll, [0.1, math.log(statistics.mean(y))], [0.1, 0.1])
    return xi, math.exp(ls)

def pot_var_es(x, k, ps):
    s = sorted(x, reverse=True); u = s[k]
    xi, sig = gpd_fit([v - u for v in s[:k]]); out = []
    for p in ps:
        var = u + sig / xi * ((len(x) / k * (1 - p)) ** -xi - 1)
        out.append((var, (var + sig - xi * u) / (1 - xi)))
    return out, xi

def normal_var_es(x, p):
    m, sd = statistics.mean(x), statistics.stdev(x)
    z = statistics.NormalDist().inv_cdf(p)
    return m + sd * z, m + sd * math.exp(-z * z / 2) / math.sqrt(2 * math.pi) / (1 - p)

if __name__ == "__main__":
    rng = random.Random(2000); res = {}
    for _ in range(200):
        x = [S * rng.gauss(0, 1) / math.sqrt(rng.gammavariate(2, 2) / 4)
             for _ in range(2500)]
        s = sorted(x)
        for k in (50, 125, 250):
            out, xi = pot_var_es(x, k, (0.99, 0.999))
            res.setdefault(("xi k=%d" % k, 0.99), []).append((xi, xi))
            for p, ve in zip((0.99, 0.999), out):
                res.setdefault(("GPD k=%d" % k, p), []).append(ve)
        for p in (0.99, 0.999):
            res.setdefault(("normal", p), []).append(normal_var_es(x, p))
            j = int(p * len(s))
            res.setdefault(("historical", p), []).append((s[j], statistics.mean(s[j:])))
    for p in (0.99, 0.999):
        tv, te = true_var_es(p)
        print(f"level {p}: true VaR {tv:.2f}, true ES {te:.2f}"
              f"   (200 samples of 2,500 days)")
        print("   method          VaR median (5-95 %)        ES median (5-95 %)")
        for m in ("normal", "historical", "GPD k=50", "GPD k=125", "GPD k=250"):
            v = statistics.quantiles([a for a, b in res[(m, p)]], n=20)
            e = statistics.quantiles([b for a, b in res[(m, p)]], n=20)
            print(f"   {m:12s}  {v[9]:5.2f} ({v[0]:4.2f}-{v[-1]:4.2f})"
                  f"         {e[9]:5.2f} ({e[0]:4.2f}-{e[-1]:4.2f})")
    for k in (50, 125, 250):
        q = statistics.quantiles([a for a, b in res[("xi k=%d" % k, 0.99)]], n=20)
        print(f"GPD shape xi with k = {k:3d} exceedances: median {q[9]:+.2f}"
              f" (5-95 % {q[0]:+.2f} to {q[-1]:+.2f}); true 0.25")
# level 0.99: true VaR 2.65, true ES 3.69   (200 samples of 2,500 days)
#    method          VaR median (5-95 %)        ES median (5-95 %)
#    normal         2.32 (2.19-2.48)          2.66 (2.52-2.84)
#    historical     2.68 (2.43-2.96)          3.65 (3.18-4.30)
#    GPD k=50       2.66 (2.44-2.94)          3.67 (3.18-4.29)
#    GPD k=125      2.66 (2.45-2.90)          3.65 (3.18-4.28)
#    GPD k=250      2.68 (2.46-2.91)          3.65 (3.19-4.25)
# level 0.999: true VaR 5.07, true ES 6.85   (200 samples of 2,500 days)
#    method          VaR median (5-95 %)        ES median (5-95 %)
#    normal         3.08 (2.92-3.29)          3.35 (3.18-3.58)
#    historical     4.94 (3.94-6.48)          5.87 (4.56-8.81)
#    GPD k=50       4.99 (4.05-6.13)          6.35 (4.67-9.99)
#    GPD k=125      5.00 (4.11-6.25)          6.49 (4.83-9.64)
#    GPD k=250      4.96 (4.11-6.06)          6.36 (4.75-8.68)
# GPD shape xi with k =  50 exceedances: median +0.13 (5-95 % -0.16 to +0.44); true 0.25
# GPD shape xi with k = 125 exceedances: median +0.16 (5-95 % +0.01 to +0.35); true 0.25
# GPD shape xi with k = 250 exceedances: median +0.15 (5-95 % +0.02 to +0.29); true 0.25

At the 99 % level the normal fit gives a median VaR of 2.32 against a true 2.65, and a normal ES of 2.66 against a true 3.69, an underestimate of about 28 %. Historical simulation and the GPD are both essentially unbiased at this level. At 99.9 % the differences become stark: the normal VaR is only 3.08 (true 5.07); historical simulation has a close median, 4.94, but a 90 % interval as wide as 3.94 to 6.48, because it rests on the two or three largest values in the sample; the GPD (k=125k = 125) gives a median VaR of 5.00 with an interval of 4.11 to 6.25. The GPD’s median ES of 6.49 is a little below the true 6.85, and the last three lines explain why: the median estimate of the shape parameter is only 0.13 to 0.16 against a true 0.25. The excesses of a Student t follow a GPD exactly only as the threshold goes to infinity, and at finite thresholds there is “second-order bias”; reducing kk lowers the bias but raises the variance quickly (at k=50k = 50 the interval runs from −0.16 to 0.44). Extreme value methods therefore give tail estimates that are much better than the normal’s but still carry systematic error and large sampling error.

Conditional EVT and backtesting

The tail of financial returns does not stand still: on high-volatility days the same quantile corresponds to a larger loss. McNeil and Frey proposed a two-step method: first estimate a GARCH model by quasi-maximum likelihood to obtain each day’s conditional volatility σt\sigma_t and standardised residuals zt=xt/σtz_t = x_t / \sigma_t; then fit a GPD to the tail of the residuals to obtain their quantile qzq_z and expected shortfall eze_z; tomorrow’s VaR and ES are σt+1qz\sigma_{t+1} q_z and σt+1ez\sigma_{t+1} e_z (McNeil and Frey 2000). GARCH itself was discussed in Book 20; here it serves only as a volatility filter.

Evidence

McNeil and Frey estimated on a rolling window of 1,000 days, fitted the GPD to the 100 largest residuals, and backtested five daily return series: the S&P 500, the DAX, BMW shares, the dollar–sterling exchange rate and gold. At the 99 % level the conditional normal method was rejected for four of the five series (for the S&P 500, 104 violations against 74 expected), while conditional EVT was never rejected (73 violations); across 15 tests at the 95 %, 99 % and 99.5 % levels, the conditional normal method failed 11 times and conditional EVT never (McNeil and Frey 2000).

The backtests use the two tests named in the author’s framework. Kupiec’s test (unconditional coverage) compares the number of violations xx with the expected npnp:

LRuc=−2ln⁡(1−p)n−xpx(1−π̂)n−xπ̂x∼χ12,π̂=x/n\mathrm{LR}_{uc} = -2\ln\frac{(1-p)^{n-x}p^{x}}{(1-\hat\pi)^{n-x}\hat\pi^{x}} \sim \chi^2_1, \qquad \hat\pi = x/n

(Kupiec 1995). Christoffersen’s test further checks whether violations come in clusters: it treats violation or not on each day as a two-state Markov chain and compares the probability of a violation after a violation with that after a quiet day (the independence test LRind\mathrm{LR}_{ind}), combining this with the coverage test into a conditional-coverage test LRcc=LRuc+LRind∼χ22\mathrm{LR}_{cc} = \mathrm{LR}_{uc} + \mathrm{LR}_{ind} \sim \chi^2_2 (Christoffersen 1998).

The program below simulates four GARCH(1,1) series with Student-t shocks (5 degrees of freedom); each series is re-estimated every 250 days on a rolling 1,000-day window, giving 8,000 one-day forecasts with which four methods are compared.

Calculation

# Conditional EVT in the manner of McNeil & Frey (2000): GARCH(1,1) by normal quasi-ML
# on the last 1,000 days, then a GPD on the 100 largest standardized losses; one-day 99 %
# VaR and ES. Backtest with Kupiec's unconditional-coverage test and Christoffersen's
# independence and conditional-coverage tests. SIMULATED: 4 series from a GARCH(1,1) with
# Student-t(5) shocks (omega 0.02, alpha 0.08, beta 0.90); 2,000 forecast days each.
import math, random, statistics

def simulate(n, rng, om=0.02, al=0.08, be=0.90, df=5):
    h, x = om / (1 - al - be), []
    for _ in range(n):
        w = math.sqrt(rng.gammavariate(df / 2, 2) / df) * math.sqrt(df / (df - 2))
        e = rng.gauss(0, 1) / w
        x.append(math.sqrt(h) * e); h = om + al * x[-1] ** 2 + be * h
    return x

def search(f, x, step, tol=1e-4):               # compass (pattern) search minimizer
    fx, step = f(x), list(step)
    while max(step) > tol:
        moved = False
        for j in range(len(x)):
            for sg in (1, -1):
                y = x[:]; y[j] += sg * step[j]; fy = f(y)
                if fy < fx:
                    x, fx, moved = y, fy, True; break
        if not moved:
            step = [v / 2 for v in step]
    return x

def garch_path(x, p):
    om, al, be = p; h = statistics.pvariance(x); hs = []
    for v in x:
        hs.append(h); h = om + al * v * v + be * h
    return hs, h                         # in-sample variances, next-day forecast

def garch_fit(x, start):
    def nll(p):
        if p[0] <= 0 or p[1] < 0 or p[2] < 0 or p[1] + p[2] >= 0.999:
            return 1e10
        hs, _ = garch_path(x, p)
        return sum(math.log(h) + v * v / h for v, h in zip(x, hs)) / 2
    return search(nll, start, [0.01, 0.02, 0.02])

def gpd_fit(y):
    def nll(p):
        xi, s = p[0], math.exp(p[1]); tot = len(y) * math.log(s)
        for v in y:
            z = 1 + xi * v / s
            if z <= 0:
                return 1e10
            tot += (1 + 1 / xi) * math.log(z) if abs(xi) > 1e-9 else v / s
        return tot
    xi, ls = search(nll, [0.1, math.log(statistics.mean(y))], [0.1, 0.1])
    return xi, math.exp(ls)

Z99 = statistics.NormalDist().inv_cdf(0.99)
PHI = math.exp(-Z99 ** 2 / 2) / math.sqrt(2 * math.pi) / 0.01

def forecasts(x, win=1000, refit=250, k=100, p=0.99):
    out, par = [], [0.05, 0.05, 0.90]
    for t in range(win, len(x)):
        w = x[t - win:t]
        if (t - win) % refit == 0:
            par = garch_fit(w, par); hs, h1 = garch_path(w, par)
            z = sorted((-v / math.sqrt(h) for v, h in zip(w, hs)), reverse=True)
            u = z[k]; xi, sg = gpd_fit([v - u for v in z[:k]])
            qz = u + sg / xi * ((win / k * (1 - p)) ** -xi - 1)
            ez = (qz + sg - xi * u) / (1 - xi)
        s1 = math.sqrt(h1); m, sd = statistics.mean(w), statistics.stdev(w)
        hsq = sorted(-v for v in w)
        out.append(dict(loss=-x[t],
                        normal=(-m + sd * Z99, -m + sd * PHI),
                        hist=(hsq[int(p * win)], statistics.mean(hsq[int(p * win):])),
                        garch_n=(s1 * Z99, s1 * PHI), garch_evt=(s1 * qz, s1 * ez)))
        h1 = par[0] + par[1] * x[t] ** 2 + par[2] * h1
    return out

def chi2_sf(x, df):
    return math.erfc(math.sqrt(x / 2)) if df == 1 else math.exp(-x / 2)

def tests(hits, p=0.01):
    n, k = len(hits), sum(hits); pi = k / n
    ll = lambda q, a, b: (a * math.log(q) if a else 0) + (b * math.log(1 - q) if b else 0)
    uc = -2 * (ll(p, k, n - k) - ll(pi, k, n - k))
    n00 = n01 = n10 = n11 = 0
    for a, b in zip(hits, hits[1:]):
        n00 += (not a) and (not b); n01 += (not a) and b
        n10 += a and (not b); n11 += a and b
    p01, p11 = n01 / (n00 + n01), (n11 / (n10 + n11) if n10 + n11 else 0)
    p1 = (n01 + n11) / (n00 + n01 + n10 + n11)
    ind = -2 * (ll(p1, n01 + n11, n00 + n10) - ll(p01, n01, n00) - ll(p11, n11, n10))
    return k, chi2_sf(uc, 1), chi2_sf(ind, 1), chi2_sf(uc + ind, 2)

def kupiec_power(n, true, p=0.01):
    tot = 0.0
    for k in range(n + 1):
        pi = k / n
        a = k * math.log(p) + (n - k) * math.log(1 - p)
        b = (k * math.log(pi) if k else 0) + ((n - k) * math.log(1 - pi) if k < n else 0)
        if -2 * (a - b) > 3.841:
            lc = math.lgamma(n + 1) - math.lgamma(k + 1) - math.lgamma(n - k + 1)
            tot += math.exp(lc + k * math.log(true) + (n - k) * math.log(1 - true))
    return tot

if __name__ == "__main__":
    rng = random.Random(2000); allf = []
    for _ in range(4):
        allf += forecasts(simulate(3000, rng))
    print(f"{len(allf)} one-day forecasts (4 series x 2,000 days);"
          f" expected violations at 99 %: {0.01 * len(allf):.0f}")
    print("                                         Christoffersen p    mean loss / ES")
    print("method               violations Kupiec p  indep.  cond.cov.  violation days")
    for m, lab in (("normal", "unconditional normal"), ("hist", "historical simulation"),
                   ("garch_n", "GARCH-normal"), ("garch_evt", "GARCH-EVT")):
        hits = [f["loss"] > f[m][0] for f in allf]
        k, puc, pind, pcc = tests(hits)
        r = statistics.mean(f["loss"] / f[m][1] for f in allf if f["loss"] > f[m][0])
        print(f"{lab:22s} {k:5d}    {puc:6.3f}   {pind:6.3f}   {pcc:6.3f}     {r:5.2f}")
    print("power of Kupiec's test (5 % level) to reject a 99 % VaR whose true rate is")
    for n in (250, 500, 1000, 2500):
        print(f"   {n:5d} days:  1.5 %: {kupiec_power(n, 0.015):.2f}"
              f"    2 %: {kupiec_power(n, 0.02):.2f}"
              f"    (size at 1 %: {kupiec_power(n, 0.01):.3f})")
# 8000 one-day forecasts (4 series x 2,000 days); expected violations at 99 %: 80
#                                          Christoffersen p    mean loss / ES
# method               violations Kupiec p  indep.  cond.cov.  violation days
# unconditional normal     183     0.000    0.000    0.000      1.24
# historical simulation    102     0.018    0.002    0.001      1.08
# GARCH-normal             165     0.000    0.820    0.000      1.14
# GARCH-EVT                 87     0.438    0.956    0.739      1.02
# power of Kupiec's test (5 % level) to reject a 99 % VaR whose true rate is
#      250 days:  1.5 %: 0.11    2 %: 0.24    (size at 1 %: 0.095)
#      500 days:  1.5 %: 0.23    2 %: 0.54    (size at 1 %: 0.071)
#     1000 days:  1.5 %: 0.34    2 %: 0.78    (size at 1 %: 0.055)
#     2500 days:  1.5 %: 0.62    2 %: 0.98    (size at 1 %: 0.044)

The expected number of violations is 80. The unconditional normal method (mean and standard deviation of the past 1,000 days) has 183 violations and fails both coverage and independence: it underestimates the tail and also fails to follow changes in volatility, so its violations cluster. Historical simulation has 102 violations, and its independence is rejected too (p=0.002p = 0.002), because a 1,000-day window reacts too slowly to changing volatility. The conditional normal method (GARCH plus a normal quantile) passes independence comfortably (p=0.820p = 0.820), showing that GARCH captures volatility clustering, but has 165 violations and fails coverage: the residuals’ tails are fatter than normal. Conditional EVT has 87 violations and passes all three tests (p=0.438p = 0.438, 0.956 and 0.739). The last column is the ratio of the actual loss to the forecast ES on violation days: 1.02 for conditional EVT, close to 1, against 1.08 to 1.24 for the others. This points in the same direction as McNeil and Frey’s results, but remember that the data here were generated by a GARCH-t model, which conditional EVT happens to approximate well.

Finally, the program computes the power of Kupiec’s test. Over 250 trading days (about a year, the window commonly used in regulatory backtesting), a model whose true violation rate is 2 % (twice the nominal 1 %) has only a 24 % chance of being rejected; with a true rate of 1.5 %, only 11 %. Rejecting a 2 % model with about 80 % probability takes about 1,000 days. At 250 days the actual size of the test is 9.5 %, not 5 %, because of the discreteness of the binomial distribution. A year of backtesting that “does not reject” says almost nothing about whether a model is right.

Chapter summary

Block maxima and excesses over high thresholds converge to the generalized extreme value and generalized Pareto distributions, which share a shape parameter; these are limit results, and finite samples are biased. The Hill estimator applies only to power-law tails and must be read with the Hill and mean-excess plots. The GPD yields VaR and ES; ES is coherent but not elicitable on its own, which makes it harder to backtest. In simulated backtests conditional EVT gives violation counts close to nominal while normal methods clearly understate the tail, and Kupiec’s test has very low power with a year of data.

References

Acerbi, Carlo, and Dirk Tasche. 2002. “On the Coherence of Expected Shortfall.” Journal of Banking & Finance 26 (7): 1487–503. https://doi.org/10.1016/S0378-4266(02)00283-2.
Artzner, Philippe, Freddy Delbaen, Jean-Marc Eber, and David Heath. 1999. “Coherent Measures of Risk.” Mathematical Finance 9 (3): 203–28. https://doi.org/10.1111/1467-9965.00068.
Balkema, August A., and Laurens de Haan. 1974. “Residual Life Time at Great Age.” The Annals of Probability 2 (5): 792–804.
Basel Committee on Banking Supervision. 2016. Minimum Capital Requirements for Market Risk. Bank for International Settlements.
Christoffersen, Peter F. 1998. “Evaluating Interval Forecasts.” International Economic Review 39 (4): 841–62. https://doi.org/10.2307/2527341.
Coles, Stuart. 2001. An Introduction to Statistical Modeling of Extreme Values. Springer.
Davison, Anthony C., and Richard L. Smith. 1990. “Models for Exceedances over High Thresholds.” Journal of the Royal Statistical Society: Series B (Methodological) 52 (3): 393–442. https://doi.org/10.1111/j.2517-6161.1990.tb01796.x.
Embrechts, Paul, Claudia Klüppelberg, and Thomas Mikosch. 1997. Modelling Extremal Events for Insurance and Finance. Springer.
Fissler, Tobias, and Johanna F. Ziegel. 2016. “Higher Order Elicitability and Osband’s Principle.” The Annals of Statistics 44 (4): 1680–707. https://doi.org/10.1214/16-AOS1439.
Gneiting, Tilmann. 2011. “Making and Evaluating Point Forecasts.” Journal of the American Statistical Association 106 (494): 746–62. https://doi.org/10.1198/jasa.2011.r10138.
Hill, Bruce M. 1975. “A Simple General Approach to Inference about the Tail of a Distribution.” The Annals of Statistics 3 (5): 1163–74. https://doi.org/10.1214/aos/1176343247.
Hosking, J. R. M., J. R. Wallis, and E. F. Wood. 1985. “Estimation of the Generalized Extreme-Value Distribution by the Method of Probability-Weighted Moments.” Technometrics 27 (3): 251–61. https://doi.org/10.1080/00401706.1985.10488049.
Kupiec, Paul H. 1995. “Techniques for Verifying the Accuracy of Risk Measurement Models.” The Journal of Derivatives 3 (2): 73–84. https://doi.org/10.3905/jod.1995.407942.
McNeil, Alexander J., and Rüdiger Frey. 2000. “Estimation of Tail-Related Risk Measures for Heteroscedastic Financial Time Series: An Extreme Value Approach.” Journal of Empirical Finance 7 (3–4): 271–300. https://doi.org/10.1016/S0927-5398(00)00012-8.
Pickands, III, James. 1975. “Statistical Inference Using Extreme Order Statistics.” The Annals of Statistics 3 (1): 119–31. https://doi.org/10.1214/aos/1176343003.

Fan, Y. (2026). Macro-Liquidity Regime Switching, Extreme Tail Dependence and Barbell Asset Allocation: Vine Copulas, Hidden Markov Models and Sovereign Buffer Dynamics [宏观流动性体制转换、极值尾部相依与杠铃资产配置] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.23828049 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).