DEV Community

citoapi
citoapi

Posted on

Tennis Surface Elo & Closing-Line Value Modeling in Python (ATP, WTA, Challenger & ITF)

Tennis is the purest head-to-head quantitative laboratory in sports. There are no teammates, draws do not exist, every match has a deterministic surface (Hard, Clay, or Grass), and the calendar spans over 20,000 professional matches per year across ATP, WTA, Challenger, and ITF circuits.

Yet most public tutorials stop at a basic ATP-only Elo script and never measure surface-blended calibration, out-of-sample log-loss, or Closing-Line Value (CLV) across lower-liquidity tiers where edges actually live.

In this guide, we walk through:

  1. Real 2026 chronological out-of-sample metrics from our open model aidancoit9203/tennis-elo-match-predictor (n = 21,274 2026 test matches).
  2. Market vig and favorite win rates across 4,572 rolling 30-day closing lines from ATP Masters 1000 down to ITF M25/W35.
  3. Reproducible Python code for surface-blended Elo, Bo3-to-Bo5 Markov amplification, CLV calculation, and live Tennis API integration.

You can test surface Elo blends and CLV math live in the Tennis Closing-Line & Surface Elo Calculator Space.


1. Real 2026 Out-of-Sample Benchmarks (n = 21,274 Matches)

Our open Platt-calibrated XGBoost model (aidancoit9203/tennis-elo-match-predictor) was warmed up on 2019 to 2021, trained on 62,276 matches (2022 to June 2025), calibrated on 9,289 matches (H2 2025), and evaluated strictly out-of-sample on 21,274 matches across 2026:

Model / Evaluation Slice Matches (n) Accuracy ROC-AUC Log-Loss Brier ECE (10-bin)
Calibrated XGBoost (All 2026 OOS) 21,274 67.15% 0.7361 0.6025 0.2079 0.0090
Baseline: Overall Elo Only 21,274 64.72% 0.7054 0.6255 0.2181 0.0159
Baseline: Surface Elo Only 21,274 64.21% 0.6950 0.6339 0.2216 0.0208
Baseline: Official Rank Logistic 21,274 63.19% 0.6858 0.6390 0.2242 0.0204
Slice: ATP (2026) 15,094 67.06% 0.7335 0.6048 0.2088 0.0100
Slice: WTA (2026) 6,180 67.38% 0.7423 0.5968 0.2056 0.0130
Slice: Clay 8,681 67.52% 0.7426 0.5976 0.2057 0.0132
Slice: Hard 11,226 67.14% 0.7340 0.6041 0.2086 0.0071
Slice: Grass 1,367 64.96% 0.7104 0.6197 0.2159 0.0214

Look at why combining signals dominates pure Elo: overall Elo captures base skill (29.92% + 25.78% gain share), surface Elo captures clay/grass specialization (7.33% + 5.04%), official ranking points capture recent tournament tier quality (5.76% + 4.83%), and rolling serve dominance (second_serve_won_pct_diff 2.02%, first_serve_won_pct_diff 1.98%) separates big servers on fast courts. Notice also the calibration precision: 0.0071 Expected Calibration Error on Hard courts across 11,226 matches.


2. Where Liquidity and Overround Diverge Across Tiers

Using aidancoit9203/tennis-betting-odds-closing-lines-dataset (4,572 H2H closing lines, 9,383 pre-match hourly movement snapshots, and 2,857 spread/set lines), here is how market friction scales down the pro pyramid:

Tour & Tier 30-Day Matches Avg Close Overround Avg Abs Prob Shift Closing Fav Win %
ATP Tour Finals 15 3.90% 2.86 pp 93.33%
ATP 250 37 5.09% 3.20 pp 63.89%
WTA 250 57 5.18% 2.42 pp 71.43%
ATP Masters 1000 52 5.24% 3.24 pp 62.75%
ATP Challenger 1,185 5.99% 3.14 pp 68.87%
WTA 125 180 6.41% 2.38 pp 74.72%
WTA ITF 1,478 7.57% 3.21 pp 73.85%
ATP ITF 1,524 7.67% 2.30 pp 75.15%

