Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.9 kB
2
Indexable
Never
    
public static double CalculateHorseRaceEV(
        double backOdds, // Decimal odds for the horse to win
        double top3Odds, // Decimal odds for the horse to finish in the top 3
        double stake, // The stake amount
        double layOdds, // Decimal odds for laying the horse
        double commissionRate, // The commission rate for winning lay bets
        double underlayFactor // Underlay factor (1 for normal laying, < 1 for underlaying)
    )
    {
        // Calculate the probabilities from the odds
        double probabilityWin = 1 / backOdds;
        double probabilityTop3 = 1 / top3Odds;
        double probability2ndOr3rd = probabilityTop3 - probabilityWin;
        double probabilityLose = 1 - probabilityTop3;
    
        // Calculate the potential returns
        double payoutWin = stake * (backOdds - 1);
        double bonus = stake * 0.8;
        double loss = -stake;
    
        // Calculate the lay stake, adjust for underlaying
        double layStake = (underlayFactor * stake * (backOdds - 1)) / (layOdds - commissionRate);
    
        // Calculate the returns for lay bet
        double layWinProfit = layStake * (1 - commissionRate);
        double layLoss = -layStake * (layOdds - 1);
    
        // Calculate the EV considering the lay and back bets
        double ev = (probabilityWin * (payoutWin - layLoss)) +
                    (probability2ndOr3rd * (bonus - layLoss)) +
                    (probabilityLose * (loss + layWinProfit));
    
        return ev;
    }
    
    // Example usage:
    // backOdds: 5.0 (4/1 in fractional odds)
    // top3Odds: 1.5 (1/2 in fractional odds)
    // stake: 50.0
    // layOdds: 5.2
    // commissionRate: 0.05 (5%)
    // underlayFactor: 0.95 (5% underlay)
    double expectedValue = CalculateHorseRaceEV(5.0, 1.5, 50.0, 5.2, 0.05, 0.95);
    
    Console.WriteLine($"The expected value of the bet is: {expectedValue}");