Spaces:
Running
Running
James McCool
commited on
Commit
·
d2d39d3
1
Parent(s):
44c4ce3
Full update to prop sim to fix trends and object orientations
Browse files
app.py
CHANGED
@@ -55,7 +55,7 @@ gcservice_account, gcservice_account2, NHL_Data = init_conn()
|
|
55 |
prop_table_options = ['SOG', 'points', 'blocked_shots', 'assists']
|
56 |
prop_format = {'L5 Success': '{:.2%}', 'L10_Success': '{:.2%}', 'L20_success': '{:.2%}', 'Matchup Boost': '{:.2%}', 'Trending Over': '{:.2%}', 'Trending Under': '{:.2%}',
|
57 |
'Implied Over': '{:.2%}', 'Implied Under': '{:.2%}', 'Over Edge': '{:.2%}', 'Under Edge': '{:.2%}'}
|
58 |
-
all_sim_vars = ['
|
59 |
sim_all_hold = pd.DataFrame(columns=['Player', 'Prop type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge'])
|
60 |
|
61 |
@st.cache_resource(ttl=300)
|
@@ -183,40 +183,42 @@ with tab3:
|
|
183 |
for prop in all_sim_vars:
|
184 |
|
185 |
if game_select_var == 'Draftkings':
|
186 |
-
|
187 |
elif game_select_var == 'Pick6':
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
|
|
|
|
200 |
prop_dict = dict(zip(df.Player, df.Prop))
|
201 |
over_dict = dict(zip(df.Player, df.Over))
|
202 |
under_dict = dict(zip(df.Player, df.Under))
|
203 |
|
204 |
-
total_sims =
|
205 |
|
206 |
df.replace("", 0, inplace=True)
|
207 |
|
208 |
-
if prop == '
|
209 |
df['Median'] = df['Player TP']
|
210 |
-
elif prop == '
|
211 |
df['Median'] = df['Player SOG']
|
212 |
-
elif prop == '
|
213 |
df['Median'] = df['Player Assists']
|
214 |
-
elif prop == '
|
215 |
df['Median'] = df['Player Blocks']
|
216 |
|
217 |
flex_file = df
|
218 |
flex_file['Floor'] = (flex_file['Median'] * .15)
|
219 |
-
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] *
|
220 |
flex_file['STD'] = (flex_file['Median']/3)
|
221 |
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
222 |
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
@@ -224,7 +226,7 @@ with tab3:
|
|
224 |
hold_file = flex_file
|
225 |
overall_file = flex_file
|
226 |
prop_file = flex_file
|
227 |
-
|
228 |
overall_players = overall_file[['Player']]
|
229 |
|
230 |
for x in range(0,total_sims):
|
@@ -268,130 +270,136 @@ with tab3:
|
|
268 |
players_only['Team'] = players_only['Player'].map(team_dict)
|
269 |
|
270 |
leg_outcomes = players_only[['Player', 'Team', 'Prop type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
|
271 |
-
|
272 |
sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
|
273 |
|
274 |
-
|
275 |
|
276 |
elif prop_type_var != 'All Props':
|
|
|
277 |
if game_select_var == 'Draftkings':
|
278 |
-
|
279 |
elif game_select_var == 'Pick6':
|
280 |
-
|
281 |
-
|
282 |
-
if prop_type_var == "SOG":
|
283 |
-
prop_df = prop_df.loc[prop_df['prop_type'] == 'SOG']
|
284 |
-
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
285 |
-
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
286 |
-
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
287 |
-
st.table(prop_df)
|
288 |
-
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))
|
289 |
-
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))
|
290 |
-
prop = 'SOG'
|
291 |
-
df = pd.merge(prop_display, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
292 |
-
elif prop_type_var == "points":
|
293 |
-
prop_df = prop_df.loc[prop_df['prop_type'] == 'points']
|
294 |
-
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
295 |
-
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
296 |
-
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
297 |
-
st.table(prop_df)
|
298 |
-
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))
|
299 |
-
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))
|
300 |
-
prop = 'points'
|
301 |
-
df = pd.merge(prop_display, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
302 |
-
elif prop_type_var == "assists":
|
303 |
-
prop_df = prop_df.loc[prop_df['prop_type'] == 'assists']
|
304 |
-
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
305 |
-
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
306 |
-
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
307 |
-
st.table(prop_df)
|
308 |
-
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))
|
309 |
-
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))
|
310 |
-
prop = 'assists'
|
311 |
-
df = pd.merge(prop_display, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
312 |
-
elif prop_type_var == "blocked_shots":
|
313 |
-
prop_df = prop_df.loc[prop_df['prop_type'] == 'blocked_shots']
|
314 |
-
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
315 |
-
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
316 |
-
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
317 |
-
st.table(prop_df)
|
318 |
-
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))
|
319 |
-
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))
|
320 |
-
prop = 'blocked_shots'
|
321 |
-
df = pd.merge(prop_display, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
322 |
-
|
323 |
-
st.table(df)
|
324 |
-
prop_dict = dict(zip(df.Player, df.Prop))
|
325 |
-
over_dict = dict(zip(df.Player, df.Over))
|
326 |
-
under_dict = dict(zip(df.Player, df.Under))
|
327 |
-
|
328 |
-
total_sims = 5000
|
329 |
-
|
330 |
-
df.replace("", 0, inplace=True)
|
331 |
-
|
332 |
-
if prop == 'points':
|
333 |
-
df['Median'] = df['Player TP']
|
334 |
-
elif prop == 'SOG':
|
335 |
-
df['Median'] = df['Player SOG']
|
336 |
-
elif prop == 'assists':
|
337 |
-
df['Median'] = df['Player Assists']
|
338 |
-
elif prop == 'blocked_shots':
|
339 |
-
df['Median'] = df['Player Blocks']
|
340 |
-
|
341 |
-
flex_file = df
|
342 |
-
flex_file['Floor'] = (flex_file['Median'] * .15)
|
343 |
-
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * .85)
|
344 |
-
flex_file['STD'] = (flex_file['Median']/3)
|
345 |
-
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
346 |
-
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
347 |
-
|
348 |
-
hold_file = flex_file
|
349 |
-
overall_file = flex_file
|
350 |
-
prop_file = flex_file
|
351 |
-
|
352 |
-
overall_players = overall_file[['Player']]
|
353 |
-
|
354 |
-
for x in range(0,total_sims):
|
355 |
-
prop_file[x] = prop_file['Prop']
|
356 |
-
|
357 |
-
prop_file = prop_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
358 |
-
|
359 |
-
for x in range(0,total_sims):
|
360 |
-
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
361 |
-
|
362 |
-
overall_file=overall_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
363 |
-
|
364 |
-
players_only = hold_file[['Player']]
|
365 |
-
|
366 |
-
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
367 |
-
|
368 |
-
prop_check = (overall_file - prop_file)
|
369 |
-
|
370 |
-
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
371 |
-
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
372 |
-
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
373 |
-
players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
|
374 |
-
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
375 |
-
players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
|
376 |
-
players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
|
377 |
-
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
378 |
-
players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
|
379 |
-
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
380 |
-
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
381 |
-
players_only['prop_threshold'] = .10
|
382 |
-
players_only = players_only.loc[players_only['Mean_Outcome'] > 0]
|
383 |
-
players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
|
384 |
-
players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
|
385 |
-
players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
|
386 |
-
players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
|
387 |
-
players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
|
388 |
-
players_only['Edge'] = players_only['Bet_check']
|
389 |
-
|
390 |
-
players_only['Player'] = hold_file[['Player']]
|
391 |
-
players_only['Team'] = players_only['Player'].map(team_dict)
|
392 |
-
|
393 |
-
final_outcomes = players_only[['Player', 'Team', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
|
394 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
395 |
final_outcomes = final_outcomes[final_outcomes['Prop'] > 0]
|
396 |
final_outcomes = final_outcomes.sort_values(by='Edge', ascending=False)
|
397 |
|
|
|
55 |
prop_table_options = ['SOG', 'points', 'blocked_shots', 'assists']
|
56 |
prop_format = {'L5 Success': '{:.2%}', 'L10_Success': '{:.2%}', 'L20_success': '{:.2%}', 'Matchup Boost': '{:.2%}', 'Trending Over': '{:.2%}', 'Trending Under': '{:.2%}',
|
57 |
'Implied Over': '{:.2%}', 'Implied Under': '{:.2%}', 'Over Edge': '{:.2%}', 'Under Edge': '{:.2%}'}
|
58 |
+
all_sim_vars = ['NHL_GAME_PLAYER_SHOTS_ON_GOAL', 'NHL_GAME_PLAYER_POINTS', 'NHL_GAME_PLAYER_BLOCKED_SHOTS', 'NHL_GAME_PLAYER_ASSISTS']
|
59 |
sim_all_hold = pd.DataFrame(columns=['Player', 'Prop type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge'])
|
60 |
|
61 |
@st.cache_resource(ttl=300)
|
|
|
183 |
for prop in all_sim_vars:
|
184 |
|
185 |
if game_select_var == 'Draftkings':
|
186 |
+
prop_df_raw = prop_trends[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
187 |
elif game_select_var == 'Pick6':
|
188 |
+
prop_df_raw = pick_frame[['Full_name', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
189 |
+
prop_df_raw.rename(columns={"Full_name": "Player"}, inplace = True)
|
190 |
+
|
191 |
+
for books in ['FANDUEL', 'DRAFTKINGS', 'BET365', 'CONSENSUS']:
|
192 |
+
prop_df = prop_df_raw.loc[prop_df_raw['book'] == books]
|
193 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == prop]
|
194 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
195 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
196 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
197 |
+
st.table(prop_df)
|
198 |
+
prop_df['Over'] = 1 / prop_df['over_line']
|
199 |
+
prop_df['Under'] = 1 / prop_df['under_line']
|
200 |
+
df = pd.merge(prop_display, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
201 |
+
|
202 |
prop_dict = dict(zip(df.Player, df.Prop))
|
203 |
over_dict = dict(zip(df.Player, df.Over))
|
204 |
under_dict = dict(zip(df.Player, df.Under))
|
205 |
|
206 |
+
total_sims = 1000
|
207 |
|
208 |
df.replace("", 0, inplace=True)
|
209 |
|
210 |
+
if prop == 'NHL_GAME_PLAYER_POINTS':
|
211 |
df['Median'] = df['Player TP']
|
212 |
+
elif prop == 'NHL_GAME_PLAYER_SHOTS_ON_GOAL':
|
213 |
df['Median'] = df['Player SOG']
|
214 |
+
elif prop == 'NHL_GAME_PLAYER_ASSISTS':
|
215 |
df['Median'] = df['Player Assists']
|
216 |
+
elif prop == 'NHL_GAME_PLAYER_BLOCKED_SHOTS':
|
217 |
df['Median'] = df['Player Blocks']
|
218 |
|
219 |
flex_file = df
|
220 |
flex_file['Floor'] = (flex_file['Median'] * .15)
|
221 |
+
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * 1)
|
222 |
flex_file['STD'] = (flex_file['Median']/3)
|
223 |
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
224 |
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
|
|
226 |
hold_file = flex_file
|
227 |
overall_file = flex_file
|
228 |
prop_file = flex_file
|
229 |
+
|
230 |
overall_players = overall_file[['Player']]
|
231 |
|
232 |
for x in range(0,total_sims):
|
|
|
270 |
players_only['Team'] = players_only['Player'].map(team_dict)
|
271 |
|
272 |
leg_outcomes = players_only[['Player', 'Team', 'Prop type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
|
|
|
273 |
sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
|
274 |
|
275 |
+
final_outcomes = sim_all_hold
|
276 |
|
277 |
elif prop_type_var != 'All Props':
|
278 |
+
|
279 |
if game_select_var == 'Draftkings':
|
280 |
+
prop_df_raw = prop_trends[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
281 |
elif game_select_var == 'Pick6':
|
282 |
+
prop_df_raw = pick_frame[['Full_name', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
283 |
+
prop_df_raw.rename(columns={"Full_name": "Player"}, inplace = True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
|
285 |
+
for books in ['FANDUEL', 'DRAFTKINGS', 'BET365', 'CONSENSUS']:
|
286 |
+
prop_df = prop_df_raw.loc[prop_df_raw['book'] == books]
|
287 |
+
if prop_type_var == "SOG":
|
288 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == 'NHL_GAME_PLAYER_SHOTS_ON_GOAL']
|
289 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
290 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
291 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
292 |
+
st.table(prop_df)
|
293 |
+
prop_df['Over'] = 1 / prop_df['over_line']
|
294 |
+
prop_df['Under'] = 1 / prop_df['under_line']
|
295 |
+
prop = 'SOG'
|
296 |
+
df = pd.merge(prop_display, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
297 |
+
elif prop_type_var == "points":
|
298 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == 'NHL_GAME_PLAYER_POINTS']
|
299 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
300 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
301 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
302 |
+
st.table(prop_df)
|
303 |
+
prop_df['Over'] = 1 / prop_df['over_line']
|
304 |
+
prop_df['Under'] = 1 / prop_df['under_line']
|
305 |
+
prop = 'points'
|
306 |
+
df = pd.merge(prop_display, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
307 |
+
elif prop_type_var == "assists":
|
308 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == 'NHL_GAME_PLAYER_ASSISTS']
|
309 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
310 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
311 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
312 |
+
st.table(prop_df)
|
313 |
+
prop_df['Over'] = 1 / prop_df['over_line']
|
314 |
+
prop_df['Under'] = 1 / prop_df['under_line']
|
315 |
+
prop = 'assists'
|
316 |
+
df = pd.merge(prop_display, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
317 |
+
elif prop_type_var == "blocked_shots":
|
318 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == 'NHL_GAME_PLAYER_BLOCKED_SHOTS']
|
319 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
320 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
321 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
322 |
+
st.table(prop_df)
|
323 |
+
prop_df['Over'] = 1 / prop_df['over_line']
|
324 |
+
prop_df['Under'] = 1 / prop_df['under_line']
|
325 |
+
prop = 'blocked_shots'
|
326 |
+
df = pd.merge(prop_display, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
327 |
+
|
328 |
+
st.table(df)
|
329 |
+
prop_dict = dict(zip(df.Player, df.Prop))
|
330 |
+
over_dict = dict(zip(df.Player, df.Over))
|
331 |
+
under_dict = dict(zip(df.Player, df.Under))
|
332 |
+
|
333 |
+
total_sims = 1000
|
334 |
+
|
335 |
+
df.replace("", 0, inplace=True)
|
336 |
+
|
337 |
+
if prop == 'NHL_GAME_PLAYER_POINTS':
|
338 |
+
df['Median'] = df['Player TP']
|
339 |
+
elif prop == 'NHL_GAME_PLAYER_SHOTS_ON_GOAL':
|
340 |
+
df['Median'] = df['Player SOG']
|
341 |
+
elif prop == 'NHL_GAME_PLAYER_ASSISTS':
|
342 |
+
df['Median'] = df['Player Assists']
|
343 |
+
elif prop == 'NHL_GAME_PLAYER_BLOCKED_SHOTS':
|
344 |
+
df['Median'] = df['Player Blocks']
|
345 |
+
|
346 |
+
flex_file = df
|
347 |
+
flex_file['Floor'] = (flex_file['Median'] * .15)
|
348 |
+
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * 1)
|
349 |
+
flex_file['STD'] = (flex_file['Median']/3)
|
350 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
351 |
+
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
352 |
+
|
353 |
+
hold_file = flex_file
|
354 |
+
overall_file = flex_file
|
355 |
+
prop_file = flex_file
|
356 |
+
|
357 |
+
overall_players = overall_file[['Player']]
|
358 |
+
|
359 |
+
for x in range(0,total_sims):
|
360 |
+
prop_file[x] = prop_file['Prop']
|
361 |
+
|
362 |
+
prop_file = prop_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
363 |
+
|
364 |
+
for x in range(0,total_sims):
|
365 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
366 |
+
|
367 |
+
overall_file=overall_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
368 |
+
|
369 |
+
players_only = hold_file[['Player']]
|
370 |
+
|
371 |
+
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
372 |
+
|
373 |
+
prop_check = (overall_file - prop_file)
|
374 |
+
|
375 |
+
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
376 |
+
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
377 |
+
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
378 |
+
players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
|
379 |
+
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
380 |
+
players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
|
381 |
+
players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
|
382 |
+
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
383 |
+
players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
|
384 |
+
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
385 |
+
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
386 |
+
players_only['prop_threshold'] = .10
|
387 |
+
players_only = players_only.loc[players_only['Mean_Outcome'] > 0]
|
388 |
+
players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
|
389 |
+
players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
|
390 |
+
players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
|
391 |
+
players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
|
392 |
+
players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
|
393 |
+
players_only['Edge'] = players_only['Bet_check']
|
394 |
+
|
395 |
+
players_only['Player'] = hold_file[['Player']]
|
396 |
+
players_only['Team'] = players_only['Player'].map(team_dict)
|
397 |
+
|
398 |
+
leg_outcomes = players_only[['Player', 'Team', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
|
399 |
+
sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
|
400 |
+
|
401 |
+
final_outcomes = sim_all_hold
|
402 |
+
|
403 |
final_outcomes = final_outcomes[final_outcomes['Prop'] > 0]
|
404 |
final_outcomes = final_outcomes.sort_values(by='Edge', ascending=False)
|
405 |
|