5D Library › 宏观流动性体制转换、极值尾部相依与杠铃资产配置 · English

第二章 极值理论:从尾部指数到期望损失

为什么不能用正态分布估计尾部

风险管理关心的往往不是平均的一天,而是一百天、一千天才出现一次的那一天。正态分布在这里是一个糟糕的工具:它的尾部按 e−x2/2e^{-x^2/2} 衰减,比几乎所有金融收益的经验分布都快得多。第 20 本与第 38 本讨论过收益的厚尾与波动聚集;本章的问题更具体:如果我们只关心尾部,能不能只用尾部的数据、借助一个有理论依据的极限分布来估计它?极值理论给出的回答是:在相当宽的条件下可以,但「极限」两个字要认真对待。

块最大值与广义极值分布

把数据分成长度为 nn 的块(例如每年),取每块的最大损失 MnM_n。费希尔—蒂皮特—格涅坚科定理说:如果存在常数 an>0a_n > 0、bnb_n 使 (Mn−bn)/an(M_n – b_n)/a_n 的分布收敛到一个非退化的极限,这个极限必定是广义极值分布(GEV)

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,

ξ=0\xi = 0 时理解为 exp⁡(−e−x)\exp(-e^{-x})。形状参数 ξ\xi 决定尾部的类型:ξ>0\xi > 0 为弗雷歇型(幂律厚尾,例如学生 t),ξ=0\xi = 0 为古贝尔型(指数型尾部,例如正态),ξ<0\xi < 0 为有上界的韦布尔型 (Embrechts et al. 1997; Coles 2001)。块最大值方法的缺点是浪费数据:每块只用一个数。

超阈值与皮坎兹—巴尔克马—德哈恩定理

另一种做法是取一个高阈值 uu,研究超过它的部分 Y=X−uY = X – u。

证据

皮坎兹—巴尔克马—德哈恩定理 (Pickands 1975; Balkema and Haan 1974):分布 FF 属于某个 GξG_\xi 的最大值吸引域,当且仅当存在正函数 β(u)\beta(u),使超额分布 Fu(y)=P(X−u≤y∣X>u)F_u(y) = P(X – u \le y \mid X > u) 在 uu 趋向 FF 的右端点时一致收敛到广义帕累托分布(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.

两种方法的形状参数 ξ\xi 是同一个。戴维森与史密斯系统地发展了基于这个结果的超阈值统计模型 (Davison and Smith 1990)。

定理有两个前提常被省略。第一,FF 必须属于某个极值分布的吸引域;大多数连续分布满足,但不是全部。第二,它是一个极限结果:阈值越高,近似越好,可用的数据也越少。在有限样本中,阈值的选择是偏差与方差之间的权衡。

希尔估计量是 ξ>0\xi > 0 时最常用的估计 (Hill 1975):把损失从大到小排列为 X(1)≥X(2)≥⋯X_{(1)} \ge X_{(2)} \ge \cdots,取前 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 .

平均超额函数 e(u)=E[X−u∣X>u]e(u) = E[X – u \mid X > u] 是另一个诊断工具:若超额服从 ξ<1\xi < 1 的 GPD,e(u)=(β+ξu)/(1−ξ)e(u) = (\beta + \xi u)/(1 – \xi) 是 uu 的线性函数,斜率 ξ/(1−ξ)\xi/(1-\xi);正态分布的 e(u)e(u) 则大约按 1/u1/u 下降。作者框架建议用平均超额图选择阈值:在图开始近似线性的地方取阈值。

推导

# 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

对自由度为 3 的学生 t 分布(真实 α=3\alpha = 3),希尔估计在 k=25k = 25 到 100 时为 3.40、3.22、2.84,随后一路下降到 k=1,600k = 1{,}600 时的 1.14:取的数据太多,就把分布的中心部分也当成了尾部。对正态数据,希尔估计从 10.06 降到 1.29,其中 k=400k = 400 时的 3.74 看上去就像一个尾部指数约为 3.7 的幂律厚尾,与 t 分布在小 kk 处的估计(3.22 到 3.40)及其真值 3 相差无几,而正态分布根本没有幂律尾部。所以单看某一个 kk 的希尔估计,既可能把薄尾误认为厚尾,也说不出真正的尾部指数;需要看整条「希尔图」是否有稳定的平台,并结合平均超额图。图 2 给出了这两种图:t 分布的 e(u)e(u) 从 1.08 升到 1.95,近似线性(理论斜率 0.5);正态分布的 e(u)e(u) 从 0.54 降到 0.27。用 50 个块最大值估计 GEV 的形状参数(概率加权矩法 (Hosking et al. 1985)),t 分布的中位数为 0.290、90% 区间 0.066 到 0.572,正态分布为 −0.109、区间 −0.277 到 0.071:方向是对的,但 50 个数据点的不确定性很大。

左:平均超额函数 e(u);右:希尔估计随所用尾部数据个数 k 的变化。实线为自由度 3 的学生 t 分布,虚线为正态分布,各 5,000 个模拟损失。

从尾部分布到 VaR 与 ES

在 pp 水平上,风险价值 VaRp\mathrm{VaR}_p 是损失分布的 pp 分位数,期望损失 ESp=E[X∣X>VaRp]\mathrm{ES}_p = E[X \mid X > \mathrm{VaR}_p] 是超过它的损失的平均。用超过阈值的 kk 个数据(样本量 nn)拟合 GPD 后,

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).

