Skip to content

Instantly share code, notes, and snippets.

import subprocess
import pandas as pd
import pickle
from fuzzywuzzy import process, fuzz
from sympy import symbols, Eq, solve
#3,Finding Surebets
#Formula to find surebets
def find_surebet(frame):
frame[['btts_x_1', 'btts_x_2']] = frame['btts_x'].apply(lambda x: x.split('\n')).apply(pd.Series).astype(float)
frame[['btts_y_1', 'btts_y_2']] = frame['btts_y'].apply(lambda x: x.split('\n')).apply(pd.Series).astype(float)
frame['sure_btts1'] = (1 / frame['btts_x_1']) + (1 / frame['btts_y_2'])
frame['sure_btts2'] = (1 / frame['btts_x_2']) + (1 / frame['btts_y_1'])
frame = frame[['Teams_x', 'btts_x', 'Teams_y', 'btts_y', 'sure_btts1', 'sure_btts2']]
frame = frame[(frame['sure_btts1'] < 1) | (frame['sure_btts2'] < 1)]
frame.reset_index(drop=True, inplace=True)
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
import time
import pickle
import re
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import pandas as pd
import pickle
options = Options()
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import pandas as pd
import pickle
def beat_bookies(odds1, odds2, total_stake):
x, y = symbols('x y')
eq1 = Eq(x + y - total_stake, 0) # total_stake = x + y
eq2 = Eq((odds2*y) - odds1*x, 0) # odds1*x = odds2*y
stakes = solve((eq1,eq2), (x, y))
total_investment = stakes[x] + stakes[y]
profit1 = odds1*stakes[x] - total_stake
profit2 = odds2*stakes[y] - total_stake
benefit1 = f'{profit1 / total_investment * 100:.2f}%'
benefit2 = f'{profit2 / total_investment * 100:.2f}%'
import subprocess
import pandas as pd
import pickle
from fuzzywuzzy import process, fuzz
from sympy import symbols, Eq, solve
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)
headers = {
'authority': 'www.google.com',
'content-length': '0',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
'content-type': 'text/plain;charset=UTF-8',
'accept': '*/*',
'referer': 'https://www.google.com/',
'accept-language': 'en-US,en;q=0.9',
}
def calculate_real_odds(home_team, away_team, df_past_years, market):
df_past_years = df_past_years.assign(total_goals=df_past_years['home_goals'] + df_past_years['away_goals'])
df_past_years['Over/Under'] = np.where(df_past_years['total_goals']>2, 'Over 2.5', 'Under 2.5')
dict_markets = {'Over/Under':['Over 2.5', 'Under 2.5']}
df_real_odds = df_past_years[(df_past_years['home_team']==home_team)|(df_past_years['away_team']==away_team)].groupby(market).count()[['total_goals']]
option1 = df_real_odds.loc[dict_markets[market][0], 'total_goals']
option2 = df_real_odds.loc[dict_markets[market][1], 'total_goals']
percentage_odds_over = option1 / (option1 + option2)
real_odds = round(1/percentage_odds_over, 2)
return real_odds
dict_leagues = {'Spanish La Liga':'SP1', 'German Bundesliga':'D1',
'English Premier League':'E0', 'Italian Serie A':'I1'}
dict_historical_data = {}
for league in dict_leagues:
frames = []
for i in range(15, 21):
df = pd.read_csv("http://www.football-data.co.uk/mmz4281/"+str(i)+str(i+1)+"/"+dict_leagues[league]+".csv")
df = df[['Date', 'HomeTeam', 'AwayTeam', 'FTHG', 'FTAG']]
df = df.rename(columns={'HomeTeam':'home_team', 'AwayTeam':'away_team','FTHG': 'home_goals', 'FTAG': 'away_goals'})