Given a bank roll, a stake you have already bet and a potential pot of winnings, the Kelly Criterion should calculate for you the optimal amount you should bet to maximize your winnings in the long run.
So, here’s what looks like a trivial piece of code, but is actually quite powerful:
public class KellyEvaluator
{
private decimal proportion;
public KellyEvaluator(decimal proportion = 1.0M)
{
this.proportion = proportion;
}
public decimal MaxBankRoll(decimal bankRoll, decimal pot, decimal stake, decimal ourWinPercentage)
{
return bankRoll * MaxFraction(bankRoll, pot, stake, ourWinPercentage);
}
public decimal MaxNormalisedBankRoll(decimal bankRoll, decimal pot, decimal stake,
decimal ourWinPercentage, decimal meanWinPercentage)
{
return bankRoll *
MaxNormalisedFraction(bankRoll, pot, stake, ourWinPercentage, meanWinPercentage);
}
public decimal MaxNormalisedFraction(decimal bankRoll, decimal pot, decimal totalStaked,
decimal ourWinPercentage, decimal meanWinPercentage)
{
decimal f = 0.0M;
decimal proposedBet = bankRoll;
decimal max = 0.0M;
while (proposedBet > 0.0M)
{
f = NormalisedFraction
(bankRoll, pot – totalStaked, proposedBet, ourWinPercentage, meanWinPercentage);
if (f >= 0.0M)
max = f;
proposedBet -= 1.0M;
}
return max;
}
public decimal MaxFraction
(decimal bankRoll, decimal pot, decimal totalStaked, decimal ourWinPercentage)
{
decimal f = 0.0M;
decimal proposedBet = bankRoll;
decimal max = 0.0M;
while(proposedBet > 0.0M)
{
f = Fraction(bankRoll, pot – totalStaked, proposedBet, ourWinPercentage);
if (f >= 0.0M)
max = f;
proposedBet -= 1.0M;
}
return max;
}
private decimal NormalisedFraction(decimal bankRoll, decimal potentialWinnings, decimal ourStake,
decimal ourWinPercentage, decimal meanWinPercentage)
{
decimal delta = ourWinPercentage – meanWinPercentage;
decimal edgePercentage = delta / meanWinPercentage;
return Fraction(bankRoll, potentialWinnings, ourStake, edgePercentage);
}
private decimal Fraction(decimal bankRoll, decimal potentialWinnings,
decimal ourStake, decimal ourWinPercentage)
{
decimal b = potentialWinnings / (ourStake);
decimal f = ((b * ourWinPercentage) – (1 – ourWinPercentage)) / b;
return f * proportion;
}
}