-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbetting_strategy.py
62 lines (44 loc) · 1.56 KB
/
betting_strategy.py
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
import pandas as pd
predict_results = pd.read_csv('/tmp/fifa/today_result.csv')
def calc_ratio(data):
wind_proba = data['win_proba']
lose_proba = data['lose_proba']
draw_proba = data['draw_proba']
max_proba = max(wind_proba, lose_proba, draw_proba)
if wind_proba == max_proba:
p = wind_proba
b = data['win_odds']
buy = "win"
elif lose_proba == max_proba:
p = lose_proba
b = data['lose_odds']
buy = "lose"
else:
p = draw_proba
b = data['draw_odds']
buy = "draw"
ratio = (p * b - 1) / p
return ratio, buy
predict_results[['ratio', 'buy']] = predict_results.apply(
calc_ratio, axis=1, result_type="expand")
columns = ['home_team', 'away_team', 'ratio', 'buy', 'win_odds', 'draw_odds', 'lose_odds', 'win_proba',
'lose_proba', 'draw_proba']
predict_results = predict_results[columns]
print()
print(predict_results.to_string())
predict_results = predict_results[predict_results['ratio'] > 0]
predict_results['ratio'] /= predict_results['ratio'].sum()
predict_results['ratio'] = predict_results['ratio'].round(2)
if len(predict_results) > 0:
print(predict_results.to_string())
print()
mean = 0
print("betting strategy:")
for _, data in predict_results.iterrows():
mean += data[data['buy']+"_odds"] * \
data['ratio'] * data[data['buy']+"_proba"]
print(
f"{data['home_team']} vs {data['away_team']}: {data['buy']} {data['ratio']}")
print("The possible payoff is : ", mean)
else:
print("No bet today!")