A simple and efficient Python function that calculates the optimal bet size using the Kelly Criterion formula.
This helps bettors or investors determine the ideal percentage of their bankroll to stake on an opportunity based on the odds and probability of success.
The Kelly Criterion is a mathematical formula used to determine the optimal fraction of your bankroll to wager:
[ f^* = \frac{bp - q}{b} ]
Where:
- f* = fraction of your bankroll to bet
- b = decimal odds - 1
- p = probability of winning
- q = probability of losing = 1 - p
In this script, the final bet amount is scaled by the user’s available bankroll (amt).
def cal(odd, pba, amt):
odd = float(odd)
pba = float(pba)
odd -= 1 # Convert to profit-based odds
proba = round(pba / 100, 4)
loss = 1 - proba
if odd == 0:
return 0
f = round((((odd * proba) - (loss)) / odd) * amt)
return f
🧩 Parameters
Parameter Type Description
odd float Decimal odds of the bet (e.g. 2.5)
pba float Win probability (in percentage, e.g. 55 for 55%)
amt float Total bankroll amount
💻 Example Usage
from kelly import cal
odd = 2.0 # Betting odds
pba = 55 # 55% probability of winning
amt = 1000 # Total bankroll in naira
bet_size = cal(odd, pba, amt)
print("Recommended Bet:", bet_size)
🧾 Output
Recommended Bet: 100
(This means you should bet ₦100 from a ₦1000 bankroll.)
💡 Example Use Case
This function can be integrated into:
Automated football betting bots
Investment position sizing tools
Risk management systems
Portfolio optimization algorithms
🧰 Tech Stack
Python 3
Built-in math (no external libraries required)
👨💻 Author
Ezee Kits
Focused on Python automation, data analysis, and intelligent betting systems.
📺 YouTube: Ezee Kits
📄 License
This project is licensed under the MIT License — you are free to use, modify, and share with proper credit.