Skip to content

Instantly share code, notes, and snippets.

@invkrh
Last active November 11, 2019 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save invkrh/49000105914d1fbd5d931c978796c849 to your computer and use it in GitHub Desktop.
Save invkrh/49000105914d1fbd5d931c978796c849 to your computer and use it in GitHub Desktop.
Useful code for calculate bet size
def kellyFactor(pWin: Double, odd: Double) = {
(pWin * odd - 1) / (odd - 1)
}
def betSize(
bankroll: Double,
minOdd: Double,
odd: Double) = {
val pWin = 1.02 / minOdd
val kf = kellyFactor(pWin, odd)
val left = (0.75 / 100 + kf * (odd / minOdd - 1)) / (odd - 1)
val right = 2d / 100 / (odd - 1)
// println(s"$left <> $right")
val size = math.min(left, right)
bankroll * size
}
Seq(3d -> 9.2, 3.1 -> 11d, 3.2 -> 14d, 3.3 -> 17d, 3.4 -> 20d).map {
case (odd, bet) =>
val newBet = betSize(2500d, 2.979, odd)
println(newBet -> bet)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment