Untitled

mail@pastecode.io avatar
unknown
csharp
7 months ago
1.4 kB
7
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;
}