5D Library › 体制转换分数凯利、最大回撤约束与生命周期杠杆配置 · English

第五章 拉尔夫·文斯的最优 f:交易者单位下的凯利及其回撤

最优 f 是什么

拉尔夫·文斯的最优 f 自 1990 年起在期货交易者中流行,它根据过去交易结果的清单确定仓位 (Vince 1990)。在比例 ff 下,每笔交易的持有期收益是 1+ft/B1 + f \, t / B,其中 tt 是该笔交易的盈利,BB 是清单中最大的一笔亏损;交易者每有 B/fB/f 美元权益就持有一张合约。最优 f 使这些收益的几何平均最大。这就是把凯利准则用在交易的经验分布上,只是下注以最大亏损为单位来度量;文斯的贡献在于实用的记账方法,他本人也提醒过,按最优值交易会带来很深的回撤。p09 使用一份由 20 笔交易组成的示意清单。

推导

# Chapter 5. p09: Ralph Vince's optimal f on an illustrative list of 20
# trade results (dollars per contract). Holding period return of a
# trade t at fraction f is 1 + f * t / B, B the largest loss (300): one
# contract is traded for every B / f dollars of equity. Optimal f
# maximizes the geometric mean; TWR is the product over the list.
# Drawdowns at each f are measured on 2,000 sequences of 100 trades
# drawn from the list with replacement, seed 98.
import random
from math import exp, log

TRADES = (250, -100, 80, -150, 400, -120, -90, 60, 300, -200,
          150, -80, -110, 500, -60, 90, -140, 70, -300, 220)
B = -min(TRADES)

def g(f):
    return sum(log(1 + f * t / B) for t in TRADES) / len(TRADES)

def argmax(fun, lo, hi):
    for _ in range(100):
        a, b = lo + (hi - lo) / 3, hi - (hi - lo) / 3
        lo, hi = (a, hi) if fun(a) < fun(b) else (lo, b)
    return (lo + hi) / 2

def max_dd(seq, f):
    w = peak = 1.0
    dd = 0.0
    for t in seq:
        w *= 1 + f * t / B
        peak = max(peak, w)
        dd = max(dd, 1 - w / peak)
    return dd

if __name__ == "__main__":
    fo = argmax(g, 0.0, 0.999)
    lo, hi = fo, 0.999
    for _ in range(100):
        mid = (lo + hi) / 2
        lo, hi = (mid, hi) if g(mid) > 0 else (lo, mid)
    print("   mean trade {:.1f}, largest loss {}".format(
        sum(TRADES) / 20, B))
    print("   optimal f {:.3f}: one contract per {:.0f} dollars".format(
        fo, B / fo))
    print("   growth turns negative above f = {:.3f}".format(lo))
    rng = random.Random(98)
    seqs = [[rng.choice(TRADES) for _ in range(100)] for _ in range(2000)]
    print("   f       f/opt  TWR(20)  median MDD  P(MDD>=50%)")
    for k in (0.25, 0.5, 1.0, 1.5, 2.0):
        f = k * fo
        dd = sorted(max_dd(s, f) for s in seqs)
        print("   {:.3f}  {:5.2f}  {:7.2f}  {:10.3f}  {:11.3f}".format(
            f, k, exp(20 * g(f)), dd[1000],
            sum(d >= 0.5 for d in dd) / 2000))
#    mean trade 38.5, largest loss 300
#    optimal f 0.300: one contract per 999 dollars
#    growth turns negative above f = 0.594
#    f       f/opt  TWR(20)  median MDD  P(MDD>=50%)
#    0.075   0.25     1.18       0.259        0.019
#    0.150   0.50     1.33       0.468        0.407
#    0.300   1.00     1.45       0.760        0.976
#    0.450   1.50     1.32       0.918        1.000
#    0.601   2.00     0.98       0.983        1.000

这份清单的平均盈利是 38.5 美元,最大亏损 300;最优 f 是 0.300,即每 999 美元一张合约。f 超过 0.594 后增长转负,几乎恰好是最优值的两倍,与第一章的「两倍凯利」边界相同。在 100 笔交易的重抽样序列上,最优值下最大回撤的中位数是 0.760,出现腰斩以上回撤的机会是 0.976。最优 f 的一半在 20 笔交易上保留 1.33 的 TWR(最优值是 1.45),回撤中位数 0.468;四分之一保留 1.18,回撤 0.259。

用短记录估计最优 f

更深的问题在于清单本身。p10 把这 20 笔交易当作全体,让 4,000 名交易者各自看到从中抽出的 30 笔交易记录。

推导

