跳至主要內容

回測視窗 2016-05-02 〜 2026-10-26 · 資料截至 2026-10-27

美股動能廣度擇時(槓桿 ETF)

以流動性前 500 檔美股的 12−1 月動能廣度(超過 8%)與 QQQ 趨勢判斷多空:多頭月份在最強的防禦型 ETF 之外加上 TQQQ、TECL(約各 25%、防禦 50%),空頭月份只持有 IEF、GLD、SHY 中最強的一檔;月換股、8% 停損。2016 年 5 月至 2026 年 10 月回測年化報酬 29.9%、日夏普 1.40、最大回撤 -21.1%;同視窗 QQQ 含息年化 20.7%、日夏普 0.95、最大回撤 -35.1%。鄰近參數、前後兩段、每邊 0.1% 交易成本三項驗證皆通過。

投資警語:本文僅供教學參考,不構成投資建議。過去績效不代表未來表現,投資有風險。

回測績效

年化報酬率
29.9%
日夏普
1.40
最大回撤
-21.1%
總報酬率
1457%

回測不計手續費與交易稅(finlab 套件 sim() 的美股預設成本),日夏普未扣無風險利率。策略淨值自資料可得日(2016-05-02)起算。

淨值曲線(對數座標)

美股動能廣度擇時(槓桿 ETF) vs QQQ 買進持有(含息)
1x2x3x5x8x12x2016-05-022018-01-232019-10-172021-07-152023-04-112025-01-272026-10-26
美股動能廣度擇時(槓桿 ETF)QQQ 買進持有(含息)

與 QQQ 買進持有(含息)對照

對象年化報酬率日夏普最大回撤統計視窗
美股動能廣度擇時(槓桿 ETF)29.9%1.40-21.1%2016-05-02 〜 2026-10-26
QQQ 買進持有(含息)20.7%0.95-35.1%2016-05-02 〜 2026-10-26

完整策略程式碼

安裝 finlab 套件後即可直接執行重現(finlab.login() 會自動引導登入,不需手動填 token)。想用 AI 輔助安裝與跑第一次回測,可以走安裝教學。

展開程式碼(strategy.py)
"""US cross-sectional momentum -> leveraged-ETF regime strategy (FinLab).

The screen runs on the full liquid US universe; the tradable position is a small
basket of leveraged growth ETFs that is only held when stock-level momentum
breadth and the QQQ trend are both positive. Reproduces the backtest in the
article. Complete the AI-assisted setup flow at https://finlab.finance/en/setup before running this file.

    python strategy.py              # backtest
    python strategy.py --validate   # robustness checks from the article
"""
import sys

import finlab
from finlab import data
from finlab.backtest import sim
from finlab.dataframe import FinlabDataFrame

RISK_ASSETS = ["TQQQ", "TECL"]            # leveraged growth ETFs (held in risk-on)
DEFENSIVE_ASSETS = ["IEF", "GLD", "SHY"]  # treasuries / gold / cash-like (risk-off)


def liquid_universe(close, raw_close, volume, top_n=500, min_price=10, min_dollar_volume=10_000_000):
    """Point-in-time top-N universe by 60-day dollar volume, with price and
    data-quality gates so the backtest can only pick names it could trade.
    Volume is not split-adjusted, so dollar volume and the price floor use the
    unadjusted close (adjusted close x volume overstates reverse-split names)."""
    dollar_volume = (raw_close * volume).rolling(60, min_periods=20).mean()
    top_liquid = dollar_volume.is_largest(top_n)
    liquid_enough = dollar_volume > min_dollar_volume
    price_ok = raw_close > min_price

    # Drop names for a year after any single-day move >= 50% (split/data artifacts).
    returns = close.pct_change()
    extreme = returns.abs() >= 0.50
    recently_bad = extreme.rolling(252, min_periods=1).max().shift(1).fillna(False) > 0
    return top_liquid & liquid_enough & price_ok & (~recently_bad.astype(bool))


