跳到正文
DEV Community· AlgoRover·· 1 小時前AI 評分41

挑選 4,843 次回測中的最佳策略:其夏普比率有多少隻是運氣?

Picking the best of 4,843 backtests: how much of its Sharpe is luck?

AI 導讀

4,843 次回測中,最佳策略的夏普比率為 3.39,但是否只是運氣取決於回測年期。假設策略沒有優勢,1 年、2 年和 5 年回測的最高夏普比率約為 3.68、2.60 和 1.65;文章未交代實際回測年期。作者建議從觀察值扣除運氣基準,並先以樣本外模擬交易,再投入資金。

正文

Cover image for Picking the best of 4,843 backtests: how much of its Sharpe is luck?

AlgoRover

A post reports that the best of 4,843 backtested strategies has a Sharpe of 3.39. With no edge at all, the best would still land around 3.68 on a 1-year daily backtest, 2.60 on 2 years and 1.65 on 5. So 3.39 is within the luck range for a 1-year test and clearly above it for 5 years. The post summary doesn't give the backtest length, so we can't tell which case applies.

Where 3.68 comes from

With zero edge, an annualized Sharpe from daily data is noise with a standard error of about 1/√T (T in years). The expected maximum of N standard normals is about (1−γ)·Φ⁻¹(1−1/N) + γ·Φ⁻¹(1−1/(N·e)), with γ ≈ 0.5772. At N = 4,843 that gives 0.4228×3.53 + 0.5772×3.79 ≈ 3.68. For longer tests, divide by √T.

Check it by simulation

import numpy as np
from statistics import NormalDist

def chance_max_sharpe(n, years):
    g, z = 0.5772156649, NormalDist().inv_cdf
    m = (1-g)*z(1-1/n) + g*z(1-1/(n*np.e))
    return m / np.sqrt(years)

rng = np.random.default_rng(42)
N = 4843
for years in (1, 2, 5):
    maxes = []
    for _ in range(100):
        r = rng.standard_normal((N, 252*years))
        sr = r.mean(1) / r.std(1, ddof=1) * np.sqrt(252)
        maxes.append(sr.max())
    print(years, round(np.mean(maxes), 2),
          round(chance_max_sharpe(N, years), 2))

It prints the years, the simulated mean maximum and the formula value. Run it and check that the two columns come out close (no output is shown here). At 5 years each repeat draws about 6.1 million numbers, so lower the repeat count if it's slow.

Apply it to your own ranking

def haircut(observed_sr, n_trials, years):
    return observed_sr - chance_max_sharpe(n_trials, years)

def min_years(target_sr, n_trials):
    return (chance_max_sharpe(n_trials, 1) / target_sr) ** 2

N should count every parameter set, symbol and timeframe you tried, including the ones you dropped. At N = 4,843, min_years says a top Sharpe of 2 needs about 3.4 years of data to clear the chance level.

Limits

The summary also doesn't list the return frequency, whether the Sharpe is annualized, costs or how correlated the strategies are. These numbers assume zero edge, independent strategies, normal returns and daily data, and since correlation shrinks the effective N and lowers the benchmark, treat them as a rough range, not a verdict on the post's list.

What to do

Subtract the chance maximum from your top strategy's Sharpe before you trust it. A strategy that clears the bar has still only passed a historical backtest, so paper trade it out of sample before you risk money.

This article was drafted with AI assistance and reviewed by the author.

python #statistics #trading #backtesting

來源:DEV Community · dev.to