Skip to main content

stakepd - pandas for betting
#

stakepd is a Python package that extends pandas with specialized tools for betting analytics. It provides custom DataFrame and Series methods as well as utilities for modeling, analyzing, and optimizing sports bets (or betting of any kind).

Features
#

  • Betting-specific DataFrame and Series extensions
  • Odds conversion and normalization
  • Betting optimization functionality
  • Integration with pandas workflows

Contents
#

  1. Installation
  2. Usage Examples
  3. Documentation
  4. Contact

Installation
#

Terminal:

pip install stakepd

Jupyter:

!pip install stakepd

Usage Examples
#

Example 1:

import pandas as pd
import stakepd as spd

# Example: Calculate implied probabilities from odds
odds = pd.Series([2.0, 3.5, 1.8]) # A pandas Series of decimal odds
implied_probability = odds.implied_probability() # Some stakepd methods work directly on pandas objects
print(implied_probability)
Output:
0    0.500000
1    0.285714
2    0.555556
dtype: float64

Example 2:

import pandas as pd
import stakepd as spd

# Example: Calculate the potential profit from a Series of bets
stakes = pd.Series([100, 50, 10]) # Series of betting stakes
odds = pd.Series([100, -200, 300]) # Series of American betting odds corresponding to stakes
payout = spd.profit(stakes, odds, 'american') # Some stakepd methods are called from spd module
print(payout)
Output:
0    100.0
1     25.0
2     30.0
dtype: float64

Documentation
#

pandas.Series.implied_probability
#

pandas.Series.implied_probability(odds_type = 'decimal')

Calculate the implied probability from a series of odds.

Parameters:

  • odds_type (str, optional): Type of odds provided. Supported values are 'decimal', 'fractional', and 'american'. Default is 'decimal'.

Returns:

  • pandas.Series: Series of implied probabilities as decimals (float).

Example:

odds = pd.Series([2.0, 3.5, 1.8])
implied_probabilities = odds.implied_probability()
print(implied_probabilities)
Output:
0    0.500000
1    0.285714
2    0.555556
dtype: float64

Example (fractional odds):

odds = pd.Series([1/4, 2/1, 10/2])
implied_probabilities = odds.implied_probability(odds_type = 'fractional')
print(implied_probabilities)
Output:
0    0.800000
1    0.333333
2    0.166667
dtype: float64

Example (american odds):

odds = pd.Series([100, -150, 200])
implied_probabilities = odds.implied_probability(odds_type = 'american')
print(implied_probabilities)
Output:
0    0.500000
1    0.600000
2    0.333333
dtype: float64

pandas.DataFrame.implied_probability
#

pandas.DataFrame.implied_probability(odds_type = 'decimal')

Calculate the implied probability from a DataFrame of odds.

Parameters:

  • odds_type (str, optional): Type of odds provided. Supported values are 'decimal', 'fractional', and 'american'. Default is 'decimal'.

Returns:

  • pandas.DataFrame: DataFrame of implied probabilities as decimals (float).

Example:

odds = pd.DataFrame({"A": [2.0, 1.5, 5.0], "B": [50, 8.0, 25.0]})
implied_probabilities = odds.implied_probability()
print(implied_probabilities)
Output:
   A_implied_probability  B_implied_probability
0               0.500000                  0.020
1               0.666667                  0.125
2               0.200000                  0.040

pandas.Series.odds
#

pandas.Series.odds(odds_type = 'decimal')

Convert implied probability to the specified odds type.

Parameters:

  • odds_type (str, optional): Type of odds provided. Supported values are 'decimal', 'fractional', and 'american'. Default is 'decimal'.

Returns:

  • pandas.Series: Series of float odds in odds_type format.

Example:

prob = pd.Series([0.5, 0.4])
odds_vals = prob.odds(odds_type = 'decimal')
print(odds_vals)
Output:
0    2.000000
1    2.500000
dtype: float64

pandas.DataFrame.odds
#

pandas.DataFrame.odds(odds_type : str = 'decimal')

Convert implied probability to the specified odds type.

Parameters:

  • odds_type (str, optional): Type of odds provided. Supported values are 'decimal', 'fractional', and 'american'. Default is 'decimal'.

Returns:

  • pandas.DataFrame: DataFrame of odds in odds_type format.

Example:

implied_probabilities = pd.DataFrame({"A": [0.5, 0.4], "B": [0.3, 0.2]})
odds_df = implied_probabilities.odds(odds_type = "decimal")
print(odds_df)
Output: 
   A_decimal_odds  B_decimal_odds
0             2.0        3.333333
1             2.5        5.000000

pandas.Series.convert
#

pandas.Series.convert(from_type, to_type)

Convert between types of odds or implied_probability

Parameters:

  • from_type (str): input type. Supported values are 'decimal', 'fractional', 'american' and 'implied_probability'.
  • to_type (str): output type. Supported values are 'decimal', 'fractional', 'american' and 'implied_probability'.

