-
Notifications
You must be signed in to change notification settings - Fork 6
/
simulate.py
62 lines (52 loc) · 1.87 KB
/
simulate.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 mlbgame
import datetime
import numpy as np
import pandas as pd
import math
import matplotlib.pyplot as plt
simulationData = {}
pickMethods = {}
initialBankroll = 0.0
bankrollTrend = {}
# Setup Methods
def with_bankroll(amount):
global initialBankroll
initialBankroll = amount
def with_data(data):
global simulationData
simulationData = data
def with_methods(methods):
global pickMethods,initialBankroll
pickMethods = methods
for key in pickMethods.keys():
bankrollTrend[key] = [initialBankroll]
#Public Methods
def games_for_seasons(seasons):
global simulationData,pickMethod,bankrollTrend
for season in seasons:
seasonData = simulationData[season]
for i,row in seasonData.iterrows():
game = seasonData.iloc[i]
for key,method in pickMethods.items():
pick,confidence = method(game)
pickLine = game['HomeTeamLine'] if pick==game['HomeTeam'] else game['AwayTeamLine']
bankroll = bankrollTrend[key][-1]
betAmount = round(float(bankroll)*confidence,2)
bankroll -= betAmount
didWinPick = (pick==game['WinningTeam'])
if didWinPick:
winningsAmount = round(float(betAmount)*float(convert_line_to_multiplier(game['WinningTeamLine'])),2)
bankroll += winningsAmount
bankrollTrend[key].append(bankroll)
print bankroll
plt.title(str(season) + ' MLB Season' );
plt.xlabel('Games Bet')
plt.ylabel('Bankroll ($)')
for label,trend in bankrollTrend.items():
plt.plot(trend, label=label)
plt.legend(loc=0)
plt.savefig('graphs/mlb_{}.png'.format(season))
def convert_line_to_multiplier(line):
if float(line)>0:
return float(line)/100.0 + 1.0
return 100.0/float(abs(line)) + 1.0