Skip to content

Instantly share code, notes, and snippets.

@thepycoach
Last active September 22, 2022 20:06
Show Gist options
  • Select an option

  • Save thepycoach/399c022f0d35bf0d5f8ae758ce2ef70d to your computer and use it in GitHub Desktop.

Select an option

Save thepycoach/399c022f0d35bf0d5f8ae758ce2ef70d to your computer and use it in GitHub Desktop.
from sympy import symbols, Eq, solve
def beat_bookies(odds1, odds2, total_stake):
x, y = symbols('x y')
eq1 = Eq(x + y - total_stake, 0) # total_stake = x + y
eq2 = Eq((odds2*y) - odds1*x, 0) # odds1*x = odds2*y
stakes = solve((eq1,eq2), (x, y))
total_investment = stakes[x] + stakes[y]
profit1 = odds1*stakes[x] - total_stake
profit2 = odds2*stakes[y] - total_stake
benefit1 = f'{profit1 / total_investment * 100:.2f}%'
benefit2 = f'{profit2 / total_investment * 100:.2f}%'
dict_gabmling = {'Stake1':stakes[x], 'Stake2':stakes[y], 'Profit1':profit1, 'Profit2':profit2,
'Benefit1': benefit1, 'Benefit2': benefit2}
return dict_gabmling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment