Simulate Bets
def get_ml_bet_winnings(ml_odds, bet_amount): | |
if ml_odds < 0: | |
returns = (-100.0 / ml_odds) * bet_amount | |
else: | |
returns = (bet_amount / 100.0) * ml_odds | |
return returns |
# Function that simulates a betting strategy | |
def simulate_bets(dataset_df=df_pin, bet_amount=100, win_prob_threshold=0.5): | |
total_profit = 0 | |
all_winnings = [] | |
running_profits = [] | |
df_generator = dataset_df.iterrows() | |
for (i, row1), (j, row2) in zip(df_generator, df_generator): | |
### 1. Determine who to bet on for this game | |
t1_ml = row1['ml_PIN'] | |
t2_ml = row2['ml_PIN'] | |
t1_score = row1['score'] | |
t2_score = row2['score'] | |
t1_win_prob = row1['win_prob_norm_PIN'] | |
t2_win_prob = row2['win_prob_norm_PIN'] | |
# If any odds are missing, just skip the game | |
if pd.isnull(t1_ml) or pd.isnull(t2_ml): | |
continue | |
if t1_win_prob < win_prob_threshold: | |
placed_bet_on = 1 | |
bet_ml = t1_ml | |
elif t2_win_prob <= win_prob_threshold: | |
placed_bet_on = 2 | |
bet_ml = t2_ml | |
else: | |
# Not a favorable bet. Skip to next game | |
continue | |
### 2. Deterimine if we won or lost this bet | |
if t1_score > t2_score: | |
game_winner = 1 | |
elif t2_score > t1_score: | |
game_winner = 2 | |
else: | |
# Throw out any games missing scores (shouldn't be any) | |
continue | |
is_win = game_winner == placed_bet_on | |
### 3. Calculate winnings from this bet | |
# If favorite lost, then deduct bet from net profits | |
if is_win is False: | |
winnings = -bet_amount | |
# If favorite won, then add winnings to net profits | |
if is_win is True: | |
winnings = get_ml_bet_winnings(bet_ml, bet_amount) | |
### 4. Record winnings and update total profits | |
total_profit += winnings | |
all_winnings.append(winnings) | |
running_profits.append(total_profit) | |
return total_profit, all_winnings, running_profits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment