-
Notifications
You must be signed in to change notification settings - Fork 61
/
sports_betting.py
70 lines (60 loc) · 2.12 KB
/
sports_betting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#####################################################
# A sports betting script written in python.
# What the script handles:
#
# American odds formula:
# Decimal odds formula:
# Percentage odds formula:
# Implied probability formula:
# + 1P = 100 / (odd + 100)
# - 1P = (-1 x odd) / ((-1 x odd) + 100)
#
#
# By Doug Purcell
# https://www.purcellconsult.com
#
#
#####################################################
from fractions import Fraction
def odds_calculator(american_odds, amount=100):
"""provides the amount to win and the payout."""
if american_odds > 0:
fractional_odds = Fraction(american_odds, 100)
to_win = float(fractional_odds * amount)
payout = float(to_win + amount)
decimal_odds = 1 + fractional_odds
decimal_odds = float(decimal_odds)
implied_prob = round(100 / (american_odds + 100), 3)
implied_prob *= 100
print('-----------------------')
print(
f'To win: {to_win} \n'
f'Payout: {payout} \n'
f'American odds: {american_odds} \n'
f'Fractional odds: {fractional_odds} \n'
f'Decimal odds: {decimal_odds} \n'
f'Implied probability: {implied_prob} '
)
else:
american_odds = (american_odds)
fractional_odds = abs(Fraction(100, american_odds))
to_win = int(amount * fractional_odds)
payout = int(to_win + amount)
decimal_odds = 1 + fractional_odds
implied_prob = (-1 * american_odds)
implied_prob = round(implied_prob / ((-1 * american_odds) + 100),3)
implied_prob *= 100
print(
f'To win: {to_win} \n'
f'Payout: {payout} \n'
f'American odds: {american_odds} \n'
f'Fractional odds: {fractional_odds} \n'
f'Decimal odds: {decimal_odds} \n'
f'Implied probability: {implied_prob} '
)
if __name__ == '__main__':
print('Welcome to the odds calculator: ')
odds = int(input('Enter the odds '))
wager = int(input('Enter wager (bet amount)'))
print(f'Bet {wager}')
odds_calculator(odds, wager)