Skip to main content

Variable: oddsMath

const oddsMath: object

Defined in: src/odds/math.ts:399

Every odds math function under both its sdv-py snake_case name and a camelCase alias; spread onto sdv.odds by src/index.ts.

Type Declaration​

devig_multiplicative​

devig_multiplicative: (p_raw) => number[]

Vig removal by normalizing raw implied probabilities to sum to 1, order preserved (py devig_multiplicative).

Parameters​

p_raw​

readonly number[]

Raw implied probabilities of every outcome of one market (e.g. from prob_from_american). An empty array returns an empty array.

Returns​

number[]

A new array, p_raw[i] / sum(p_raw) for each outcome.

Throws​

OddsZeroDivisionError When p_raw is non-empty and sums to 0.

Remarks​

The sum is Python 3.12+ compensated (Neumaier) summation, so results match sdv-py's sum() to ~1e-12. NaN inputs propagate NaN.

Example​

import sdv from 'sportsdataverse';
sdv.odds.devig_multiplicative([0.6, 0.4347826086956522]); // [0.5798..., 0.4201...]

devig_shin​

devig_shin: (p_raw) => number[]

Vig removal with Shin's (1993) insider-trading method (py devig_shin).

Solves for the insider share z at which the Shin probabilities sum to 1 (a port of scipy's brentq on [0, 1 - 1e-9], xtol = 1e-12), then renormalizes.

Parameters​

p_raw​

readonly number[]

Raw implied probabilities of every outcome of one market.

Returns​

number[]

A new array of devigged probabilities in p_raw order, summing to 1.

Throws​

OddsZeroDivisionError When the booksum is <= 1 and the multiplicative fallback divides by a zero sum (non-empty p_raw).

Throws​

OddsRuntimeError When the root solver does not converge in 100 iterations.

Remarks​

With booksum (overround) <= 1 this reduces to devig_multiplicative. If the solver cannot bracket a root (or hits a NaN) it warns Shin solver failed to bracket (...) (a Node process warning named SdvWarning, console.warn elsewhere) once per distinct message per process and falls back to the multiplicative method, as sdv-py warns.

Example​

import sdv from 'sportsdataverse';
sdv.odds.devig_shin([0.6, 0.4347826086956522]); // [0.58..., 0.41...], sums to 1

devigMultiplicative​

devigMultiplicative: (p_raw) => number[] = devig_multiplicative

Vig removal by normalizing raw implied probabilities to sum to 1, order preserved (py devig_multiplicative).

Parameters​

p_raw​

readonly number[]

Raw implied probabilities of every outcome of one market (e.g. from prob_from_american). An empty array returns an empty array.

Returns​

number[]

A new array, p_raw[i] / sum(p_raw) for each outcome.

Throws​

OddsZeroDivisionError When p_raw is non-empty and sums to 0.

Remarks​

The sum is Python 3.12+ compensated (Neumaier) summation, so results match sdv-py's sum() to ~1e-12. NaN inputs propagate NaN.

Example​

import sdv from 'sportsdataverse';
sdv.odds.devig_multiplicative([0.6, 0.4347826086956522]); // [0.5798..., 0.4201...]

devigShin​

devigShin: (p_raw) => number[] = devig_shin

Vig removal with Shin's (1993) insider-trading method (py devig_shin).

Solves for the insider share z at which the Shin probabilities sum to 1 (a port of scipy's brentq on [0, 1 - 1e-9], xtol = 1e-12), then renormalizes.

Parameters​

p_raw​

readonly number[]

Raw implied probabilities of every outcome of one market.

Returns​

number[]

A new array of devigged probabilities in p_raw order, summing to 1.

Throws​

OddsZeroDivisionError When the booksum is <= 1 and the multiplicative fallback divides by a zero sum (non-empty p_raw).

Throws​

OddsRuntimeError When the root solver does not converge in 100 iterations.

Remarks​

With booksum (overround) <= 1 this reduces to devig_multiplicative. If the solver cannot bracket a root (or hits a NaN) it warns Shin solver failed to bracket (...) (a Node process warning named SdvWarning, console.warn elsewhere) once per distinct message per process and falls back to the multiplicative method, as sdv-py warns.

Example​

import sdv from 'sportsdataverse';
sdv.odds.devig_shin([0.6, 0.4347826086956522]); // [0.58..., 0.41...], sums to 1

logit_blend​

logit_blend: (p_a, p_b, weight_a) => number

Blend two probabilities in logit space, nfelo's 70/30 practice (py logit_blend).

Parameters​

p_a​

number

First probability, strictly inside (0, 1).

p_b​

number

Second probability, strictly inside (0, 1).

weight_a?​

number = 0.7

Weight on p_a's logit; p_b gets 1 - weight_a. Default 0.7.

Returns​

number

sigmoid(weight_a * logit(p_a) + (1 - weight_a) * logit(p_b)).

Throws​

OddsZeroDivisionError When p_a or p_b is exactly 1 (odds ratio divides by 0).

Throws​

OddsValueError When an odds ratio is <= 0 (a probability <= 0 or > 1), Python's math domain error.

Throws​

OddsOverflowError When exp(-logit) overflows to Infinity from a finite blended logit, Python's math range error.

Remarks​

Error triggers mirror CPython's math.log / math.exp; NaN propagates.

Example​

import sdv from 'sportsdataverse';
sdv.odds.logit_blend(0.6, 0.5); // 0.5705...
sdv.odds.logit_blend(0.6, 0.5, 0.5); // equal weights

logitBlend​

logitBlend: (p_a, p_b, weight_a) => number = logit_blend

Blend two probabilities in logit space, nfelo's 70/30 practice (py logit_blend).

Parameters​

p_a​

number

First probability, strictly inside (0, 1).

p_b​

number

Second probability, strictly inside (0, 1).

weight_a?​

number = 0.7

Weight on p_a's logit; p_b gets 1 - weight_a. Default 0.7.

Returns​

number

sigmoid(weight_a * logit(p_a) + (1 - weight_a) * logit(p_b)).

Throws​

OddsZeroDivisionError When p_a or p_b is exactly 1 (odds ratio divides by 0).

Throws​

OddsValueError When an odds ratio is <= 0 (a probability <= 0 or > 1), Python's math domain error.

Throws​

OddsOverflowError When exp(-logit) overflows to Infinity from a finite blended logit, Python's math range error.

Remarks​

Error triggers mirror CPython's math.log / math.exp; NaN propagates.

Example​

import sdv from 'sportsdataverse';
sdv.odds.logit_blend(0.6, 0.5); // 0.5705...
sdv.odds.logit_blend(0.6, 0.5, 0.5); // equal weights

moneyline_pair_prob​

moneyline_pair_prob: (home_price, away_price, method) => number

Vig-removed HOME win probability from a two-way American moneyline pair (py moneyline_pair_prob).

Parameters​

home_price​

number

Home American price (non-zero).

away_price​

number

Away American price (non-zero).

method?​

string = 'multiplicative'

Devig method: 'multiplicative' (default, devig_multiplicative) or 'shin' (devig_shin).

Returns​

number

The home outcome's devigged probability (element 0 of the devigged pair).

Throws​

OddsValueError When either price is 0, or method is not one of the two names.

Throws​

OddsZeroDivisionError When the raw pair sums to 0 (via the devig).

Throws​

OddsRuntimeError When method === 'shin' and the solver fails to converge.

Remarks​

'shin' may emit the once-per-process Shin fallback warning (see devig_shin).

Example​

import sdv from 'sportsdataverse';
sdv.odds.moneyline_pair_prob(-150, 130); // 0.5798...
sdv.odds.moneyline_pair_prob(-150, 130, 'shin'); // Shin-devigged

moneylinePairProb​

moneylinePairProb: (home_price, away_price, method) => number = moneyline_pair_prob

Vig-removed HOME win probability from a two-way American moneyline pair (py moneyline_pair_prob).

Parameters​

home_price​

number

Home American price (non-zero).

away_price​

number

Away American price (non-zero).

method?​

string = 'multiplicative'

Devig method: 'multiplicative' (default, devig_multiplicative) or 'shin' (devig_shin).

Returns​

number

The home outcome's devigged probability (element 0 of the devigged pair).

Throws​

OddsValueError When either price is 0, or method is not one of the two names.

Throws​

OddsZeroDivisionError When the raw pair sums to 0 (via the devig).

Throws​

OddsRuntimeError When method === 'shin' and the solver fails to converge.

Remarks​

'shin' may emit the once-per-process Shin fallback warning (see devig_shin).

Example​

import sdv from 'sportsdataverse';
sdv.odds.moneyline_pair_prob(-150, 130); // 0.5798...
sdv.odds.moneyline_pair_prob(-150, 130, 'shin'); // Shin-devigged

prob_from_american​

prob_from_american: (price) => number

Raw (vig-included) implied probability of an American moneyline price (py prob_from_american).

Parameters​

price​

number

American price: negative for a favourite (-150 -> 0.6), positive for an underdog (+130 -> 100 / 230). Must not be 0.

Returns​

number

The implied probability in (0, 1): -p / (-p + 100) for p < 0, else 100 / (p + 100).

Throws​

OddsValueError When price is 0.

Remarks​

Not devigged; pass the raw pair through devig_multiplicative / devig_shin or use moneyline_pair_prob. A NaN price propagates NaN.

Example​

import sdv from 'sportsdataverse';
sdv.odds.prob_from_american(-150); // 0.6
sdv.odds.probFromAmerican(130); // 0.4347826...

prob_from_decimal​

prob_from_decimal: (price) => number

Raw (vig-included) implied probability of a decimal price (py prob_from_decimal).

Parameters​

price​

number

Decimal (European) price; must be strictly greater than 1.

Returns​

number

1 / price.

Throws​

OddsValueError When price <= 1.

Remarks​

A NaN price is not rejected by the <= 1 check and yields NaN.

Example​

import sdv from 'sportsdataverse';
sdv.odds.prob_from_decimal(2.5); // 0.4

probFromAmerican​

probFromAmerican: (price) => number = prob_from_american

Raw (vig-included) implied probability of an American moneyline price (py prob_from_american).

Parameters​

price​

number

American price: negative for a favourite (-150 -> 0.6), positive for an underdog (+130 -> 100 / 230). Must not be 0.

Returns​

number

The implied probability in (0, 1): -p / (-p + 100) for p < 0, else 100 / (p + 100).

Throws​

OddsValueError When price is 0.

Remarks​

Not devigged; pass the raw pair through devig_multiplicative / devig_shin or use moneyline_pair_prob. A NaN price propagates NaN.

Example​

import sdv from 'sportsdataverse';
sdv.odds.prob_from_american(-150); // 0.6
sdv.odds.probFromAmerican(130); // 0.4347826...

probFromDecimal​

probFromDecimal: (price) => number = prob_from_decimal

Raw (vig-included) implied probability of a decimal price (py prob_from_decimal).

Parameters​

price​

number

Decimal (European) price; must be strictly greater than 1.

Returns​

number

1 / price.

Throws​

OddsValueError When price <= 1.

Remarks​

A NaN price is not rejected by the <= 1 check and yields NaN.

Example​

import sdv from 'sportsdataverse';
sdv.odds.prob_from_decimal(2.5); // 0.4

spread_to_prob​

spread_to_prob: (spread, sigma) => number

Home win probability from a point spread: Phi(spread / sigma) (py spread_to_prob).

Parameters​

spread​

number

Expected HOME margin in points; positive = home favoured (the negative of the quoted home line).

sigma​

number

Standard deviation of the margin in points; must not be 0.

Returns​

number

The standard-normal CDF of spread / sigma, a HOME win probability in [0, 1].

Throws​

OddsZeroDivisionError When sigma is 0.

Remarks​

The CDF is the Hart 1968 / West 2005 double-precision algorithm (~1e-15). NaN propagates; |x| > 37 saturates to exactly 0 / 1.

Example​

import sdv from 'sportsdataverse';
sdv.odds.spread_to_prob(3, 13.5); // 0.5878...

spreadToProb​

spreadToProb: (spread, sigma) => number = spread_to_prob

Home win probability from a point spread: Phi(spread / sigma) (py spread_to_prob).

Parameters​

spread​

number

Expected HOME margin in points; positive = home favoured (the negative of the quoted home line).

sigma​

number

Standard deviation of the margin in points; must not be 0.

Returns​

number

The standard-normal CDF of spread / sigma, a HOME win probability in [0, 1].

Throws​

OddsZeroDivisionError When sigma is 0.

Remarks​

The CDF is the Hart 1968 / West 2005 double-precision algorithm (~1e-15). NaN propagates; |x| > 37 saturates to exactly 0 / 1.

Example​

import sdv from 'sportsdataverse';
sdv.odds.spread_to_prob(3, 13.5); // 0.5878...

Remarks​

Pure functions, no I/O; each alias is the same function object as its snake_case original.