Skip to main content

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 in both of its measures (overround in probability points, hold in dollars), and fair-probability recovery: proportional, power, and Shin methods
odds every notation one price can be written in (American, decimal, fractional, percent, contract cents), the exact continued-fraction reduction, and what a stake pays: profit, total return, and the vig-free payout beside it
kelly single-bet, fractional, and joint simultaneous Kelly sizing
arb two-outcome arbitrage detection and the stake split, with execution-risk caveats
middle two opposite-side prices at different numbers: sigma - 1 as the required hit rate, the equal-payout split, and the three-cell payoff grid
hedge sizing a hedge on a position you hold (H = S·d1/d2, the total return and not the profit), and what buying the certainty costs in expected value
teaser the per-leg break-even a teaser price implies, what the bought points have to be worth, and the payout given up against the same legs parlayed straight
roundrobin every combination of a set of legs, the total risk (the stake is per ticket), and an exact hit-level table from enumerating all 2^n outcomes
breakeven the win rate a price needs, and whether a settled record separates from it: Wilson score interval, one-sample proportion test, and the sample size an edge needs
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

Where a calculation has one headline number, the function returns it (teaser_breakeven, required_hit_rate, kalshi_fee). Where the point is the whole derivation, a *_breakdown function returns every intermediate value in one dict.

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

# One price, written every way, and what $100 does at it
tb.convert_price("10/11", "fractional")  # -> -110 American, 1.909 decimal, 52.38%, 52.4c
tb.payout(100, -110, other=-105)         # -> profit, total return, and the vig-free payout

# Hedge a $100 bet taken at +150, now that the other side is -130
tb.hedge_stake(100, 150, -130)           # -> 141.30  (S·d1/d2: the TOTAL return, not the profit)

# A middle: how often does the window have to land to break even?
tb.required_hit_rate(-110, -110)         # -> 0.0476  (sigma - 1, the overround on the pair)

# What a two-team six-point tease needs from its points
tb.teaser_breakeven(-120, 2)             # -> 0.7385 per leg
tb.points_needed(-120, 2, -110)          # -> 0.2147 probability per leg

# Does 55 of 100 at -110 prove anything yet? (No.)
tb.breakeven_win_rate(-110)              # -> 0.5238
tb.breakeven_breakdown(-110, bets=100, wins=55)   # -> z = 0.52, p = 0.60, 45.2% to 64.4%

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/odds_example.py        # one price in five notations, and what it pays
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/hedge_example.py       # size a hedge, price the certainty, read a middle
python examples/multileg_example.py    # teaser points and round-robin tickets
python examples/breakeven_example.py   # the rate a price needs, and what a record proves
python examples/simulate_example.py    # Monte Carlo a season of fractional-Kelly bets
python examples/kalshi_example.py      # what a Kalshi fill costs, and why holding is cheaper

Tests

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

pip install teachersbettextbook[test]
pytest        # 230+ 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 Escapement Technologies LLC.

Metadata

Release files for teachersbettextbook 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for teachersbettextbook 0.4.0
File Size Uploaded Provenance
teachersbettextbook-0.4.0.tar.gz 70.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for teachersbettextbook 0.4.0
File Interpreter ABI Platform
teachersbettextbook-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 103.3 kB

Release files / teachersbettextbook-0.4.0.tar.gz

Download URL teachersbettextbook-0.4.0.tar.gz
Size 70.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e12764ac952b09903f3e815cb0b0ee8e647d25047ceffd48c8e6c0702832c360
BLAKE2b-256 checksum
How to use checksums
184f0020e355db3178815243ec7ef7691189877a760b59e4ff1e3d1a8abdccba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.5

Release files / teachersbettextbook-0.4.0-py3-none-any.whl

Download URL teachersbettextbook-0.4.0-py3-none-any.whl
Size 32.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c77a6338a4e9667c11bf62e7bd141feab8606ff4a61deb4745e219f7d7e7d855
BLAKE2b-256 checksum
How to use checksums
ea27a5d452b0f6ff9e2719f2b8728be6594654623f23451870c737b6cd954fd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.5

Security for teachersbettextbook 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page