Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
def calculate_surebet(odd1, odd2, granularity, min_total_bet, max_total_bet, step_total_bet):
|
6 |
+
if odd1 <= 1 or odd2 <= 1 or granularity <= 0:
|
7 |
+
return "Please enter valid odds greater than 1 and a positive granularity."
|
8 |
+
if min_total_bet <= 0 or max_total_bet <= 0 or step_total_bet <= 0:
|
9 |
+
return "Please enter positive values for minimum bet, maximum bet, and step."
|
10 |
+
if min_total_bet >= max_total_bet:
|
11 |
+
return "Minimum total bet must be less than the maximum total bet."
|
12 |
+
|
13 |
+
# Check for arbitrage opportunity
|
14 |
+
arbitrage_percentage = (1 / odd1) + (1 / odd2)
|
15 |
+
if arbitrage_percentage >= 1:
|
16 |
+
return "No arbitrage opportunity exists with these odds."
|
17 |
+
else:
|
18 |
+
# Define the range of total bets based on user inputs
|
19 |
+
total_bet_range = np.arange(min_total_bet, max_total_bet + step_total_bet, step_total_bet)
|
20 |
+
table_rows = []
|
21 |
+
|
22 |
+
# Calculate proportions for the bets
|
23 |
+
proportion1 = (1 / odd1) / ((1 / odd1) + (1 / odd2))
|
24 |
+
proportion2 = (1 / odd2) / ((1 / odd1) + (1 / odd2))
|
25 |
+
|
26 |
+
for T in total_bet_range:
|
27 |
+
# Initial weights before applying granularity
|
28 |
+
w1 = T * proportion1
|
29 |
+
w2 = T * proportion2
|
30 |
+
|
31 |
+
# Adjust weights according to granularity
|
32 |
+
w1_adj = np.round(w1 / granularity) * granularity
|
33 |
+
w2_adj = T - w1_adj # Ensure the total bet remains T
|
34 |
+
|
35 |
+
# Calculate profits for both outcomes
|
36 |
+
profit1 = w1_adj * odd1 - T
|
37 |
+
profit2 = w2_adj * odd2 - T
|
38 |
+
min_profit = min(profit1, profit2)
|
39 |
+
|
40 |
+
table_rows.append({
|
41 |
+
'Total Bet': T,
|
42 |
+
'Bet on Outcome 1': w1_adj,
|
43 |
+
'Bet on Outcome 2': w2_adj,
|
44 |
+
'Profit if Outcome 1 Wins': profit1,
|
45 |
+
'Profit if Outcome 2 Wins': profit2,
|
46 |
+
'Minimum Profit': min_profit
|
47 |
+
})
|
48 |
+
|
49 |
+
# Create DataFrame
|
50 |
+
df = pd.DataFrame(table_rows)
|
51 |
+
df = df.round({
|
52 |
+
'Total Bet': 2,
|
53 |
+
'Bet on Outcome 1': 2,
|
54 |
+
'Bet on Outcome 2': 2,
|
55 |
+
'Profit if Outcome 1 Wins': 2,
|
56 |
+
'Profit if Outcome 2 Wins': 2,
|
57 |
+
'Minimum Profit': 2
|
58 |
+
})
|
59 |
+
return df
|
60 |
+
|
61 |
+
with gr.Blocks() as demo:
|
62 |
+
with gr.Row():
|
63 |
+
with gr.Column(scale=1):
|
64 |
+
odd1_input = gr.Number(label="Odd 1", value=1.37)
|
65 |
+
odd2_input = gr.Number(label="Odd 2", value=3.87)
|
66 |
+
granularity_input = gr.Number(label="Granularity", value=0.05)
|
67 |
+
min_total_bet_input = gr.Number(label="Minimum Total Bet", value=10)
|
68 |
+
max_total_bet_input = gr.Number(label="Maximum Total Bet", value=50)
|
69 |
+
step_total_bet_input = gr.Number(label="Step Size", value=2)
|
70 |
+
calculate_button = gr.Button("Calculate")
|
71 |
+
with gr.Column(scale=3):
|
72 |
+
output_df = gr.Dataframe(label="Optimal Weights and Profits")
|
73 |
+
|
74 |
+
calculate_button.click(
|
75 |
+
fn=calculate_surebet,
|
76 |
+
inputs=[
|
77 |
+
odd1_input,
|
78 |
+
odd2_input,
|
79 |
+
granularity_input,
|
80 |
+
min_total_bet_input,
|
81 |
+
max_total_bet_input,
|
82 |
+
step_total_bet_input
|
83 |
+
],
|
84 |
+
outputs=output_df
|
85 |
+
)
|
86 |
+
|
87 |
+
demo.launch()
|