# Chapter 5. p10: Optimal f estimated from a short record. Treat the 20
# trades of p09 as the whole population. A trader sees 30 trades drawn
# from it, computes optimal f and the largest loss of that sample, and
# then trades the next 100 trades with that sizing (contracts per
# dollar = f / largest loss), or with half of it. Sizes are reported
# relative to the true optimum (0.300 / 300). 4,000 traders, seed 98.
import random
from math import log

TRADES = (250, -100, 80, -150, 400, -120, -90, 60, 300, -200,
          150, -80, -110, 500, -60, 90, -140, 70, -300, 220)

def opt_f(sample):
    b = -min(sample)
    if b <= 0:
        return 0.999, 1.0
    def g(f):
        return sum(log(1 + f * t / b) for t in sample)
    lo, hi = 0.0, 0.999
    for _ in range(80):
        x, y = lo + (hi - lo) / 3, hi - (hi - lo) / 3
        lo, hi = (x, hi) if g(x) < g(y) else (lo, y)
    return (lo + hi) / 2, b

def grow(seq, size):
    w = 1.0
    for t in seq:
        w = max(w * (1 + size * t), 0.0)
    return w

if __name__ == "__main__":
    rng = random.Random(98)
    true_size = 0.300 / 300
    rel, missed = [], 0
    out = {"true": [], "estimated": [], "half": []}
    for _ in range(4000):
        f, b = opt_f([rng.choice(TRADES) for _ in range(30)])
        size = f / b
        missed += b < 300
        rel.append(size / true_size)
        fut = [rng.choice(TRADES) for _ in range(100)]
        out["true"].append(grow(fut, true_size))
        out["estimated"].append(grow(fut, size))
        out["half"].append(grow(fut, size / 2))
    rel.sort()
    q = lambda v, a: v[int(a * (len(v) - 1))]
    print("   estimated size / true size: 10% {:.2f}, median {:.2f},"
          " 90% {:.2f}".format(q(rel, 0.1), q(rel, 0.5), q(rel, 0.9)))
    print("   share sized above 2 x true: {:.3f}".format(
        sum(r > 2 for r in rel) / 4000))
    print("   share whose sample missed the -300 loss: {:.3f}".format(
        missed / 4000))
    print("   sizing        median TWR(100)  10th pct  share losing money")
    for k in ("true", "estimated", "half"):
        v = sorted(out[k])
        print("   {:<12}  {:15.2f}  {:8.3f}  {:18.3f}".format(
            k, q(v, 0.5), q(v, 0.1), sum(x < 1 for x in v) / 4000))
#    estimated size / true size: 10% 0.00, median 1.03, 90% 2.28
#    share sized above 2 x true: 0.150
#    share whose sample missed the -300 loss: 0.209
#    sizing        median TWR(100)  10th pct  share losing money
#    true                     6.29     0.537               0.173
#    estimated                1.75     0.034               0.252
#    half                     2.31     0.966               0.110

交易者的中位数仓位大致正确(真实最优值的 1.03 倍),但离散程度极大:十分之一的人仓位为零,因为他们的样本显示没有优势;另有十分之一的人仓位达到最优值的 2.28 倍以上;0.150 的人超过两倍。30 笔交易的样本漏掉最大亏损的机会是 0.209,记录中缺了最坏一笔的交易者,会用较小的 BB 来定仓位。

在接下来的 100 笔交易中,真实最优值给出的 TWR 中位数是 6.29;估计出的最优值只有 1.75,第十百分位数 0.034,亏钱的机会 0.252。估计值的一半在每一项关系到生存的指标上都更好:中位数 2.31,第十百分位数 0.966,亏钱的机会 0.110。当最优值必须估计时,只用它的一部分不是胆怯,而是更好的下注。

假说 · 尚未验证

作者的诠释(尚未验证): 用少于五十笔自身交易记录算出最优 f 并据此定仓位的交易者,其期末权益低于只用该仓位一半的交易者。什么会证明它错: 在券商的系统化期货账户记录中,按估计的最优 f 全值定仓的账户,一百笔交易后的权益中位数高于按其一半定仓的账户,而销户率并不更高。

小结

最优 f 是交易者单位下的凯利,继承了凯利的两个性质:到最优值的两倍时增长消失,而在最优值本身,腰斩以上的回撤也是常态。用 30 笔交易估计时,它的不确定性大到用估计值的一半反而中位数增长更快、亏钱的情况少得多。

参考文献

Vince, Ralph. 1990. Portfolio Management Formulas: Mathematical Trading Methods for the Futures, Options, and Stock Markets. John Wiley & Sons.

Fan, Y. (2026). Regime-Switching Fractional Kelly, Maximum-Drawdown Constraints and Lifecycle Leverage Allocation: Cyclical Drift Estimation Errors, Ruin-Bounded Bet Sizing and Human-Capital Amortization [体制转换分数凯利、最大回撤约束与生命周期杠杆配置] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090256 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).