On Tour Finals and Masters 1000 matches, overround compresses to 3.9% to 5.2%. On Challenger (1,185 matches/month) and ITF (3,002 matches/month), overround widens to 6.0% to 7.7%, but opening lines move by 2.3 to 3.2 percentage points before first serve, rewarding automated opening-line scanners that track player fatigue, surface transitions, and ITF/Challenger qualifying form.


3. Python Implementation: Surface Elo, Bo5 Markov & CLV Backtest

import math
import pandas as pd

CL_URL = (
    "https://huggingface.co/datasets/aidancoit9203/"
    "tennis-betting-odds-closing-lines-dataset/resolve/main/"
    "tennis_h2h_closing_lines_30d.csv"
)

def bo3_to_bo5_prob(p_bo3: float) -> float:
    # Invert p_bo3 = s^2 * (3 - 2s) to find single-set win prob s
    lo, hi = 1e-4, 1.0 - 1e-4
    for _ in range(50):
        mid = 0.5 * (lo + hi)
        if mid * mid * (3.0 - 2.0 * mid) < p_bo3:
            lo = mid
        else:
            hi = mid
    s = 0.5 * (lo + hi)
    # Best-of-5 match win probability
    return (s ** 3) * (10.0 - 15.0 * s + 6.0 * s * s)

def surface_blended_elo_prob(elo_a: float, elo_b: float, s_elo_a: float, s_elo_b: float, w_surface: float = 0.35) -> float:
    p_all = 1.0 / (1.0 + 10.0 ** ((elo_b - elo_a) / 400.0))
    p_surf = 1.0 / (1.0 + 10.0 ** ((s_elo_b - s_elo_a) / 400.0))
    return (1.0 - w_surface) * p_all + w_surface * p_surf

df = pd.read_csv(CL_URL).dropna(subset=["elo_p1_win_prob", "open_p1_odds_mean", "close_p1_novig_prob", "player1_won"])

# Evaluate simulated strategy: bet Player 1 at opening mean whenever Elo prior beats opening implied prob by >= 4%
df["open_edge"] = df["elo_p1_win_prob"] - df["open_p1_novig_prob"]
df["clv_pct"] = (df["open_p1_odds_mean"] * df["close_p1_novig_prob"] - 1.0) * 100.0

signals = df[df["open_edge"] >= 0.04].copy()
signals["pnl_1u"] = signals.apply(
    lambda r: (r["open_p1_odds_mean"] - 1.0) if r["player1_won"] == 1 else -1.0,
    axis=1,
)

print(f"Signals: {len(signals)} | Mean CLV: {signals['clv_pct'].mean():+.2f}% | Flat 1u ROI: {signals['pnl_1u'].mean()*100:+.2f}%")
print("Example Bo3 -> Bo5 conversion (65% Bo3 favorite):", round(bo3_to_bo5_prob(0.65), 4))
Enter fullscreen mode Exit fullscreen mode

4. Fetching Live Player Elo, H2H & Odds History via REST API

import os
import requests

API_KEY = os.environ["CITO_API_KEY"]
BASE = "https://api.citoapi.com/api/v1/tennis"
HEADERS = {"x-api-key": API_KEY, "Accept": "application/json"}

# Upcoming ATP/WTA/Challenger/ITF odds
upcoming = requests.get(f"{BASE}/odds/upcoming", headers=HEADERS, params={"limit": 20}, timeout=15).json()
matches = upcoming.get("data", [])

for m in matches[:3]:
    mid = m["match_id"]
    p1 = m.get("player1_id")
    p2 = m.get("player2_id")
    hist = requests.get(f"{BASE}/odds/{mid}/history", headers=HEADERS, timeout=15).json().get("data", [])
    elo1 = requests.get(f"{BASE}/players/{p1}/elo", headers=HEADERS, timeout=15).json().get("data", {}) if p1 else {}
    print(f"{mid}: snapshots={len(hist)} | p1_elo={elo1}")
Enter fullscreen mode Exit fullscreen mode

Resources

Top comments (0)