Returns:

  • pandas.Series: Series of floating point odds/implied probabilities in to_type format.

Example:

decimal_odds = pd.Series([2.0, 1.5, 3.0])
american_odds = decimal_odds.convert(from_type = 'decimal', to_type = 'american')
print(american_odds)
Output:
0    100.0000
1    -200.0000
2    200.0000
dtype: float64

pandas.DataFrame.convert
#

pandas.DataFrame.convert(from_type, to_type)

Convert between types of odds or implied_probability

Parameters:

  • from_type (str): input type. Supported values are 'decimal', 'fractional', 'american' and 'implied_probability'.
  • to_type (str): output type. Supported values are 'decimal', 'fractional', 'american' and 'implied_probability'.

Returns:

  • pandas.DataFrame: DataFrame of floating point odds/implied probabilities in to_type format.

Example:

decimal_odds = pd.DataFrame({"A": [2.0, 1.5, 5.0], "B": [50, 8.0, 25.0]})
american_odds = decimal_odds.convert(from_type="decimal", to_type="american")
print(american_odds)
Output:
   A_implied_probability_american_odds  B_implied_probability_american_odds
0                                100.0                               4900.0
1                               -200.0                                700.0
2                                400.0                               2400.0

pandas.Series.as_fraction
#

pandas.Series.as_fraction()

Convert fractional odds from floating point to fraction in string form

Returns:

  • pandas.Series: Series of fractional odds in string form.

Example:

fractional_odds = pd.Series([0.25, 0.5, 2.0, 1.0])
fraction_strings = fractional_odds.as_fraction()
print(fraction_strings)
Output:
0    1/4
1    1/2
2    2/1
3    1/1
dtype: object

pandas.Series.as_float
#

pandas.Series.as_float()

Convert fractional odds from fraction strings to floating point. Reverse of pandas.Series.as_fraction().

Returns:

  • pandas.Series: Series of fractional odds as floating point.

Example:

fractional_strings = pd.Series(["1/4", "1/2", "2/1"])
fraction_odds = fractional_strings.as_float()
print(fraction_odds)
Output:
0    0.25
1    0.50
2    2.00
dtype: float64

pandas.Series.overround
#

pandas.Series.overround(odds_type = 'implied_probability')

Calculate the overround of a Series of odds

Parameters:

  • odds_type (str, optional): Type of odds provided. Supported values are 'decimal', 'fractional', 'american', and 'implied_probability'. Default is 'implied_probability'.

Returns:

  • float: floating point overround as decimal

Example:

implied_odds = pd.Series([0.8, 0.5, 0.3])
overround_value = implied_odds.overround(odds_type = 'implied_probability')
print(overround_value)
Output:
np.float64(0.6000000000000000)

pandas.DataFrame.overround
#

pandas.DataFrame.overround(odds_type = 'implied_probability')

Calculate the overrounds of a DataFrame of odds

Parameters:

  • odds_type (str, optional): Type of odds provided. Supported values are 'decimal', 'fractional', 'american', and 'implied_probability'. Default is 'implied_probability'.

Returns:

  • pandas.Series: Series of overrounds as decimal corresponding to the indexes of the input DataFrame

Example:

implied_odds = pd.DataFrame({"A": [0.8, 0.5], "B": [0.3, 0.7]})
overround_value = implied_odds.overround(odds_type = 'implied_probability')
print(overround_value)
Output:
0    0.1
1    0.2

pandas.Series.vig
#

pandas.Series.vig(odds_type = 'implied_probability')

Calculate the vigourish or juice of a Series of odds

Parameters:

  • odds_type (str, optional): Type of odds provided. Supported values are 'decimal', 'fractional', 'american', and 'implied_probability'. Default is 'implied_probability'.

Returns:

  • float: floating point vigourish as decimal

Example:

decimal_odds = pd.Series([2.0, 1.5, 3.0])
vig_value = decimal_odds.vig(odds_type = 'decimal')
print(vig_value)
Output:
np.float64(0.3333333333)

pandas.DataFrame.vig
#

pandas.DataFrame.vig(odds_type = 'implied_probability')

Calculate the vigourish values or juice values of a DataFrame of odds

Parameters:

  • odds_type (str, optional): Type of odds provided. Supported values are 'decimal', 'fractional', 'american', and 'implied_probability'. Default is 'implied_probability'.

Returns:

  • pd.Series: Series of vigourish values corresponding to the indexes of the input Dataframe

Example:

implied_probs = pd.DataFrame({"A": [0.8, 0.5], "B": [0.3, 0.7]})
vig_values = decimal_probs.vig()
print(vig_values)
Output:
0    0.090909
1    0.166667
dtype: float64

pandas.Series.devig
#

pandas.Series.devig()

Calculate devigged implied probabilities from a Series of implied probabilities with vigrourish