def build_position(breadth_threshold=0.08, trend_window=200):
    data.set_market("us")
    close = data.get("us_price:adj_close")
    raw_close = data.get("us_price:close")
    volume = data.get("us_price:volume")
    fund_close = data.get("us_fund_price:adj_close")[["QQQ"] + RISK_ASSETS + DEFENSIVE_ASSETS]

    # 1. Liquid universe + the 12-month-minus-1-month momentum factor.
    universe = liquid_universe(close, raw_close, volume)
    ret_12m = close / close.shift(252) - 1
    ret_1m = close / close.shift(21) - 1
    momentum = ret_12m - ret_1m

    # 2. Breadth: share of the universe that are top-decile, positive-trend leaders.
    leaders = (momentum[universe].rank(axis=1, pct=True) > 0.90) & (ret_12m > 0)
    breadth = leaders.sum(axis=1) / universe.sum(axis=1)

    # 3. Risk-on regime: broad momentum AND QQQ above its 200-day with positive 126-day trend.
    qqq_trend = fund_close["QQQ"] > fund_close["QQQ"].rolling(trend_window, min_periods=trend_window // 2).mean()
    qqq_mom = fund_close["QQQ"] / fund_close["QQQ"].shift(126) - 1
    risk_on = (breadth > breadth_threshold) & (qqq_trend & (qqq_mom > 0)).reindex(breadth.index)
    risk_on = risk_on.reindex(fund_close.index).fillna(False)

    # 4. Risk-off: 1 defensive ETF. Risk-on: the 2 strongest leveraged ETFs are added
    #    next to the defensive ETF (risk_on is an object column after reindex/fillna,
    #    so ~risk_on does not switch it off); the book ends up about 25% TQQQ,
    #    25% TECL and 50% defensive. The article's numbers are for this behaviour.
    risk_score = FinlabDataFrame(fund_close[RISK_ASSETS].pct_change(126))
    defensive_score = FinlabDataFrame(
        fund_close[DEFENSIVE_ASSETS].pct_change(63) - fund_close[DEFENSIVE_ASSETS].pct_change(21)
    )
    risky = risk_score.is_largest(2) & risk_on.to_frame().reindex(risk_score.index).iloc[:, 0]
    risky = risky.astype(float).div(risky.astype(float).sum(axis=1), axis=0).fillna(0)
    defensive = (
        defensive_score.is_largest(1) & (~risk_on).to_frame().reindex(defensive_score.index).iloc[:, 0]
    ).astype(float)

    position = (
        risky.reindex(fund_close.index).fillna(0)
        .join(defensive.reindex(fund_close.index).fillna(0), how="outer")
        .fillna(0)
        .T.groupby(level=0).max().T
    )
    return position.loc["2016-01-01":]


def run_backtest(position, fee_ratio=None):
    data.set_market("us_fund")
    return sim(
        position,
        resample="M",           # rebalance monthly
        position_limit=1,       # max weight PER asset (1.0 = 100%); the holdings and
                                # weights come from build_position() (see step 4 there)
        stop_loss=0.08,         # 8% touched stop on the ETF leg
        touched_exit=True,
        trade_at_price="close",
        fee_ratio=fee_ratio,    # None = finlab's US default (0 commission, 0 tax)
        upload=False,
    )


# ---------------------------------------------------------------------------
# Robustness checks behind the article's validation section:
#     python strategy.py --validate
# "Beats QQQ" means a higher daily Sharpe than buying and holding QQQ
# (dividend-adjusted) over exactly the same dates.
# ---------------------------------------------------------------------------
COST_PER_SIDE = 0.001  # 0.1% per buy and per sell, for spread and slippage


def daily_sharpe(equity):
    returns = equity.pct_change().dropna()
    return returns.mean() / returns.std() * 252 ** 0.5


def sharpe_vs_qqq(equity):
    qqq = data.get("us_fund_price:adj_close")["QQQ"].reindex(equity.index).ffill()
    return daily_sharpe(equity), daily_sharpe(qqq)


def validate():
    # 1. Neighbouring parameters: the original value and one step either side.
    wins = 0
    for breadth_threshold in (0.06, 0.08, 0.10):
        for trend_window in (150, 200, 250):
            report = run_backtest(build_position(breadth_threshold, trend_window))
            strategy, qqq = sharpe_vs_qqq(report.creturn)
            wins += strategy > qqq
            print(f"breadth>{breadth_threshold:.2f} QQQ>{trend_window}d MA: "
                  f"Sharpe {strategy:.2f} vs QQQ {qqq:.2f}")
    print(f"{wins}/9 parameter sets beat QQQ")

    # 2. First half and second half of the backtest, each on its own.
    equity = run_backtest(build_position()).creturn
    middle = equity.index[len(equity) // 2]
    for label, part in (("first half", equity.loc[:middle]), ("second half", equity.loc[middle:])):
        strategy, qqq = sharpe_vs_qqq(part)
        print(f"{label} {part.index[0].date()} to {part.index[-1].date()}: "
              f"Sharpe {strategy:.2f} vs QQQ {qqq:.2f}")

    # 3. Trading costs: finlab's US default is zero, so charge 0.1% per side.
    report = run_backtest(build_position(), fee_ratio=COST_PER_SIDE)
    strategy, qqq = sharpe_vs_qqq(report.creturn)
    print(f"with 0.1% per side: CAGR {report.get_stats()['cagr']:.1%}, "
          f"Sharpe {strategy:.2f} vs QQQ {qqq:.2f}")


def main():
    finlab.login()  # finlab guides you through login automatically
    if "--validate" in sys.argv:
        validate()
        return
    report = run_backtest(build_position())
    print(report.get_stats())
    report.display()


if __name__ == "__main__":
    main()

下載 strategy.py 下載 data.csv(淨值曲線)

到 FinLab Studio 重現這支策略

在 Studio 裡用同一套真實資料調整條件、重跑回測。

本頁策略與回測結果僅供教學與研究用途,詳見服務條款。