Open Source

The math is free — not as a slogan, as a package. Install it, read it, run it against your own numbers, and check every figure this site prints.

teachersbettextbook is an MIT-licensed Python library that implements the sports-betting mathematics behind Teacher’s Bet: American-moneyline conversions, three de-vig methods, expected value, single and simultaneous Kelly sizing, two-outcome arbitrage, Monte Carlo simulation, and Kalshi event-contract fee math. It is published on PyPI, has no web or data-feed dependencies, and runs offline.

Install it

pip install teachersbettextbook

One dependency (NumPy), Python 3.9 or newer, current version 0.2.0. No account, no key, no telemetry, nothing phones home.

Five lines that reproduce a number from this site

The expected value calculator ships with the market −140 / +120 and a price of +145 on the underdog. Here is that exact answer, computed locally — five lines and a print:

import teachersbettextbook as tb

p_a, p_b = tb.devig(-140, 120, method="power")   # fair probabilities, margin removed
b        = tb.moneyline_to_odds(145)             # +145 -> $1.45 profit per $1 risked
ev       = p_b * b - (1 - p_b)                   # expected value per $1 staked
stake    = tb.fractional_kelly(p_b, b) * 1000    # half-Kelly on a $1,000 bankroll

print(f"fair {p_b:.4%}  EV {ev:+.4%}  stake ${stake:,.2f}")
# fair 43.4435%  EV +6.4366%  stake $22.20

Those are the same digits the calculator prints and the same digits the API returns, because all three run the same arithmetic. If the numbers ever disagree, the site is wrong and you can prove it in five lines.

The honest zero, in code

>>> tb.kelly_fraction(0.40, 1.45)      # a 40% chance at +145 is below fair
-0.013793103448275834
>>> tb.fractional_kelly(0.40, 1.45)    # so the stake is clamped at zero
0.0
No edge in, zero out. The clamp lives in the library, not in a display layer, so nothing downstream can round a no-edge result up into a stake.

What is inside

ModuleWhat it computes
devigMoneyline ↔ implied probability and net odds, the overround, and fair-probability recovery three ways: proportional, power, and Shin. Also prob_to_decimal and prob_to_moneyline for the trip back.
kellyFull-Kelly fraction, fractional Kelly (half by default), the expected log-growth curve, and joint simultaneous Kelly across a slate of bets that settle together.
arbBest-price selection across books, the inverse-odds sum, the stake split that equalizes payouts, and the execution-risk warnings that come with it.
simulateMonte Carlo over repeated fractional-Kelly betting: bankroll paths, ruin frequency, and the distribution of ending bankrolls.
kalshiKalshi event-contract fees: taker and maker fee with the exchange’s round-up-to-the-cent rule, fee-adjusted break-even, fee as a share of outlay, and round trip vs. hold-to-settlement.

Every equation in all five modules is written out symbol by symbol on the formula sheet, with units and a worked number. The package ships the same list as FORMULAS.md.

The license

MIT. Copyright © 2026 Alex Thornton. Use it commercially, fork it, vendor it into a competing product, ship it inside something closed — the license asks for a copyright notice and nothing else. There is no non-commercial clause, no attribution-in-your-UI clause, and no field-of-use restriction.

The grant is irrevocable for every version already published. Nothing on this page is a promise about future releases beyond what the MIT text already gives you.

Where the code is

Read it without installing it

pip download teachersbettextbook --no-binary :all: --no-deps -d ./tb
tar -xzf ./tb/teachersbettextbook-*.tar.gz -C ./tb
ls ./tb/teachersbettextbook-*/src/teachersbettextbook/
# __init__.py  arb.py  devig.py  kalshi.py  kelly.py  simulate.py
Five modules, 531 lines of Python all in, plus the test suite, the examples and FORMULAS.md in the same archive. That is the entire mathematical claim of this site, and it is short enough to read in one sitting.

Tests, and why they are the interesting part

The suite covers known values, edge cases, and mathematical invariants — de-vigged probabilities summing to exactly 1, Kelly returning zero rather than a negative stake, the arbitrage split paying identically on both outcomes:

pip install "teachersbettextbook[test]"
pytest

Separately, the site’s edge runtime is JavaScript, not Python. That mirror is held to the Python implementation by golden-value tests: a fixed set of inputs, the Python outputs recorded to full precision, and a failing build if the JavaScript reproduces anything different. Parity is enforced by value, not by matching function names — the names differ between the two mirrors and always have.

What is deliberately not in here

This is the open half of the product, and the boundary is drawn on purpose rather than by neglect. Not included, and not planned:

What gets published is the result — the fair line, the confidence, the venue count, the timestamps — and never the internals that produced it. The redaction is enforced server-side, not in the browser. Methodology is the full account of what is and is not disclosed.

The dividing line is simple: textbook mathematics is open; fitted parameters are not. Every equation on the formula sheet is in the package. Nothing that was learned from market data is.

Why open it at all

Because the pitch is “you can check our math,” and that is an empty sentence if the math is a binary. Every competitor in this category is a black box; a de-vig you can read, run, and disagree with is the difference between a claim and an argument. A published, testable implementation also makes the site falsifiable in exactly the way an analytics tool should be.

It also means nothing here depends on trusting this site. If Teacher’s Bet went dark tomorrow, the arithmetic would still install.