Returns:

  • pandas.Series: Series of devigged decimal implied probabilities as floating point values

Example:

implied_probabilities = pd.Series([0.8, 0.5, 0.3])
devigged_probs = implied_probabilities.devig()
print(devigged_probs)
Output:
0    0.5000
1    0.3125
2    0.1875
dtype: float64

pandas.DataFrame.devig
#

pandas.DataFrame.devig()

Calculate devigged implied probabilities from a DataFrame of implied probabilities with vigrourish. Input df has each row as a set of vigged implied probabilities

Returns:

  • pandas.DataFrame: DataFrame of devigged decimal implied probabilities as floating point values. Each row corresponds to a row in the input DataFrame.

Example:

implied_probabilities = pd.DataFrame({
            "A": [0.8, 0.5],
            "B": [0.3, 0.7]
        })
devigged_probs = implied_probabilities.devig()
print(devigged_probs)
Output:
          A         B
0  0.727273  0.272727
1  0.416667  0.583333

stakepd.payout(stakes, odds, odds_type)
#

spd.payout(stakes, odds, odds_type)

Calculates payout from a bet or payouts from a Series of bets

Parameters:

  • stakes (float, int or pandas.Series): scalar or Series of stake/bet values.
  • odds (float, int or pandas.Series): scalar or Series of odds in odds_type format. Must be scalar if stakes is scalar, or must be Series if stakes is Series (must be same length)
  • odds_type (str): Type of odds provided. Supported values are 'decimal', 'fractional', 'american', and 'implied_probability'

Returns:

  • float: payout of bet as a floating point number OR
  • pands.Series: Series of payouts with same length as stakes and odds

Example (Scalar):

stakes = 100
odds = 2
payouts = spd.payout(stakes, odds, 'decimal')
print(payouts)
Output: 
200

Example (Series):

stakes = pd.Series([100, 50, 10])
odds = pd.Series([2.0, 3.0, 1.5])
payouts = spd.payout(stakes, odds, 'decimal')
print(payouts)
Output: 
0    200.0
1    150.0
2     15.0
dtype: float64

stakepd.profit(stakes, odds, odds_type)
#

spd.profit(stakes, odds, odds_type)

Calculates the profits from a bet or a Series of bets. Profit = Payout - Stake.

Parameters:

  • stakes (float, int or pandas.Series): scalar or Series of stake/bet values.
  • odds (float, int or pandas.Series): scalar or Series of odds in odds_type format. Must be scalar if stakes is scalar, or must be Series if stakes is Series (must be same length)
  • odds_type (str): Type of odds provided. Supported values are 'decimal', 'fractional', 'american', and 'implied_probability'

Returns:

  • float: profit of bet as a floating point number OR
  • pands.Series: Series of profit values with same length as stakes and odds

Example (Scalar):

stakes = 100
odds = 2
profits = spd.profit(stakes, odds, 'decimal')
print(profits)
Output: 
100

Example (Series):

stakes = pd.Series([100, 50, 10])
odds = pd.Series([2.0, 3.0, 1.5])
profits = spd.profit(stakes, odds, 'decimal')
print(profits)
Output: 
0    100.0
1    100.0
2      5.0
dtype: float64

stakepd.kelly_criterion(odds, true_probability, odds_type, bank_roll, kelly_percentage)
#

Calculate the amount to bet on an EV bet according to the kelly criterion formula.

Parameters:

  • odds (float, int or pandas.Series): scalar or Series of odds in odds_type format. Must be scalar if true_probability is scalar, or must be Series if true_probability is Series (must be same length)
  • true_probability (float or pandas.Series): scalar or Series of estimated ’true’ probabilities of events.
  • odds_type (str): Type of odds provided. Supported values are 'decimal', 'fractional', or 'american'
  • bank_roll (float, optional): The amount of bankroll available for making bets with. Default of 100.0.
  • kelly_percentage (float, optional): Kelly percentage as a decimal which can be adjusted for fractional kelly bets. Default of 1.0.

Returns:

  • float: amount that should be wagered according to Kelly Criterion, OR
  • pands.Series: Series of kelly wager values with same length as true_probability and odds

Example:

bankroll = 100
odds = pd.Series([2.0, 3.0])
probabilities = pd.Series([0.4, 0.3])
wagers = spd.kelly_criterion(odds, probabilities, 'decimal', bankroll)
print(wagers)
Output:
result
0    0.0
1    0.0
dtype: float64

0.0 means that you shouldn’t make the bet.

Example:

bankroll = 1000
odds = pd.Series([2.0, 3.0, 1.5])
probabilities = pd.Series([0.6, 0.4, 0.7])
wagers = spd.kelly_criterion(odds, probabilities, 'decimal', bankroll)
print(wagers)
Output:
0    200.0
1    100.0
2    100.0
dtype: float64

Contact
#

For any enquiries related ads, software bugs, or anything else, please email bhatwadekarenterprises@gmail.com.