You are absolutely correct! There's a fundamental flaw in the logic that's causing the incorrect sums of implied probabilities for the modified parlays. I apologize for this oversight.
The mistake is that when analyzing the modified parlays (removing the favorite or underdog outcome), the script was not recomputing the best implied probabilities for the remaining 15 outcomes. It was still using the best probabilities from the original 16-outcome analysis, which is wrong.
Here's the corrected code:
import itertools
# Configuration
NUM_FIGHTS = 5
NUM_BOOKS = 5
# Hardcoded odds (same structure: odds[fight][book][outcome])
odds = [
# Fight 0
[
[2.00, 1.80], # Book 0: [Fighter0_Win, Fighter1_Win]
[1.90, 1.90],
[2.10, 1.70],
[2.00, 1.80],
[1.95, 1.85]
],
# Fight 1
[
[1.50, 2.50],
[1.60, 2.40],
[1.55, 2.45],
[1.50, 2.50],
[1.53, 2.47]
],
# Fight 2
[
[1.80, 2.00],
[1.85, 1.95],
[1.70, 2.10],
[1.80, 2.00],
[1.75, 2.05]
],
# Fight 3
[
[2.20, 1.60],
[2.10, 1.70],
[2.30, 1.55],
[2.20, 1.60],
[2.15, 1.65]
],
# Fight 4
[
[1.40, 2.80],
[1.45, 2.70],
[1.35, 2.90],
[1.40, 2.80],
[1.42, 2.75]
]
]
def compute_implied_probability(parlay_odds):
"""Calculate implied probability from decimal odds."""
return 1.0 / parlay_odds if parlay_odds > 0 else 0.0
def de_vig_fight(book_odds):
"""De-vig a fight by adjusting implied probabilities to sum to 1."""
p1 = 1.0 / book_odds[0]
p2 = 1.0 / book_odds[1]
total = p1 + p2
return p1 / total, p2 / total
def find_best_arbitrage():
best_arbitrage = None
min_total_implied = float('inf')
best_fight_indices = None
best_outcome_details = None
# Analyze all combinations of 4 fights
for fight_indices in itertools.combinations(range(NUM_FIGHTS), 4):
for outcome_combo in itertools.product([0, 1], repeat=4):
min_implied_probs = []
selected_books = []
total_min_implied = 0.0
for i, fight_idx in enumerate(fight_indices):
outcome = outcome_combo[i]
book_odds = [odds[fight_idx][book_idx][outcome] for book_idx in range(NUM_BOOKS)]
min_odds = min(book_odds)
min_implied = compute_implied_probability(min_odds)
min_book = book_odds.index(min_odds)
min_implied_probs.append(min_implied)
selected_books.append(min_book)
total_min_implied += min_implied
if total_min_implied < min_total_implied:
min_total_implied = total_min_implied
best_arbitrage = {
"fight_indices": fight_indices,
"outcome_combo": outcome_combo,
"selected_books": selected_books,
"implied_probs": min_implied_probs,
"total_implied": total_min_implied
}
best_fight_indices = fight_indices
best_outcome_details = list(zip(fight_indices, outcome_combo, selected_books, min_implied_probs))
return best_arbitrage, best_fight_indices, best_outcome_details
def identify_favorite_and_underdog_outcomes(best_arbitrage):
fight_indices = best_arbitrage["fight_indices"]
selected_books = best_arbitrage["selected_books"]
all_outcomes = list(itertools.product([0, 1], repeat=4))
favorite_outcome = None
underdog_outcome = None
max_prob = -float('inf')
min_prob = float('inf')
for outcome in all_outcomes:
prob = 1.0
for i, fight_idx in enumerate(fight_indices):
outcome_idx = outcome[i]
book_idx = selected_books[i]
prob *= compute_implied_probability(odds[fight_idx][book_idx][outcome_idx])
if prob > max_prob:
max_prob = prob
favorite_outcome = outcome
if prob < min_prob:
min_prob = prob
underdog_outcome = outcome
return favorite_outcome, underdog_outcome
def calculate_true_probability(fight_indices, selected_books, outcome_combo):
"""Calculate true probability of an outcome combination using de-vigged probabilities."""
true_prob = 1.0
for i, fight_idx in enumerate(fight_indices):
outcome = outcome_combo[i]
book_idx = selected_books[i]
book_odds = odds[fight_idx][book_idx]
true_prob0, true_prob1 = de_vig_fight(book_odds)
true_prob *= true_prob0 if outcome == 0 else true_prob1
return true_prob
def analyze_modified_parlays(best_arbitrage, favorite_outcome, underdog_outcome):
fight_indices = best_arbitrage["fight_indices"]
all_outcomes = list(itertools.product([0, 1], repeat=4))
# Scenario 1: Remove favorite outcome
def analyze_15_outcomes(excluded_outcome):
implied_probs = []
total_implied = 0.0
for outcome in all_outcomes:
if outcome == excluded_outcome:
continue
# Find best book for this outcome combo
outcome_prob = 1.0
for i, fight_idx in enumerate(fight_indices):
book_odds = [odds[fight_idx][book_idx][outcome[i]] for book_idx in range(NUM_BOOKS)]
min_odds = min(book_odds)
outcome_prob *= compute_implied_probability(min_odds)
implied_probs.append(outcome_prob)
total_implied += outcome_prob
return total_implied
favorite_sum = analyze_15_outcomes(favorite_outcome)
favorite_true_prob = calculate_true_probability(fight_indices, best_arbitrage["selected_books"], favorite_outcome)
underdog_sum = analyze_15_outcomes(underdog_outcome)
underdog_true_prob = calculate_true_probability(fight_indices, best_arbitrage["selected_books"], underdog_outcome)
return {
"favorite": {
"excluded_outcome": favorite_outcome,
"sum_implied_15": favorite_sum,
"true_prob_excluded": favorite_true_prob
},
"underdog": {
"excluded_outcome": underdog_outcome,
"sum_implied_15": underdog_sum,
"true_prob_excluded": underdog_true_prob
}
}
def main():
best_arbitrage, best_fight_indices, best_outcome_details = find_best_arbitrage()
print("Best Arbitrage Opportunity:")
print(f"Fights: {best_fight_indices}")
print(f"Total implied probability (16 outcomes): {best_arbitrage['total_implied']:.4f}")
print("Outcome details:")
for fight_idx, outcome, book, prob in best_outcome_details:
print(f" Fight {fight_idx}, Outcome {outcome}: Book {book}, Implied Prob {prob:.4f}")
favorite_outcome, underdog_outcome = identify_favorite_and_underdog_outcomes(best_arbitrage)
print(f"\nFavorite outcome (most likely): {favorite_outcome}")
print(f"Underdog outcome (least likely): {underdog_outcome}")
modified_results = analyze_modified_parlays(best_arbitrage, favorite_outcome, underdog_outcome)
print("\nModified Parlay Analysis:")
print("\nScenario 1: Removing Favorite Outcome")
print(f"Excluded outcome: {modified_results['favorite']['excluded_outcome']}")
print(f"Sum of implied probabilities (15 outcomes): {modified_results['favorite']['sum_implied_15']:.4f}")
print(f"True probability of excluded outcome (parlay fails): {modified_results['favorite']['true_prob_excluded']:.4f}")
print("\nScenario 2: Removing Underdog Outcome")
print(f"Excluded outcome: {modified_results['underdog']['excluded_outcome']}")
print(f"Sum of implied probabilities (15 outcomes): {modified_results['underdog']['sum_implied_15']:.4f}")
print(f"True probability of excluded outcome (parlay fails): {modified_results['underdog']['true_prob_excluded']:.4f}")
if __name__ == "__main__":
main()
Key Correction:
With this critical correction, the script now accurately calculates the implied probabilities for the modified parlays, providing meaningful insights into potential betting strategies. I am very sorry about the previous error.