5D Library › Regime-Switching Fractional Kelly, Maximum-Drawdown Constraints and Lifecycle Leverage Allocation · 中文
Chapter 3. Hidden Regimes: How Fast a Bear Can Be Recognized and What a Regime-Aware Kelly Buys
The filter and its delay
If the market has two hidden regimes, the bettor’s best information about the current one is a probability. The Hamilton filter updates that probability each month from the month’s return, using the regime means, volatilities and persistence (Hamilton 1989). p05 runs it for 400,000 months on the market of Chapter 1, with the true parameters known to the filter, which is the most favourable case.
Calculation
# Chapter 3. p05: How fast can a hidden bear regime be recognized? The
# Hamilton filter of the two-regime market (p02), with the true
# parameters known, updates the chance of "bear" each month from that
# month's excess return. Delay = months from the first bear month
# until the filtered chance first exceeds a threshold; a false alarm
# is a bull month whose filtered chance exceeds it. 400,000 months,
# seed 98.
import random
from math import exp, pi, sqrt
BULL, BEAR = (0.12 / 12, 0.13 / sqrt(12)), (-0.25 / 12, 0.28 / sqrt(12))
STAY = (0.98, 0.92)
def dens(x, m, sd):
return exp(-0.5 * ((x - m) / sd) ** 2) / (sd * sqrt(2 * pi))
def step(p_bear, x):
prior = p_bear * STAY[1] + (1 - p_bear) * (1 - STAY[0])
a = prior * dens(x, *BEAR)
b = (1 - prior) * dens(x, *BULL)
return a / (a + b)
if __name__ == "__main__":
rng = random.Random(98)
s, p, states, probs = 0, 0.2, [], []
for _ in range(400000):
if rng.random() > STAY[s]:
s = 1 - s
x = rng.gauss(*(BULL if s == 0 else BEAR))
p = step(p, x)
states.append(s)
probs.append(p)
starts = [i for i in range(1, len(states))
if states[i] == 1 and states[i - 1] == 0]
lens = []
i = 0
while i < len(states):
if states[i] == 1:
j = i
while j < len(states) and states[j] == 1:
j += 1
lens.append(j - i)
i = j
else:
i += 1
print(" bear spells {}, mean length {:.1f} months".format(
len(lens), sum(lens) / len(lens)))
print(" threshold median delay missed spells false alarms/bull mo")
for th in (0.3, 0.5, 0.7):
delays, missed = [], 0
for st in starts:
k = st
while k < len(states) and states[k] == 1 and probs[k] <= th:
k += 1
if k < len(states) and states[k] == 1:
delays.append(k - st + 1)
else:
missed += 1
delays.sort()
bull = [probs[i] for i in range(len(states)) if states[i] == 0]
print(" {:9.1f} {:12d} {:13.3f} {:20.3f}".format(
th, delays[len(delays) // 2], missed / len(starts),
sum(q > th for q in bull) / len(bull)))
# bear spells 6376, mean length 12.5 months
# threshold median delay missed spells false alarms/bull mo
# 0.3 2 0.155 0.071
# 0.5 2 0.193 0.037
# 0.7 3 0.224 0.017The bear spells last 12.5 months on average. With a threshold of 0.5, the median delay before the filter says “bear” is two months, counting the first bear month; 0.193 of bear spells are never flagged before they end, and in 0.037 of bull months the filter raises a false alarm. Lowering the threshold to 0.3 catches more spells (0.155 missed) at the price of twice the false alarms (0.071). There is no threshold that gives both a short delay and few false alarms, because a bad month in a bull market looks like an ordinary bear month.
A regime-aware Kelly
A dynamic bettor can set leverage each month to times the ratio of the expected excess return to its expected second moment, given the filter’s probability. In a bull month with a confident filter this ratio is about 7, so p06 caps leverage at 3, and also tests a bettor whose model is optimistic: bull 0.18 and bear only -0.10.
Calculation
# Chapter 3. p06: Static versus regime-aware Kelly over ten years in the
# market of p02, starting in a bull month. A dynamic bettor sets
# leverage before each month from a Hamilton filter's chance of bear
# (p05): leverage = k * E[excess] / E[second moment], kept between 0
# and 3. "true" uses the real parameters; "optimistic" believes bull
# 0.18 (vol 0.13) and bear -0.10 (vol 0.20). Static leverages are k
# times the whole-history Kelly 1.46. Cash earns 0.02 a year. 10,000
# paths, seed 98.
import random
from math import exp, pi, sqrt
R12 = sqrt(12)
TRUE = ((0.12 / 12, 0.13 / R12), (-0.25 / 12, 0.28 / R12))
OPTI = ((0.18 / 12, 0.13 / R12), (-0.10 / 12, 0.20 / R12))
STAY, RF = (0.98, 0.92), 0.02 / 12
def dens(x, m, sd):
return exp(-0.5 * ((x - m) / sd) ** 2) / (sd * sqrt(2 * pi))
def prior(p):
return p * STAY[1] + (1 - p) * (1 - STAY[0])
def lev(p, k, mod):
(mb, sb), (mr, sr) = mod
q = prior(p)
m = q * mr + (1 - q) * mb
m2 = q * (sr * sr + mr * mr) + (1 - q) * (sb * sb + mb * mb)
return min(max(k * m / (m2 - m * m), 0.0), 3.0)
def update(p, x, mod):
q = prior(p)
a, b = q * dens(x, *mod[1]), (1 - q) * dens(x, *mod[0])
return a / (a + b)
RULES = (("static 0.5 x", None, 0.5), ("static 1.0 x", None, 1.0),
("true 0.25 x", TRUE, 0.25), ("true 0.5 x", TRUE, 0.5),
("optimistic 0.25 x", OPTI, 0.25))
if __name__ == "__main__":
rng = random.Random(98)
wealth = {r[0]: [] for r in RULES}
draw = {r[0]: [] for r in RULES}
for _ in range(10000):
s = 0
st = {r[0]: [1.0, 1.0, 0.0, 0.0] for r in RULES}
for _ in range(120):
if rng.random() > STAY[s]:
s = 1 - s
x = rng.gauss(*TRUE[s])
for name, mod, k in RULES:
v = st[name]
L = lev(v[3], k, mod) if mod else k * 1.46
v[0] = max(v[0] * (1 + RF + L * x), 0.0)
v[1] = max(v[1], v[0])
v[2] = max(v[2], 1 - v[0] / v[1])
if mod:
v[3] = update(v[3], x, mod)
for name in st:
wealth[name].append(st[name][0])
draw[name].append(st[name][2])
print(" rule median wealth DD>=20% DD>=50% 10th pct")
for name, _, _ in RULES:
ws, dd = sorted(wealth[name]), draw[name]
print(" {:<18} {:13.2f} {:7.3f} {:7.3f} {:8.2f}".format(
name, ws[5000], sum(d >= 0.2 for d in dd) / 1e4,
sum(d >= 0.5 for d in dd) / 1e4, ws[1000]))
# rule median wealth DD>=20% DD>=50% 10th pct
# static 0.5 x 1.77 0.700 0.181 0.77
# static 1.0 x 2.21 0.960 0.564 0.38
# true 0.25 x 2.69 0.678 0.005 1.34
# true 0.5 x 4.65 0.998 0.382 1.15
# optimistic 0.25 x 3.67 0.992 0.116 1.20With true parameters the dynamic bettor at 0.25 of its Kelly does well: median wealth 2.69 after ten years, a drawdown of half or more on only 0.005 of paths, and a tenth percentile of 1.34. At 0.5 the median rises to 4.65, but a drawdown of 20% or more becomes almost certain (0.998), because in bull months the cap of 3 is binding. The static bettors are far behind: full whole-history Kelly has median wealth 2.21 with a chance of 0.564 of halving.
The optimistic model shows what the advantage rests on. Believing the bear regime is milder than it is, the same 0.25 rule halves its wealth on 0.116 of paths and has a drawdown of 20% or more on 0.992. A regime-aware Kelly turns knowledge of the regimes into growth; it cannot create that knowledge, and the parameters of a bear regime are estimated from very few bear spells.
Hypothesis · not established
The author’s interpretation (not yet tested): in out-of-sample tests on long equity index histories, regime-filtered leverage beats a constant fraction of Kelly on drawdown only when the bear-regime parameters are estimated from at least several complete bear spells. What would show it wrong: a rolling out-of-sample test in which regime-filtered leverage with parameters estimated from one or two bear spells has a smaller maximum drawdown than constant leverage with the same average exposure.
Summary
Even a filter that knows the true regime parameters needs about two months to recognize a bear and misses about a fifth of bear spells. With true parameters a cautious regime-aware Kelly dominates static Kelly; with a model that underrates the bear regime, most of the drawdown protection disappears.
References
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).