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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
st.set_page_config(layout="wide")
|
| 3 |
+
|
| 4 |
+
for name in dir():
|
| 5 |
+
if not name.startswith('_'):
|
| 6 |
+
del globals()[name]
|
| 7 |
+
|
| 8 |
+
import numpy as np
|
| 9 |
+
import pandas as pd
|
| 10 |
+
import streamlit as st
|
| 11 |
+
import gspread
|
| 12 |
+
import plotly.express as px
|
| 13 |
+
import random
|
| 14 |
+
import gc
|
| 15 |
+
|
| 16 |
+
@st.cache_resource
|
| 17 |
+
def init_conn():
|
| 18 |
+
scope = ['https://www.googleapis.com/auth/spreadsheets',
|
| 19 |
+
"https://www.googleapis.com/auth/drive"]
|
| 20 |
+
|
| 21 |
+
credentials = {
|
| 22 |
+
"type": "service_account",
|
| 23 |
+
"project_id": "model-sheets-connect",
|
| 24 |
+
"private_key_id": "0e0bc2fdef04e771172fe5807392b9d6639d945e",
|
| 25 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDiu1v/e6KBKOcK\ncx0KQ23nZK3ZVvADYy8u/RUn/EDI82QKxTd/DizRLIV81JiNQxDJXSzgkbwKYEDm\n48E8zGvupU8+Nk76xNPakrQKy2Y8+VJlq5psBtGchJTuUSHcXU5Mg2JhQsB376PJ\nsCw552K6Pw8fpeMDJDZuxpKSkaJR6k9G5Dhf5q8HDXnC5Rh/PRFuKJ2GGRpX7n+2\nhT/sCax0J8jfdTy/MDGiDfJqfQrOPrMKELtsGHR9Iv6F4vKiDqXpKfqH+02E9ptz\nBk+MNcbZ3m90M8ShfRu28ebebsASfarNMzc3dk7tb3utHOGXKCf4tF8yYKo7x8BZ\noO9X4gSfAgMBAAECggEAU8ByyMpSKlTCF32TJhXnVJi/kS+IhC/Qn5JUDMuk4LXr\naAEWsWO6kV/ZRVXArjmuSzuUVrXumISapM9Ps5Ytbl95CJmGDiLDwRL815nvv6k3\nUyAS8EGKjz74RpoIoH6E7EWCAzxlnUgTn+5oP9Flije97epYk3H+e2f1f5e1Nn1d\nYNe8U+1HqJgILcxA1TAUsARBfoD7+K3z/8DVPHI8IpzAh6kTHqhqC23Rram4XoQ6\nzj/ZdVBjvnKuazETfsD+Vl3jGLQA8cKQVV70xdz3xwLcNeHsbPbpGBpZUoF73c65\nkAXOrjYl0JD5yAk+hmYhXr6H9c6z5AieuZGDrhmlFQKBgQDzV6LRXmjn4854DP/J\nI82oX2GcI4eioDZPRukhiQLzYerMQBmyqZIRC+/LTCAhYQSjNgMa+ZKyvLqv48M0\n/x398op/+n3xTs+8L49SPI48/iV+mnH7k0WI/ycd4OOKh8rrmhl/0EWb9iitwJYe\nMjTV/QxNEpPBEXfR1/mvrN/lVQKBgQDuhomOxUhWVRVH6x03slmyRBn0Oiw4MW+r\nrt1hlNgtVmTc5Mu+4G0USMZwYuOB7F8xG4Foc7rIlwS7Ic83jMJxemtqAelwOLdV\nXRLrLWJfX8+O1z/UE15l2q3SUEnQ4esPHbQnZowHLm0mdL14qSVMl1mu1XfsoZ3z\nJZTQb48CIwKBgEWbzQRtKD8lKDupJEYqSrseRbK/ax43DDITS77/DWwHl33D3FYC\nMblUm8ygwxQpR4VUfwDpYXBlklWcJovzamXpSnsfcYVkkQH47NuOXPXPkXQsw+w+\nDYcJzeu7F/vZqk9I7oBkWHUrrik9zPNoUzrfPvSRGtkAoTDSwibhoc5dAoGBAMHE\nK0T/ANeZQLNuzQps6S7G4eqjwz5W8qeeYxsdZkvWThOgDd/ewt3ijMnJm5X05hOn\ni4XF1euTuvUl7wbqYx76Wv3/1ZojiNNgy7ie4rYlyB/6vlBS97F4ZxJdxMlabbCW\n6b3EMWa4EVVXKoA1sCY7IVDE+yoQ1JYsZmq45YzPAoGBANWWHuVueFGZRDZlkNlK\nh5OmySmA0NdNug3G1upaTthyaTZ+CxGliwBqMHAwpkIRPwxUJpUwBTSEGztGTAxs\nWsUOVWlD2/1JaKSmHE8JbNg6sxLilcG6WEDzxjC5dLL1OrGOXj9WhC9KX3sq6qb6\nF/j9eUXfXjAlb042MphoF3ZC\n-----END PRIVATE KEY-----\n",
|
| 26 |
+
"client_email": "gspread-connection@model-sheets-connect.iam.gserviceaccount.com",
|
| 27 |
+
"client_id": "100369174533302798535",
|
| 28 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 29 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 30 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 31 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40model-sheets-connect.iam.gserviceaccount.com"
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
gc_con = gspread.service_account_from_dict(credentials)
|
| 35 |
+
|
| 36 |
+
return gc_con
|
| 37 |
+
|
| 38 |
+
gcservice_account = init_conn()
|
| 39 |
+
|
| 40 |
+
master_hold = 'https://docs.google.com/spreadsheets/d/1Yq0vGriWK-bS79e-bD6_u9pqrYE6Yrlbb_wEkmH-ot0/edit#gid=853878325'
|
| 41 |
+
|
| 42 |
+
game_format = {'Win%': '{:.2%}'}
|
| 43 |
+
prop_format = {'L5 Success': '{:.2%}', 'L10_Success': '{:.2%}', 'L20_success': '{:.2%}', 'Matchup Boost': '{:.2%}', 'Trending Over': '{:.2%}', 'Trending Under': '{:.2%}',
|
| 44 |
+
'Implied Over': '{:.2%}', 'Implied Under': '{:.2%}', 'Over Edge': '{:.2%}', 'Under Edge': '{:.2%}'}
|
| 45 |
+
prop_table_options = ['points', 'threes', 'rebounds', 'assists', 'blocks', 'steals', 'PRA', 'points+rebounds', 'points+assists', 'rebounds+assists']
|
| 46 |
+
all_sim_vars = ['points', 'rebounds', 'assists', 'threes', 'PRA', 'points+rebounds', 'points+assists', 'rebounds+assists']
|
| 47 |
+
sim_all_hold = pd.DataFrame(columns=['Player', 'Prop type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge'])
|
| 48 |
+
|
| 49 |
+
@st.cache_resource(ttl = 300)
|
| 50 |
+
def init_baselines():
|
| 51 |
+
sh = gcservice_account.open_by_url(master_hold)
|
| 52 |
+
worksheet = sh.worksheet('Betting Model Clean')
|
| 53 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 54 |
+
raw_display.replace('#DIV/0!', np.nan, inplace=True)
|
| 55 |
+
raw_display['Win%'] = raw_display['Win%'].replace({'%': ''}, regex=True).astype(float) / 100
|
| 56 |
+
game_model = raw_display.dropna()
|
| 57 |
+
|
| 58 |
+
worksheet = sh.worksheet('DK_Build_Up')
|
| 59 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 60 |
+
raw_display.replace('', np.nan, inplace=True)
|
| 61 |
+
raw_display.rename(columns={"Name": "Player"}, inplace = True)
|
| 62 |
+
raw_display = raw_display[['Player', 'Position', 'Team', 'Opp', 'Minutes', '3P', 'Points', 'Rebounds', 'Assists', 'Steals', 'Blocks', 'Turnovers', 'Fantasy']]
|
| 63 |
+
player_stats = raw_display[raw_display['Minutes'] > 0]
|
| 64 |
+
|
| 65 |
+
player_stats['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
|
| 66 |
+
['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
|
| 67 |
+
'Trey Murphy III', 'Cam Thomas'], inplace=True)
|
| 68 |
+
|
| 69 |
+
worksheet = sh.worksheet('Timestamp')
|
| 70 |
+
timestamp = worksheet.acell('A1').value
|
| 71 |
+
|
| 72 |
+
worksheet = sh.worksheet('Prop_Frame')
|
| 73 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 74 |
+
raw_display.replace('', np.nan, inplace=True)
|
| 75 |
+
prop_frame = raw_display.dropna(subset='Player')
|
| 76 |
+
|
| 77 |
+
worksheet = sh.worksheet('Pick6_ingest')
|
| 78 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 79 |
+
raw_display.replace('', np.nan, inplace=True)
|
| 80 |
+
pick_frame = raw_display.dropna(subset='Player')
|
| 81 |
+
|
| 82 |
+
prop_frame['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
|
| 83 |
+
['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
|
| 84 |
+
'Trey Murphy III', 'Cam Thomas'], inplace=True)
|
| 85 |
+
pick_frame['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
|
| 86 |
+
['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
|
| 87 |
+
'Trey Murphy III', 'Cam Thomas'], inplace=True)
|
| 88 |
+
return game_model, player_stats, prop_frame, pick_frame, timestamp
|
| 89 |
+
|
| 90 |
+
def convert_df_to_csv(df):
|
| 91 |
+
return df.to_csv().encode('utf-8')
|
| 92 |
+
|
| 93 |
+
game_model, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
|
| 94 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 95 |
+
|
| 96 |
+
tab1, tab2, tab3, tab4, tab5 = st.tabs(["Game Betting Model", "Player Projections", "Prop Trend Table", "Player Prop Simulations", "Stat Specific Simulations"])
|
| 97 |
+
|
| 98 |
+
with tab1:
|
| 99 |
+
st.info(t_stamp)
|
| 100 |
+
if st.button("Reset Data", key='reset1'):
|
| 101 |
+
st.cache_data.clear()
|
| 102 |
+
game_model, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
|
| 103 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 104 |
+
line_var1 = st.radio('How would you like to display odds?', options = ['Percentage', 'American'], key='line_var1')
|
| 105 |
+
team_frame = game_model
|
| 106 |
+
if line_var1 == 'Percentage':
|
| 107 |
+
team_frame = team_frame[['Team', 'Opp', 'Team Points', 'Opp Points', 'Proj Total', 'Proj Spread', 'Proj Winner', 'Win%']]
|
| 108 |
+
team_frame = team_frame.set_index('Team')
|
| 109 |
+
st.dataframe(team_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(game_format, precision=2), use_container_width = True)
|
| 110 |
+
if line_var1 == 'American':
|
| 111 |
+
team_frame = team_frame[['Team', 'Opp', 'Team Points', 'Opp Points', 'Proj Total', 'Proj Spread', 'Proj Winner', 'Odds Line']]
|
| 112 |
+
team_frame = team_frame.set_index('Team')
|
| 113 |
+
st.dataframe(team_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 114 |
+
|
| 115 |
+
st.download_button(
|
| 116 |
+
label="Export Team Model",
|
| 117 |
+
data=convert_df_to_csv(team_frame),
|
| 118 |
+
file_name='NBA_team_betting_export.csv',
|
| 119 |
+
mime='text/csv',
|
| 120 |
+
key='team_export',
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
with tab2:
|
| 124 |
+
st.info(t_stamp)
|
| 125 |
+
if st.button("Reset Data", key='reset2'):
|
| 126 |
+
st.cache_data.clear()
|
| 127 |
+
game_model, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
|
| 128 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 129 |
+
split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
|
| 130 |
+
if split_var1 == 'Specific Teams':
|
| 131 |
+
team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = player_stats['Team'].unique(), key='team_var1')
|
| 132 |
+
elif split_var1 == 'All':
|
| 133 |
+
team_var1 = player_stats.Team.values.tolist()
|
| 134 |
+
player_stats = player_stats[player_stats['Team'].isin(team_var1)]
|
| 135 |
+
player_stats_disp = player_stats.set_index('Player')
|
| 136 |
+
player_stats_disp = player_stats_disp.sort_values(by='Fantasy', ascending=False)
|
| 137 |
+
st.dataframe(player_stats_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 138 |
+
st.download_button(
|
| 139 |
+
label="Export Prop Model",
|
| 140 |
+
data=convert_df_to_csv(player_stats),
|
| 141 |
+
file_name='NBA_stats_export.csv',
|
| 142 |
+
mime='text/csv',
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
with tab3:
|
| 146 |
+
st.info(t_stamp)
|
| 147 |
+
if st.button("Reset Data", key='reset3'):
|
| 148 |
+
st.cache_data.clear()
|
| 149 |
+
game_model, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
|
| 150 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 151 |
+
split_var5 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var5')
|
| 152 |
+
if split_var5 == 'Specific Teams':
|
| 153 |
+
team_var5 = st.multiselect('Which teams would you like to include in the tables?', options = player_stats['Team'].unique(), key='team_var5')
|
| 154 |
+
elif split_var5 == 'All':
|
| 155 |
+
team_var5 = player_stats.Team.values.tolist()
|
| 156 |
+
prop_type_var2 = st.selectbox('Select type of prop are you wanting to view', options = prop_table_options)
|
| 157 |
+
prop_frame_disp = prop_frame[prop_frame['Team'].isin(team_var5)]
|
| 158 |
+
prop_frame_disp = prop_frame_disp[prop_frame_disp['prop_type'] == prop_type_var2]
|
| 159 |
+
prop_frame_disp = prop_frame_disp.set_index('Player')
|
| 160 |
+
prop_frame_disp = prop_frame_disp.sort_values(by='Trending Over', ascending=False)
|
| 161 |
+
st.dataframe(prop_frame_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(prop_format, precision=2), use_container_width = True)
|
| 162 |
+
st.download_button(
|
| 163 |
+
label="Export Prop Trends Model",
|
| 164 |
+
data=convert_df_to_csv(prop_frame),
|
| 165 |
+
file_name='NBA_prop_trends_export.csv',
|
| 166 |
+
mime='text/csv',
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
with tab4:
|
| 170 |
+
st.info(t_stamp)
|
| 171 |
+
if st.button("Reset Data", key='reset4'):
|
| 172 |
+
st.cache_data.clear()
|
| 173 |
+
game_model, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
|
| 174 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 175 |
+
col1, col2 = st.columns([1, 5])
|
| 176 |
+
|
| 177 |
+
with col2:
|
| 178 |
+
df_hold_container = st.empty()
|
| 179 |
+
info_hold_container = st.empty()
|
| 180 |
+
plot_hold_container = st.empty()
|
| 181 |
+
|
| 182 |
+
with col1:
|
| 183 |
+
player_check = st.selectbox('Select player to simulate props', options = player_stats['Player'].unique())
|
| 184 |
+
prop_type_var = st.selectbox('Select type of prop to simulate', options = ['points', 'threes', 'rebounds', 'assists', 'blocks', 'steals',
|
| 185 |
+
'PRA', 'points+rebounds', 'points+assists', 'rebounds+assists'])
|
| 186 |
+
|
| 187 |
+
ou_var = st.selectbox('Select wether it is an over or under', options = ['Over', 'Under'])
|
| 188 |
+
if prop_type_var == 'points':
|
| 189 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 50.5, value = 15.5, step = .5)
|
| 190 |
+
elif prop_type_var == 'threes':
|
| 191 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 5.5, value = 1.5, step = .5)
|
| 192 |
+
elif prop_type_var == 'rebounds':
|
| 193 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 25.5, value = 5.5, step = .5)
|
| 194 |
+
elif prop_type_var == 'assists':
|
| 195 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 25.5, value = 5.5, step = .5)
|
| 196 |
+
elif prop_type_var == 'blocks':
|
| 197 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 5.5, value = 1.5, step = .5)
|
| 198 |
+
elif prop_type_var == 'steals':
|
| 199 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 5.5, value = 1.5, step = .5)
|
| 200 |
+
elif prop_type_var == 'PRA':
|
| 201 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 65.5, value = 20.5, step = .5)
|
| 202 |
+
elif prop_type_var == 'points+rebounds':
|
| 203 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 45.5, value = 10.5, step = .5)
|
| 204 |
+
elif prop_type_var == 'points+assists':
|
| 205 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 45.5, value = 10.5, step = .5)
|
| 206 |
+
elif prop_type_var == 'rebounds+assists':
|
| 207 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 45.5, value = 10.5, step = .5)
|
| 208 |
+
line_var = st.number_input('Type in the line on the prop (i.e. -120)', min_value = -1500, max_value = 1500, value = -150, step = 1)
|
| 209 |
+
line_var = line_var + 1
|
| 210 |
+
|
| 211 |
+
if st.button('Simulate Prop'):
|
| 212 |
+
with col2:
|
| 213 |
+
|
| 214 |
+
with df_hold_container.container():
|
| 215 |
+
|
| 216 |
+
df = player_stats
|
| 217 |
+
|
| 218 |
+
total_sims = 5000
|
| 219 |
+
|
| 220 |
+
df.replace("", 0, inplace=True)
|
| 221 |
+
|
| 222 |
+
player_var = df.loc[df['Player'] == player_check]
|
| 223 |
+
player_var = player_var.reset_index()
|
| 224 |
+
|
| 225 |
+
if prop_type_var == 'points':
|
| 226 |
+
df['Median'] = df['Points']
|
| 227 |
+
elif prop_type_var == 'threes':
|
| 228 |
+
df['Median'] = df['3P']
|
| 229 |
+
elif prop_type_var == 'rebounds':
|
| 230 |
+
df['Median'] = df['Rebounds']
|
| 231 |
+
elif prop_type_var == 'assists':
|
| 232 |
+
df['Median'] = df['Assists']
|
| 233 |
+
elif prop_type_var == 'blocks':
|
| 234 |
+
df['Median'] = df['Blocks']
|
| 235 |
+
elif prop_type_var == 'steals':
|
| 236 |
+
df['Median'] = df['Steals']
|
| 237 |
+
elif prop_type_var == 'PRA':
|
| 238 |
+
df['Median'] = df['Points'] + df['Rebounds'] + df['Assists']
|
| 239 |
+
elif prop_type_var == 'points+rebounds':
|
| 240 |
+
df['Median'] = df['Points'] + df['Rebounds']
|
| 241 |
+
elif prop_type_var == 'points+assists':
|
| 242 |
+
df['Median'] = df['Points'] + df['Assists']
|
| 243 |
+
elif prop_type_var == 'rebounds+assists':
|
| 244 |
+
df['Median'] = df['Assists'] + df['Rebounds']
|
| 245 |
+
|
| 246 |
+
flex_file = df
|
| 247 |
+
flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes'] * .25)
|
| 248 |
+
flex_file['Ceiling'] = flex_file['Median'] + 10 + (flex_file['Minutes'] * .25)
|
| 249 |
+
flex_file['STD'] = (flex_file['Median']/4)
|
| 250 |
+
flex_file = flex_file[['Player', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 251 |
+
|
| 252 |
+
hold_file = flex_file
|
| 253 |
+
overall_file = flex_file
|
| 254 |
+
salary_file = flex_file
|
| 255 |
+
|
| 256 |
+
overall_players = overall_file[['Player']]
|
| 257 |
+
|
| 258 |
+
for x in range(0,total_sims):
|
| 259 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
| 260 |
+
|
| 261 |
+
overall_file=overall_file.drop(['Player', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 262 |
+
overall_file.astype('int').dtypes
|
| 263 |
+
|
| 264 |
+
players_only = hold_file[['Player']]
|
| 265 |
+
|
| 266 |
+
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
| 267 |
+
|
| 268 |
+
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
| 269 |
+
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 270 |
+
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 271 |
+
if ou_var == 'Over':
|
| 272 |
+
players_only['beat_prop'] = overall_file[overall_file > prop_var].count(axis=1)/float(total_sims)
|
| 273 |
+
elif ou_var == 'Under':
|
| 274 |
+
players_only['beat_prop'] = (overall_file[overall_file < prop_var].count(axis=1)/float(total_sims))
|
| 275 |
+
|
| 276 |
+
players_only['implied_odds'] = np.where(line_var <= 0, (-(line_var)/((-(line_var))+100)), 100/(line_var+100))
|
| 277 |
+
|
| 278 |
+
players_only['Player'] = hold_file[['Player']]
|
| 279 |
+
|
| 280 |
+
final_outcomes = players_only[['Player', '10%', 'Mean_Outcome', '90%', 'implied_odds', 'beat_prop']]
|
| 281 |
+
final_outcomes['Bet?'] = np.where(final_outcomes['beat_prop'] - final_outcomes['implied_odds'] >= .10, "Bet", "No Bet")
|
| 282 |
+
final_outcomes = final_outcomes.loc[final_outcomes['Player'] == player_check]
|
| 283 |
+
player_outcomes = player_outcomes.loc[player_outcomes['Player'] == player_check]
|
| 284 |
+
player_outcomes = player_outcomes.drop(columns=['Player']).transpose()
|
| 285 |
+
player_outcomes = player_outcomes.reset_index()
|
| 286 |
+
player_outcomes.columns = ['Instance', 'Outcome']
|
| 287 |
+
|
| 288 |
+
x1 = player_outcomes.Outcome.to_numpy()
|
| 289 |
+
|
| 290 |
+
print(x1)
|
| 291 |
+
|
| 292 |
+
hist_data = [x1]
|
| 293 |
+
|
| 294 |
+
group_labels = ['player outcomes']
|
| 295 |
+
|
| 296 |
+
fig = px.histogram(
|
| 297 |
+
player_outcomes, x='Outcome')
|
| 298 |
+
fig.add_vline(x=prop_var, line_dash="dash", line_color="green")
|
| 299 |
+
|
| 300 |
+
with df_hold_container:
|
| 301 |
+
df_hold_container = st.empty()
|
| 302 |
+
format_dict = {'10%': '{:.2f}', 'Mean_Outcome': '{:.2f}','90%': '{:.2f}', 'beat_prop': '{:.2%}','implied_odds': '{:.2%}'}
|
| 303 |
+
st.dataframe(final_outcomes.style.format(format_dict), use_container_width = True)
|
| 304 |
+
|
| 305 |
+
with info_hold_container:
|
| 306 |
+
st.info('The Y-axis is the percent of times in simulations that the player reaches certain thresholds, while the X-axis is the threshold to be met. The Green dotted line is the prop you entered. You can hover over any spot and see the percent to reach that mark.')
|
| 307 |
+
|
| 308 |
+
with plot_hold_container:
|
| 309 |
+
st.dataframe(player_outcomes, use_container_width = True)
|
| 310 |
+
plot_hold_container = st.empty()
|
| 311 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 312 |
+
|
| 313 |
+
with tab5:
|
| 314 |
+
st.info(t_stamp)
|
| 315 |
+
st.info('The Over and Under percentages are a composite percentage based on simulations, historical performance, and implied probabilities, and may be different than you would expect based purely on the median projection. Likewise, the Edge of a bet is not the only indicator of if you should make the bet or not as the suggestion is using a base acceptable threshold to determine how much edge you should have for each stat category.')
|
| 316 |
+
if st.button("Reset Data/Load Data", key='reset5'):
|
| 317 |
+
st.cache_data.clear()
|
| 318 |
+
game_model, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
|
| 319 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 320 |
+
col1, col2 = st.columns([1, 5])
|
| 321 |
+
|
| 322 |
+
with col2:
|
| 323 |
+
df_hold_container = st.empty()
|
| 324 |
+
info_hold_container = st.empty()
|
| 325 |
+
plot_hold_container = st.empty()
|
| 326 |
+
export_container = st.empty()
|
| 327 |
+
|
| 328 |
+
with col1:
|
| 329 |
+
game_select_var = st.selectbox('Select prop source', options = ['Draftkings', 'Pick6'])
|
| 330 |
+
if game_select_var == 'Draftkings':
|
| 331 |
+
prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 332 |
+
elif game_select_var == 'Pick6':
|
| 333 |
+
prop_df = pick_frame[['Full_name', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 334 |
+
prop_df.rename(columns={"Full_name": "Player"}, inplace = True)
|
| 335 |
+
st.download_button(
|
| 336 |
+
label="Download Prop Source",
|
| 337 |
+
data=convert_df_to_csv(prop_df),
|
| 338 |
+
file_name='Nba_prop_source.csv',
|
| 339 |
+
mime='text/csv',
|
| 340 |
+
key='prop_source',
|
| 341 |
+
)
|
| 342 |
+
prop_type_var = st.selectbox('Select prop category', options = ['All Props', 'points', 'rebounds', 'assists', 'threes', 'PRA', 'points+rebounds',
|
| 343 |
+
'points+assists', 'rebounds+assists'])
|
| 344 |
+
if prop_type_var == 'All Props':
|
| 345 |
+
st.info('please note that the All Props run can take some time, you will see progress as tables show up in the sim area to the right')
|
| 346 |
+
|
| 347 |
+
if st.button('Simulate Prop Category'):
|
| 348 |
+
with col2:
|
| 349 |
+
with df_hold_container.container():
|
| 350 |
+
if prop_type_var == 'All Props':
|
| 351 |
+
for prop in all_sim_vars:
|
| 352 |
+
|
| 353 |
+
if game_select_var == 'Draftkings':
|
| 354 |
+
prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 355 |
+
elif game_select_var == 'Pick6':
|
| 356 |
+
prop_df = pick_frame[['Full_name', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 357 |
+
prop_df.rename(columns={"Full_name": "Player"}, inplace = True)
|
| 358 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == prop]
|
| 359 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 360 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 361 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 362 |
+
st.table(prop_df)
|
| 363 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 364 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 365 |
+
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 366 |
+
|
| 367 |
+
prop_dict = dict(zip(df.Player, df.Prop))
|
| 368 |
+
over_dict = dict(zip(df.Player, df.Over))
|
| 369 |
+
under_dict = dict(zip(df.Player, df.Under))
|
| 370 |
+
|
| 371 |
+
total_sims = 5000
|
| 372 |
+
|
| 373 |
+
df.replace("", 0, inplace=True)
|
| 374 |
+
|
| 375 |
+
if prop == 'points':
|
| 376 |
+
df['Median'] = df['Points']
|
| 377 |
+
elif prop == 'rebounds':
|
| 378 |
+
df['Median'] = df['Rebounds']
|
| 379 |
+
elif prop == 'assists':
|
| 380 |
+
df['Median'] = df['Assists']
|
| 381 |
+
elif prop == 'threes':
|
| 382 |
+
df['Median'] = df['3P']
|
| 383 |
+
elif prop == 'PRA':
|
| 384 |
+
df['Median'] = df['Points'] + df['Rebounds'] + df['Assists']
|
| 385 |
+
elif prop == 'points+rebounds':
|
| 386 |
+
df['Median'] = df['Points'] + df['Rebounds']
|
| 387 |
+
elif prop == 'points+assists':
|
| 388 |
+
df['Median'] = df['Points'] + df['Assists']
|
| 389 |
+
elif prop == 'rebounds+assists':
|
| 390 |
+
df['Median'] = df['Assists'] + df['Rebounds']
|
| 391 |
+
|
| 392 |
+
flex_file = df
|
| 393 |
+
flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes'] * .25)
|
| 394 |
+
flex_file['Ceiling'] = flex_file['Median'] + 10 + (flex_file['Minutes'] * .25)
|
| 395 |
+
flex_file['STD'] = (flex_file['Median']/4)
|
| 396 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
| 397 |
+
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 398 |
+
|
| 399 |
+
hold_file = flex_file
|
| 400 |
+
overall_file = flex_file
|
| 401 |
+
prop_file = flex_file
|
| 402 |
+
|
| 403 |
+
overall_players = overall_file[['Player']]
|
| 404 |
+
|
| 405 |
+
for x in range(0,total_sims):
|
| 406 |
+
prop_file[x] = prop_file['Prop']
|
| 407 |
+
|
| 408 |
+
prop_file = prop_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 409 |
+
|
| 410 |
+
for x in range(0,total_sims):
|
| 411 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
| 412 |
+
|
| 413 |
+
overall_file=overall_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 414 |
+
|
| 415 |
+
players_only = hold_file[['Player']]
|
| 416 |
+
|
| 417 |
+
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
| 418 |
+
|
| 419 |
+
prop_check = (overall_file - prop_file)
|
| 420 |
+
|
| 421 |
+
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
| 422 |
+
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 423 |
+
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 424 |
+
players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
|
| 425 |
+
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
| 426 |
+
players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
|
| 427 |
+
players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
|
| 428 |
+
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
| 429 |
+
players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
|
| 430 |
+
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
| 431 |
+
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
| 432 |
+
players_only['prop_threshold'] = .10
|
| 433 |
+
players_only = players_only.loc[players_only['Mean_Outcome'] > 0]
|
| 434 |
+
players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
|
| 435 |
+
players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
|
| 436 |
+
players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
|
| 437 |
+
players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
|
| 438 |
+
players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
|
| 439 |
+
players_only['Edge'] = players_only['Bet_check']
|
| 440 |
+
players_only['Prop type'] = prop
|
| 441 |
+
|
| 442 |
+
players_only['Player'] = hold_file[['Player']]
|
| 443 |
+
|
| 444 |
+
leg_outcomes = players_only[['Player', 'Prop type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
|
| 445 |
+
|
| 446 |
+
sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
|
| 447 |
+
|
| 448 |
+
final_outcomes = sim_all_hold
|
| 449 |
+
|
| 450 |
+
elif prop_type_var != 'All Props':
|
| 451 |
+
if game_select_var == 'Draftkings':
|
| 452 |
+
prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 453 |
+
elif game_select_var == 'Pick6':
|
| 454 |
+
prop_df = pick_frame[['Full_name', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 455 |
+
prop_df.rename(columns={"Full_name": "Player"}, inplace = True)
|
| 456 |
+
if prop_type_var == "points":
|
| 457 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == 'points']
|
| 458 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 459 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 460 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 461 |
+
st.table(prop_df)
|
| 462 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 463 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 464 |
+
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 465 |
+
elif prop_type_var == "rebounds":
|
| 466 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == 'rebounds']
|
| 467 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 468 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 469 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 470 |
+
st.table(prop_df)
|
| 471 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 472 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 473 |
+
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 474 |
+
elif prop_type_var == "assists":
|
| 475 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == 'assists']
|
| 476 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 477 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 478 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 479 |
+
st.table(prop_df)
|
| 480 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 481 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 482 |
+
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 483 |
+
elif prop_type_var == "threes":
|
| 484 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == 'threes']
|
| 485 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 486 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 487 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 488 |
+
st.table(prop_df)
|
| 489 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 490 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 491 |
+
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 492 |
+
elif prop_type_var == "PRA":
|
| 493 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == 'PRA']
|
| 494 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 495 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 496 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 497 |
+
st.table(prop_df)
|
| 498 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 499 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 500 |
+
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 501 |
+
elif prop_type_var == "points+rebounds":
|
| 502 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == 'points+rebounds']
|
| 503 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 504 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 505 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 506 |
+
st.table(prop_df)
|
| 507 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 508 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 509 |
+
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 510 |
+
elif prop_type_var == "points+assists":
|
| 511 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == 'points+assists']
|
| 512 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 513 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 514 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 515 |
+
st.table(prop_df)
|
| 516 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 517 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 518 |
+
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 519 |
+
elif prop_type_var == "rebounds+assists":
|
| 520 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == 'rebounds+assists']
|
| 521 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 522 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 523 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 524 |
+
st.table(prop_df)
|
| 525 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 526 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 527 |
+
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 528 |
+
|
| 529 |
+
prop_dict = dict(zip(df.Player, df.Prop))
|
| 530 |
+
over_dict = dict(zip(df.Player, df.Over))
|
| 531 |
+
under_dict = dict(zip(df.Player, df.Under))
|
| 532 |
+
|
| 533 |
+
total_sims = 5000
|
| 534 |
+
|
| 535 |
+
df.replace("", 0, inplace=True)
|
| 536 |
+
|
| 537 |
+
if prop_type_var == 'points':
|
| 538 |
+
df['Median'] = df['Points']
|
| 539 |
+
elif prop_type_var == 'rebounds':
|
| 540 |
+
df['Median'] = df['Rebounds']
|
| 541 |
+
elif prop_type_var == 'assists':
|
| 542 |
+
df['Median'] = df['Assists']
|
| 543 |
+
elif prop_type_var == 'threes':
|
| 544 |
+
df['Median'] = df['3P']
|
| 545 |
+
elif prop_type_var == 'PRA':
|
| 546 |
+
df['Median'] = df['Points'] + df['Rebounds'] + df['Assists']
|
| 547 |
+
elif prop_type_var == 'points+rebounds':
|
| 548 |
+
df['Median'] = df['Points'] + df['Rebounds']
|
| 549 |
+
elif prop_type_var == 'points+assists':
|
| 550 |
+
df['Median'] = df['Points'] + df['Assists']
|
| 551 |
+
elif prop_type_var == 'rebounds+assists':
|
| 552 |
+
df['Median'] = df['Assists'] + df['Rebounds']
|
| 553 |
+
|
| 554 |
+
flex_file = df
|
| 555 |
+
flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes'] * .25)
|
| 556 |
+
flex_file['Ceiling'] = flex_file['Median'] + 10 + (flex_file['Minutes'] * .25)
|
| 557 |
+
flex_file['STD'] = (flex_file['Median']/4)
|
| 558 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
| 559 |
+
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 560 |
+
|
| 561 |
+
hold_file = flex_file
|
| 562 |
+
overall_file = flex_file
|
| 563 |
+
prop_file = flex_file
|
| 564 |
+
|
| 565 |
+
overall_players = overall_file[['Player']]
|
| 566 |
+
|
| 567 |
+
for x in range(0,total_sims):
|
| 568 |
+
prop_file[x] = prop_file['Prop']
|
| 569 |
+
|
| 570 |
+
prop_file = prop_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 571 |
+
|
| 572 |
+
for x in range(0,total_sims):
|
| 573 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
| 574 |
+
|
| 575 |
+
overall_file=overall_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 576 |
+
|
| 577 |
+
players_only = hold_file[['Player']]
|
| 578 |
+
|
| 579 |
+
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
| 580 |
+
|
| 581 |
+
prop_check = (overall_file - prop_file)
|
| 582 |
+
|
| 583 |
+
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
| 584 |
+
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 585 |
+
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 586 |
+
players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
|
| 587 |
+
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
| 588 |
+
players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
|
| 589 |
+
players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
|
| 590 |
+
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
| 591 |
+
players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
|
| 592 |
+
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
| 593 |
+
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
| 594 |
+
players_only['prop_threshold'] = .10
|
| 595 |
+
players_only = players_only.loc[players_only['Mean_Outcome'] > 0]
|
| 596 |
+
players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
|
| 597 |
+
players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
|
| 598 |
+
players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
|
| 599 |
+
players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
|
| 600 |
+
players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
|
| 601 |
+
players_only['Edge'] = players_only['Bet_check']
|
| 602 |
+
|
| 603 |
+
players_only['Player'] = hold_file[['Player']]
|
| 604 |
+
|
| 605 |
+
final_outcomes = players_only[['Player', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
|
| 606 |
+
|
| 607 |
+
final_outcomes = final_outcomes[final_outcomes['Prop'] > 0]
|
| 608 |
+
final_outcomes = final_outcomes.sort_values(by='Edge', ascending=False)
|
| 609 |
+
|
| 610 |
+
with df_hold_container:
|
| 611 |
+
df_hold_container = st.empty()
|
| 612 |
+
st.dataframe(final_outcomes.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 613 |
+
with export_container:
|
| 614 |
+
export_container = st.empty()
|
| 615 |
+
st.download_button(
|
| 616 |
+
label="Export Projections",
|
| 617 |
+
data=convert_df_to_csv(final_outcomes),
|
| 618 |
+
file_name='Nba_prop_proj.csv',
|
| 619 |
+
mime='text/csv',
|
| 620 |
+
key='prop_proj',
|
| 621 |
+
)
|