import pandas as pd
#5대리그의 1등 , 꼴등 팀을 안다고 할 떄 , 그 팀의 승리 패배에 2폴씩 건다면 얼마의 수익이 날까
#1번 케이스 ) 전시즌에 1등한 팀은 또 잘할 가능성이 높다.
#2번 케이스 ) 강등하는 팀을 안다고 가정할때 , 꼴찌들만 엮어보자.
#3번 케이스 ) 1번 + 2번 케이스로 확인하자.
#전시즌 우승팀
#2017 ~ 2018 : 첼시 / 레알 / 뮌헨 / 유베 / 모나코
#2018 ~ 2019 : 맨시티 / 바셀 / 뮌헨 / 유베 / PSG
#2019 ~ 2020 : 맨시티 / 바셀 / 뮌헨 / 유베 / PSG
#2020 ~ 2021 : 리버풀 / 레알 / 뮌헨 / 유베 / PSG
#2021 ~ 2022 : 맨시티 / ATM / 뮌헨 / 인터밀란 / 릴
#해당시즌 꼴지팀 / 성탄절의 저주 적용해 후반기 스타트 (19라운드 기준) 에 꼴지팀
#2017 ~ 2018 : 스완지 / 라스팔마스 / 쾰른 / 베네벤토 / 메스
#2018 ~ 2019 : 허더즈필드 / 우에스카 / 뉘른베르크 / 키에보 / 갱강
#2019 ~ 2020 : 노리치 / 에스파뇰 / 파더보른 / SPAL / 툴루즈
#2020 ~ 2021 : 셰필드 / 우에스카 / 샬케 / 크로토네 / 님 올랭피크
#2021 ~ 2022 : 노리치 / 레반테 / 퓌르트 / 살레르니타나 / 생테티엔
#file : all-euro-data-2021-2022 등등
#2021 ~ 2022 WINNER : Man City , Ath Madrid , Bayern Munich , Inter , Lille
winner2122 = ["Man City" , "Ath Madrid" , "Bayern Munich" , "Inter" , "Lille"]
winner2021 = ["Liverpool" , "Real Madrid" , "Bayern Munich" , "Juventus" , "Paris SG"]
winner1920 = ["Man City" , "Barcelona" , "Bayern Munich" , "Juventus" , "Paris SG"]
winner1819 = ["Man City" , "Barcelona" , "Bayern Munich" , "Juventus" , "Paris SG"]
winner1718 = ["Chelsea" , "Real Madrid" , "Bayern Munich" , "Juventus" , "Monaco"]
loser2122 = ["Norwich","Levante","Greuther Furth","Salernitana","St Etienne"]
loser2021 = ["Sheffield United","Huesca","Schalke 04","Crotone","Nimes"]
loser1920 = ["Norwich","Espanol","Paderborn","Spal","Toulouse"]
loser1819 = ["Huddersfield","Huesca","Nurnberg","Chievo","Guingamp"]
loser1718 = ["Swansea","Las Palmas","FC Koln","Benevento","Metz"]
file_list = ["all-euro-data-2021-2022","all-euro-data-2020-2021","all-euro-data-2019-2020"
,"all-euro-data-2018-2019","all-euro-data-2017-2018"]
#file list 0 , 1 , 2 ... 가 2022,2021,2020... 순으로 매칭
#1팀만 픽한 경우 - 1등팀
def howmuch_onepick_winner(winner,file):
find_list = ["E0","SP1","D1","I1","F1"]
money = [0,0,0,0,0] #리그별 수익금
betting = 10000 #만원씩 건다고 예시 (옵션)
move = [[],[],[],[],[]] #금액의 변화량 확인
for i, team in enumerate(winner):
xl = pd.read_excel("./%s.xlsx" %(file) , sheet_name=find_list[i])
for ntp in xl.itertuples():
if ntp.HomeTeam == team:
if int(ntp.FTHG) > int(ntp.FTAG):
money[i] += ((betting * float(ntp.B365H))-betting)
else:
money[i] -= betting
move[i].append(money[i])
elif ntp.AwayTeam == team:
if int(ntp.FTHG) < int(ntp.FTAG):
money[i] += ((betting * float(ntp.B365A))-betting)
else:
money[i] -= betting
move[i].append(money[i])
move[2] += [move[2][-1],move[2][-1],move[2][-1],move[2][-1]]
return (money , move)
#1팀만 픽한 경우 - 꼴등팀
def howmuch_onepick_loser(loser,file):
find_list = ["E0","SP1","D1","I1","F1"]
money = [0,0,0,0,0] #리그별 수익금
betting = 10000 #만원씩 건다고 예시 (옵션)
half = [19,19,17,19,19] #리그 경기수의 절반 인덱스
move = [[],[],[],[],[]] #금액의 변화량 확인
for i, team in enumerate(loser):
xl = pd.read_excel("./%s.xlsx" %(file) , sheet_name=find_list[i])
half_idx = 1
for ntp in xl.itertuples():
if ntp.HomeTeam == team:
if half_idx > half[i]:
if int(ntp.FTHG) < int(ntp.FTAG):
money[i] += ((betting * float(ntp.B365A))-betting)
else:
money[i] -= betting
move[i].append(money[i])
half_idx += 1
elif ntp.AwayTeam == team:
if half_idx > half[i]:
if int(ntp.FTHG) > int(ntp.FTAG):
money[i] += ((betting * float(ntp.B365H))-betting)
else:
money[i] -= betting
move[i].append(money[i])
half_idx += 1
move[2] += [move[2][-1],move[2][-1]]
return (money , move)
from matplotlib import pyplot as plt
def winner_graph(winner,file):
plt.figure(figsize=(16,12))
outcome , out_move = howmuch_onepick_winner(winner,file)
for i in out_move:
while True:
if len(i) < 38:
i.append(i[-1])
else:
break
x_values = [i for i in range(1,39)]
for i in range(5):
plt.plot(x_values, out_move[i], label=winner[i])
plt.legend(fontsize=16)
plt.show()
for i in range(5):
print(winner[i] + " : {}".format(round(outcome[i])))
def loser_graph(loser,file):
plt.figure(figsize=(16,12))
outcome , out_move = howmuch_onepick_loser(loser,file)
for i in out_move:
while True:
if len(i) < 19:
i.append(i[-1])
else:
break
x_values = [i for i in range(1,20)]
for i in range(5):
plt.plot(x_values, out_move[i], label=loser[i])
plt.legend(fontsize=16)
plt.show()
for i in range(5):
print(loser[i] + " : {}".format(round(outcome[i])))
winner_graph(winner2122,file_list[0])
Man City : 8600 Ath Madrid : -27600 Bayern Munich : -19900 Inter : -19400 Lille : -56900
winner_graph(winner2021,file_list[1])
Liverpool : -61800 Real Madrid : 38900 Bayern Munich : -14300 Juventus : -37500 Paris SG : -38700
winner_graph(winner1920,file_list[2])
Man City : -50400 Barcelona : -30300 Bayern Munich : -14500 Juventus : 18100 Paris SG : 13000
winner_graph(winner1819,file_list[3])
Man City : 27500 Barcelona : -23000 Bayern Munich : -35800 Juventus : 29800 Paris SG : -16500
winner_graph(winner1718,file_list[4])
Chelsea : -28900 Real Madrid : -102200 Bayern Munich : 18100 Juventus : 70600 Monaco : 2400
loser_graph(loser2122,file_list[0])
Norwich : 14100 Levante : 700 Greuther Furth : -59500 Salernitana : -88900 St Etienne : -35700
loser_graph(loser2021,file_list[1])
Sheffield United : 23900 Huesca : -6000 Schalke 04 : -4800 Crotone : 36400 Nimes : -67200
loser_graph(loser1920,file_list[2])
Norwich : 42200 Espanol : 57800 Paderborn : 15600 Spal : 83500 Toulouse : 74200
loser_graph(loser1819,file_list[3])
Huddersfield : 81500 Huesca : -54700 Nurnberg : 13000 Chievo : 12100 Guingamp : -19700
loser_graph(loser1718,file_list[4])
Swansea : -16400 Las Palmas : 22300 FC Koln : -1000 Benevento : -10200 Metz : -15000