File size: 3,286 Bytes
4aba1ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import gradio as gr
import pandas as pd
import numpy as np

def calculate_surebet(odd1, odd2, granularity, min_total_bet, max_total_bet, step_total_bet):
    if odd1 <= 1 or odd2 <= 1 or granularity <= 0:
        return "Please enter valid odds greater than 1 and a positive granularity."
    if min_total_bet <= 0 or max_total_bet <= 0 or step_total_bet <= 0:
        return "Please enter positive values for minimum bet, maximum bet, and step."
    if min_total_bet >= max_total_bet:
        return "Minimum total bet must be less than the maximum total bet."
    
    # Check for arbitrage opportunity
    arbitrage_percentage = (1 / odd1) + (1 / odd2)
    if arbitrage_percentage >= 1:
        return "No arbitrage opportunity exists with these odds."
    else:
        # Define the range of total bets based on user inputs
        total_bet_range = np.arange(min_total_bet, max_total_bet + step_total_bet, step_total_bet)
        table_rows = []

        # Calculate proportions for the bets
        proportion1 = (1 / odd1) / ((1 / odd1) + (1 / odd2))
        proportion2 = (1 / odd2) / ((1 / odd1) + (1 / odd2))

        for T in total_bet_range:
            # Initial weights before applying granularity
            w1 = T * proportion1
            w2 = T * proportion2

            # Adjust weights according to granularity
            w1_adj = np.round(w1 / granularity) * granularity
            w2_adj = T - w1_adj  # Ensure the total bet remains T

            # Calculate profits for both outcomes
            profit1 = w1_adj * odd1 - T
            profit2 = w2_adj * odd2 - T
            min_profit = min(profit1, profit2)

            table_rows.append({
                'Total Bet': T,
                'Bet on Outcome 1': w1_adj,
                'Bet on Outcome 2': w2_adj,
                'Profit if Outcome 1 Wins': profit1,
                'Profit if Outcome 2 Wins': profit2,
                'Minimum Profit': min_profit
            })
        
        # Create DataFrame
        df = pd.DataFrame(table_rows)
        df = df.round({
            'Total Bet': 2,
            'Bet on Outcome 1': 2,
            'Bet on Outcome 2': 2,
            'Profit if Outcome 1 Wins': 2,
            'Profit if Outcome 2 Wins': 2,
            'Minimum Profit': 2
        })
        return df

with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column(scale=1):
            odd1_input = gr.Number(label="Odd 1", value=1.37)
            odd2_input = gr.Number(label="Odd 2", value=3.87)
            granularity_input = gr.Number(label="Granularity", value=0.05)
            min_total_bet_input = gr.Number(label="Minimum Total Bet", value=10)
            max_total_bet_input = gr.Number(label="Maximum Total Bet", value=50)
            step_total_bet_input = gr.Number(label="Step Size", value=2)
            calculate_button = gr.Button("Calculate")
        with gr.Column(scale=3):
            output_df = gr.Dataframe(label="Optimal Weights and Profits")

    calculate_button.click(
        fn=calculate_surebet,
        inputs=[
            odd1_input,
            odd2_input,
            granularity_input,
            min_total_bet_input,
            max_total_bet_input,
            step_total_bet_input
        ],
        outputs=output_df
    )

demo.launch()