证据

阿兹纳等人提出「一致风险度量」的四条公理,VaR 不满足其中的次可加性:两笔头寸合起来的 VaR 可以大于各自 VaR 之和 (Artzner et al. 1999)。阿切尔比与塔舍证明 ES 是一致的风险度量 (Acerbi and Tasche 2002)。但格奈廷证明 ES 不是「可引出的」(没有一个评分函数能使诚实报告 ES 成为最优),这使 ES 的回测比 VaR 困难 (Gneiting 2011);菲斯勒与齐格尔证明 VaR 与 ES 合在一起是可引出的 (Fissler and Ziegel 2016)。巴塞尔委员会 2016 年的市场风险框架把内部模型的主要度量从 99% VaR 改为 97.5% ES (Basel Committee on Banking Supervision 2016)。

下面的程序检验这些公式在有限样本中的表现:真实损失为自由度 4 的学生 t 分布(标准差 1,真实 ξ=0.25\xi = 0.25),每个样本 2,500 天,重复 200 次。

推导

# 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

在 99% 水平上,正态拟合的 VaR 中位数为 2.32,真实值 2.65;正态的 ES 为 2.66,真实值 3.69,低估约 28%。历史模拟与 GPD 在这个水平上都基本无偏。到 99.9% 水平,差别变得醒目:正态 VaR 只有 3.08(真实 5.07),历史模拟的中位数 4.94 虽然接近,但 90% 区间宽达 3.94 到 6.48,因为它只依赖样本中最大的两三个数;GPD(k=125k = 125)的 VaR 中位数 5.00,区间 4.11 到 6.25。GPD 的 ES 中位数 6.49,略低于真实的 6.85,原因在最后三行:形状参数的估计中位数只有 0.13 到 0.16,而真实值是 0.25。学生 t 分布的超额只在阈值趋于无穷时才精确服从 GPD,在有限的阈值上存在「二阶偏差」;减小 kk 能降低偏差,但方差迅速增大(k=50k = 50 时区间从 −0.16 到 0.44)。所以极值方法给出的是比正态好得多、但仍有系统误差与很大抽样误差的尾部估计。

条件极值方法与回测

