Skip to content
ThatOneSharpDudePublic

About

Remove the bookmaker margin from 2-way and n-way odds: proportional, additive, power, Shin and odds-ratio methods. Pure Python, typed, tested.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

devig

CI

Remove the bookmaker margin from betting odds to recover implied fair probabilities. Pure Python, zero runtime dependencies, fully type-hinted, Python 3.10+.

Overround

A bookmaker's decimal odds d_i for a set of mutually exclusive, exhaustive outcomes imply raw probabilities q_i = 1 / d_i. Their sum is the booksum S = sum(q_i), and the overround (margin, vig) is S - 1. A fair market has S = 1; a quoted market normally has S > 1. "De-vigging" maps q to fair probabilities p with sum(p_i) = 1. The methods below differ in how the margin is assumed to be spread across outcomes, and there is no single correct answer: the true allocation is not observable from prices alone.

If S < 1 (an underround) there is no margin to remove and devig raises ValueError.

Methods

All formulas use q_i = 1 / d_i and S = sum(q_i).

proportional (multiplicative normalisation): p_i = q_i / S. Assumes the margin is proportional to each outcome's probability. The simplest and most common baseline.

additive: p_i = q_i - (S - 1) / n. Subtracts an equal margin from every outcome. Longshots can end up with a non-positive probability under a large margin, in which case devig raises ValueError.

power: p_i = q_i^k, with k >= 1 solving sum(q_i^k) = 1. Because k > 1 shrinks small probabilities proportionally more, it removes relatively more margin from longshots than proportional does. This is the usual motivation for power-style methods when a favourite-longshot bias is suspected (Clarke et al., 2017).

shin: Shin's model of a market with a fraction z of insider traders (Shin, 1993):

p_i = ( sqrt(z^2 + 4 (1 - z) q_i^2 / S) - z ) / ( 2 (1 - z) ),   z solves sum(p_i) = 1

z is interpreted as the proportion of insider money and is solved numerically. For two outcomes Shin's result coincides exactly with additive. Like power, it takes relatively more margin from longshots. Štrumbelj (2014) discusses Shin-based probabilities among approaches for extracting forecasts from odds.

odds_ratio: divides every outcome's odds by a common ratio c >= 1:

p_i / (1 - p_i) = ( q_i / (1 - q_i) ) / c   =>   p_i = q_i / ( q_i + c (1 - q_i) ),   c solves sum(p_i) = 1

Implied probabilities below 1e-150 (decimal odds above 1e150) are rejected as too extreme. Root finding is bisection (devig.solve), with TOLERANCE = 1e-14 and MAX_ITERATIONS = 200. Already-fair markets (|S - 1| <= 1e-12) are returned unchanged by every method.

Install

pip install git+https://github.com/ThatOneSharpDude/devig.git

or, from a clone, pip install -e ".[dev]".

Usage

Two-way American odds:

>>> from devig import devig, overround
>>> overround([-110, -110], odds_format="american")
0.04761904761904767
>>> devig([-110, -110], method="power", odds_format="american")
[0.5, 0.5]
>>> devig([-150, 130], method="additive", odds_format="american")  # favourite / underdog
[0.5826086956521739, 0.417391304347826]

Three-way decimal odds (e.g. home / draw / away):

>>> p = devig([2.10, 3.40, 3.60], method="power")
>>> round(sum(p), 12)
1.0
>>> devig([2.10, 3.40, 3.60], method="shin")
[0.4586657159613352, 0.27873763713279054, 0.26259664690587436]
>>> devig([2.10, 3.40, 3.60], method="proportional")
[0.45434298440979953, 0.2806236080178174, 0.2650334075723831]

Other helpers: american_to_decimal, decimal_to_american, implied_prob, and devig.METHODS (name to function mapping). Invalid input (odds <= 1.0, NaN, empty or single-outcome markets, underrounds) raises ValueError with an explanatory message.

Command line

python -m devig -110 -110 --format american --method power
method: power
outcome   fair prob  fair decimal  fair american
      1    0.500000        2.0000         +100.0
      2    0.500000        2.0000         +100.0

Options: --format {decimal,american} (default decimal) and --method {proportional,additive,power,shin,odds_ratio} (default power).

Development

pip install -e ".[dev]"
pytest
ruff check .

References

  • Shin, H. S. (1993). Measuring the incidence of insider trading in a market for state-contingent claims. The Economic Journal, 103(420).
  • Štrumbelj, E. (2014). On determining probability forecasts from betting odds. International Journal of Forecasting, 30(4).
  • Clarke, S., Kovalchik, S., & Ingram, M. (2017). Adjusting bookmaker's odds to allow for overround. American Journal of Sports Science, 5(6).

License

MIT

About

Remove the bookmaker margin from 2-way and n-way odds: proportional, additive, power, Shin and odds-ratio methods. Pure Python, typed, tested.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages