Skip to main content

The open betting-math textbook: de-vig, +EV, arbitrage, Kelly sizing, and Kalshi fee math as a pure Python/NumPy library.

Project description

teachersbettextbook

The open betting-math textbook — the standard, teachable math behind sports-betting analytics, as a small, dependency-light Python/NumPy library.

It is the open half of Teacher's Bet: the same math the site shows its work with, extracted so you can import it, read it, and check it yourself. Every free lesson at teachersbet.com/learn is built on these functions.

Not betting advice. Every function is a calculation on the inputs you supply — not a prediction, pick, or direction to wager, and no guarantee of any outcome. For informational and educational use. You must be of legal age to gamble in your jurisdiction. Gamble responsibly — 1-800-GAMBLER.

Install

pip install teachersbettextbook

What's inside

Module What it does
devig moneyline ↔ implied probability / net odds, the vig, and fair-probability recovery — proportional, power, and Shin methods
kelly single-bet, fractional, and joint simultaneous Kelly sizing
arb two-outcome arbitrage detection and the stake split, with execution-risk caveats
simulate Monte Carlo of repeated fractional-Kelly bets
kalshi Kalshi event-contract fee math — taker/maker fee with the exchange's ceil-to-cent rounding, fee-adjusted break-even, fee as a share of outlay, round trip vs. hold-to-settlement

See FORMULAS.md for every equation, and the free guides at teachersbet.com/learn for the plain-language lessons.

Quick start

import teachersbettextbook as tb

# De-vig a two-sided moneyline into fair probabilities
tb.devig(-150, 130, method="shin")      # -> (p_a, p_b), summing to 1

# The book's margin (vig) baked into that line
tb.overround(-150, 130)                 # -> ~0.03

# Fractional Kelly stake for a 55% edge at even money (half-Kelly is the default)
tb.fractional_kelly(p=0.55, b=1.0)       # -> 0.05  (half of the full 0.10)

# Is there an arb across these books? How do you split the stake?
tb.find_arbitrage([
    {"book": "A", "ml_a": 110, "ml_b": -105},
    {"book": "B", "ml_a": -102, "ml_b": 115},
], total_stake=1000)                     # -> best prices, is_arb, stakes, return

# Kalshi: what a 100-contract taker fill at 50c really costs
tb.kalshi_fee(100, 0.50)                 # -> 1.75  (dollars; ceil-to-cent on the total)
tb.kalshi_breakeven(0.50)                # -> 0.5175  (price + fee, the true break-even)
tb.kalshi_fee_breakdown(100, 0.50)       # -> the whole worked cost, incl. round trip vs. hold

Worked examples

Runnable, step-by-step walkthroughs live in examples/ — one per topic, each printing the full calculation with labelled intermediate values:

python examples/devig_example.py       # strip the vig from a moneyline three ways
python examples/kelly_example.py       # f*, the growth curve, half-Kelly, joint sizing
python examples/arb_example.py         # detect a two-book arb and split the stake
python examples/simulate_example.py    # Monte Carlo a season of fractional-Kelly bets
python examples/utils_example.py       # moneyline ↔ probability / odds, vig, Kelly ratio

Tests

Every module has a comprehensive suite (known values, edge cases, and mathematical invariants) under tests/:

pip install teachersbettextbook[test]
pytest        # 160+ tests

Scope

This package is math only. It contains no web app, no odds-data feeds, no account or billing code, and none of the hosted service's proprietary sharp-consensus anchor detection. It reads and runs on its own, offline.

License

MIT. Copyright (c) 2026 Alex Thornton.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

teachersbettextbook-0.2.0.tar.gz (37.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

teachersbettextbook-0.2.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file teachersbettextbook-0.2.0.tar.gz.

File metadata

  • Download URL: teachersbettextbook-0.2.0.tar.gz
  • Upload date:
  • Size: 37.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for teachersbettextbook-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f415c797651e9509225d871361a56d90df3258fae65f4c973500932590eb0415
MD5 6db854537f958229f162493f061d5efa
BLAKE2b-256 ab20f4396297a9f12daf2239459ef8fa34e78452e929bc23a5d74b2abc45c0d4

See more details on using hashes here.

File details

Details for the file teachersbettextbook-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for teachersbettextbook-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec22c8b4fdd73e0e433a747c71e133058f138232d7d7b20d453937c94b188515
MD5 4f9fcc14e5ec04c9e1f0010fcd66761e
BLAKE2b-256 9bd7b3a9577e690a0aeac708039d5cdcb4b27f6a123810b1f29baa860c3fbb3b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page