金融收益的尾部不是一成不变的:在高波动的日子里,同样的分位数对应更大的损失。麦克尼尔与弗雷提出两步法:先用拟极大似然估计 GARCH 模型,得到每天的条件波动率 σt\sigma_t 与标准化残差 zt=xt/σtz_t = x_t / \sigma_t;再对残差的尾部拟合 GPD,得到残差的分位数 qzq_z 与期望损失 eze_z;明天的 VaR 与 ES 就是 σt+1qz\sigma_{t+1} q_z 与 σt+1ez\sigma_{t+1} e_z (McNeil and Frey 2000)。GARCH 本身在第 20 本已经讨论过,这里只用它作为波动率的滤波器。

证据

麦克尼尔与弗雷在 1,000 天的滚动窗口上估计,并对残差中最大的 100 个拟合 GPD,回测了标普 500、DAX、宝马股票、美元/英镑汇率与黄金五个日收益序列。在 99% 水平上,条件正态方法在五个序列中有四个被拒绝(例如标普 500 期望突破 74 次,实际 104 次),条件极值方法一次也没有被拒绝(73 次);在 95%、99% 与 99.5% 三个水平共 15 次检验中,条件正态方法失败 11 次,条件极值方法从未失败 (McNeil and Frey 2000)。

回测用的两种检验是作者框架点名的。库皮克检验(无条件覆盖)比较实际突破次数 xx 与期望 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)。克里斯托弗森检验进一步检查突破是否成串出现:把每天是否突破看作一条两状态马尔可夫链,比较「昨天突破后今天突破」与「昨天没突破后今天突破」的概率是否相同(独立性检验 LRind\mathrm{LR}_{ind}),并与覆盖检验合并为条件覆盖检验 LRcc=LRuc+LRind∼χ22\mathrm{LR}_{cc} = \mathrm{LR}_{uc} + \mathrm{LR}_{ind} \sim \chi^2_2 (Christoffersen 1998)。

下面的程序模拟四个 GARCH(1,1) 序列(冲击为自由度 5 的学生 t 分布),每个序列在 1,000 天的滚动窗口上每 250 天重新估计一次,共 8,000 个一日预测,比较四种方法。

推导

# 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)

期望的突破次数是 80 次。无条件正态方法(用过去 1,000 天的均值与标准差)突破 183 次,覆盖与独立性都被拒绝:它既低估了尾部,也跟不上波动的变化,突破成串出现。历史模拟突破 102 次,独立性同样被拒绝(p=0.002p = 0.002),因为 1,000 天的窗口对波动的变化反应太慢。条件正态(GARCH + 正态分位数)的独立性很好(p=0.820p = 0.820),说明 GARCH 捕捉了波动聚集,但突破 165 次,覆盖被拒绝:残差的尾部比正态厚。条件极值方法突破 87 次,三项检验都不拒绝(p=0.438p = 0.438、0.956、0.739)。最后一列是突破日的实际损失与预测 ES 之比:条件极值方法为 1.02,接近 1,其余方法在 1.08 到 1.24 之间。这与麦克尼尔与弗雷的结论方向一致,但要记住,这里的数据是按 GARCH-t 模型生成的,条件极值方法的设定恰好接近真实模型。

程序最后计算了库皮克检验的把握度:在 250 个交易日(约一年,监管回测常用的窗口)中,一个真实突破率为 2%(名义 1% 的两倍)的模型,只有 24% 的机会被拒绝;真实突破率 1.5% 时只有 11%。要以约 80% 的把握拒绝 2% 的模型,需要约 1,000 天。250 天时检验的实际显著性水平为 9.5% 而不是 5%,这是二项分布离散性造成的。一年的回测「没有拒绝」,几乎说明不了模型是对的。

本章小结

块最大值与高阈值超额分别收敛到广义极值分布与广义帕累托分布,二者共享形状参数;这些是极限结果,有限样本有偏。希尔估计量只适用于幂律尾部,须结合希尔图与平均超额图判断。由 GPD 可得 VaR 与 ES;ES 是一致的风险度量,但单独不可引出,回测更难。条件极值方法在模拟回测中突破次数接近名义值,正态方法明显低估尾部;库皮克检验在一年的数据中把握度很低。

参考文献

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).