Multichem commited on
Commit
a31528c
1 Parent(s): 97af186

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +242 -148
app.py CHANGED
@@ -43,6 +43,8 @@ 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', 'PR', 'PA', 'PR']
 
 
46
 
47
  @st.cache_resource(ttl = 300)
48
  def init_baselines():
@@ -309,158 +311,250 @@ with tab5:
309
  export_container = st.empty()
310
 
311
  with col1:
312
- prop_type_var = st.selectbox('Select prop category', options = ['points', 'rebounds', 'assists', 'PRA', 'points+rebounds', 'points+assists', 'rebounds+assists'])
 
313
 
314
  if st.button('Simulate Prop Category'):
315
  with col2:
316
  with df_hold_container.container():
317
-
318
- if prop_type_var == "points":
319
- prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
320
- prop_df = prop_df.loc[prop_df['prop_type'] == 'points']
321
- prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
322
- prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
323
- prop_df = prop_df.loc[prop_df['Prop'] != 0]
324
- st.table(prop_df)
325
- 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))
326
- 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))
327
- df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
328
- elif prop_type_var == "rebounds":
329
- prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
330
- prop_df = prop_df.loc[prop_df['prop_type'] == 'rebounds']
331
- prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
332
- prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
333
- prop_df = prop_df.loc[prop_df['Prop'] != 0]
334
- st.table(prop_df)
335
- 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))
336
- 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))
337
- df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
338
- elif prop_type_var == "assists":
339
- prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
340
- prop_df = prop_df.loc[prop_df['prop_type'] == 'assists']
341
- prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
342
- prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
343
- prop_df = prop_df.loc[prop_df['Prop'] != 0]
344
- st.table(prop_df)
345
- 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))
346
- 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))
347
- df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
348
- elif prop_type_var == "PRA":
349
- prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
350
- prop_df = prop_df.loc[prop_df['prop_type'] == 'PRA']
351
- prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
352
- prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
353
- prop_df = prop_df.loc[prop_df['Prop'] != 0]
354
- st.table(prop_df)
355
- 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))
356
- 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))
357
- df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
358
- elif prop_type_var == "points+rebounds":
359
- prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
360
- prop_df = prop_df.loc[prop_df['prop_type'] == 'points+rebounds']
361
- prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
362
- prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
363
- prop_df = prop_df.loc[prop_df['Prop'] != 0]
364
- st.table(prop_df)
365
- 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))
366
- 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))
367
- df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
368
- elif prop_type_var == "points+assists":
369
- prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
370
- prop_df = prop_df.loc[prop_df['prop_type'] == 'points+assists']
371
- prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
372
- prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
373
- prop_df = prop_df.loc[prop_df['Prop'] != 0]
374
- st.table(prop_df)
375
- 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))
376
- 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))
377
- df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
378
- elif prop_type_var == "rebounds+assists":
379
- prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
380
- prop_df = prop_df.loc[prop_df['prop_type'] == 'rebounds+assists']
381
- prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
382
- prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
383
- prop_df = prop_df.loc[prop_df['Prop'] != 0]
384
- st.table(prop_df)
385
- 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))
386
- 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))
387
- df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
388
-
389
- prop_dict = dict(zip(df.Player, df.Prop))
390
- over_dict = dict(zip(df.Player, df.Over))
391
- under_dict = dict(zip(df.Player, df.Under))
392
-
393
- total_sims = 5000
394
-
395
- df.replace("", 0, inplace=True)
396
-
397
- if prop_type_var == 'points':
398
- df['Median'] = df['Points']
399
- elif prop_type_var == 'rebounds':
400
- df['Median'] = df['Rebounds']
401
- elif prop_type_var == 'assists':
402
- df['Median'] = df['Assists']
403
- elif prop_type_var == 'PRA':
404
- df['Median'] = df['Points'] + df['Rebounds'] + df['Assists']
405
- elif prop_type_var == 'points+rebounds':
406
- df['Median'] = df['Points'] + df['Rebounds']
407
- elif prop_type_var == 'points+assists':
408
- df['Median'] = df['Points'] + df['Assists']
409
- elif prop_type_var == 'rebounds+assists':
410
- df['Median'] = df['Assists'] + df['Rebounds']
411
-
412
- flex_file = df
413
- flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes'] * .25)
414
- flex_file['Ceiling'] = flex_file['Median'] + 10 + (flex_file['Minutes'] * .25)
415
- flex_file['STD'] = (flex_file['Median']/4)
416
- flex_file['Prop'] = flex_file['Player'].map(prop_dict)
417
- flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
418
-
419
- hold_file = flex_file
420
- overall_file = flex_file
421
- prop_file = flex_file
422
-
423
- overall_players = overall_file[['Player']]
424
-
425
- for x in range(0,total_sims):
426
- prop_file[x] = prop_file['Prop']
427
-
428
- prop_file = prop_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
429
-
430
- for x in range(0,total_sims):
431
- overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
432
-
433
- overall_file=overall_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
434
-
435
- players_only = hold_file[['Player']]
436
-
437
- player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
438
-
439
- prop_check = (overall_file - prop_file)
440
-
441
- players_only['Mean_Outcome'] = overall_file.mean(axis=1)
442
- players_only['10%'] = overall_file.quantile(0.1, axis=1)
443
- players_only['90%'] = overall_file.quantile(0.9, axis=1)
444
- players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
445
- players_only['Imp Over'] = players_only['Player'].map(over_dict)
446
- players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
447
- players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
448
- players_only['Imp Under'] = players_only['Player'].map(under_dict)
449
- players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
450
- players_only['Prop'] = players_only['Player'].map(prop_dict)
451
- players_only['Prop_avg'] = players_only['Prop'].mean() / 100
452
- players_only['prop_threshold'] = .10
453
- players_only = players_only.loc[players_only['Mean_Outcome'] > 0]
454
- players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
455
- players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
456
- players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
457
- players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
458
- players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
459
- players_only['Edge'] = players_only['Bet_check']
460
-
461
- players_only['Player'] = hold_file[['Player']]
462
-
463
- final_outcomes = players_only[['Player', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
464
 
465
  final_outcomes = final_outcomes.sort_values(by='Edge', ascending=False)
466
 
 
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', 'PR', 'PA', 'PR']
46
+ all_sim_vars = ['points', 'rebounds', 'assists', 'PRA', 'points+rebounds', 'points+assists', 'rebounds+assists']
47
+ sim_all_hold = pd.DataFrame(columns=['Player', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge'])
48
 
49
  @st.cache_resource(ttl = 300)
50
  def init_baselines():
 
311
  export_container = st.empty()
312
 
313
  with col1:
314
+ prop_type_var = st.selectbox('Select prop category', options = ['points', 'rebounds', 'assists', 'PRA', 'points+rebounds', 'points+assists', 'rebounds+assists',
315
+ 'Sim all'])
316
 
317
  if st.button('Simulate Prop Category'):
318
  with col2:
319
  with df_hold_container.container():
320
+ if prop_type_var == 'Sim all':
321
+ for prop in all_sim_vars:
322
+
323
+ prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
324
+ prop_df = prop_df.loc[prop_df['prop_type'] == prop]
325
+ prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
326
+ prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
327
+ prop_df = prop_df.loc[prop_df['Prop'] != 0]
328
+ st.table(prop_df)
329
+ 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))
330
+ 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))
331
+ df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
332
+
333
+ prop_dict = dict(zip(df.Player, df.Prop))
334
+ over_dict = dict(zip(df.Player, df.Over))
335
+ under_dict = dict(zip(df.Player, df.Under))
336
+
337
+ total_sims = 5000
338
+
339
+ df.replace("", 0, inplace=True)
340
+
341
+ if prop == 'points':
342
+ df['Median'] = df['Points']
343
+ elif prop == 'rebounds':
344
+ df['Median'] = df['Rebounds']
345
+ elif prop == 'assists':
346
+ df['Median'] = df['Assists']
347
+ elif prop == 'PRA':
348
+ df['Median'] = df['Points'] + df['Rebounds'] + df['Assists']
349
+ elif prop == 'points+rebounds':
350
+ df['Median'] = df['Points'] + df['Rebounds']
351
+ elif prop == 'points+assists':
352
+ df['Median'] = df['Points'] + df['Assists']
353
+ elif prop == 'rebounds+assists':
354
+ df['Median'] = df['Assists'] + df['Rebounds']
355
+
356
+ flex_file = df
357
+ flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes'] * .25)
358
+ flex_file['Ceiling'] = flex_file['Median'] + 10 + (flex_file['Minutes'] * .25)
359
+ flex_file['STD'] = (flex_file['Median']/4)
360
+ flex_file['Prop'] = flex_file['Player'].map(prop_dict)
361
+ flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
362
+
363
+ hold_file = flex_file
364
+ overall_file = flex_file
365
+ prop_file = flex_file
366
+
367
+ overall_players = overall_file[['Player']]
368
+
369
+ for x in range(0,total_sims):
370
+ prop_file[x] = prop_file['Prop']
371
+
372
+ prop_file = prop_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
373
+
374
+ for x in range(0,total_sims):
375
+ overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
376
+
377
+ overall_file=overall_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
378
+
379
+ players_only = hold_file[['Player']]
380
+
381
+ player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
382
+
383
+ prop_check = (overall_file - prop_file)
384
+
385
+ players_only['Mean_Outcome'] = overall_file.mean(axis=1)
386
+ players_only['10%'] = overall_file.quantile(0.1, axis=1)
387
+ players_only['90%'] = overall_file.quantile(0.9, axis=1)
388
+ players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
389
+ players_only['Imp Over'] = players_only['Player'].map(over_dict)
390
+ players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
391
+ players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
392
+ players_only['Imp Under'] = players_only['Player'].map(under_dict)
393
+ players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
394
+ players_only['Prop'] = players_only['Player'].map(prop_dict)
395
+ players_only['Prop_avg'] = players_only['Prop'].mean() / 100
396
+ players_only['prop_threshold'] = .10
397
+ players_only = players_only.loc[players_only['Mean_Outcome'] > 0]
398
+ players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
399
+ players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
400
+ players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
401
+ players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
402
+ players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
403
+ players_only['Edge'] = players_only['Bet_check']
404
+
405
+ players_only['Player'] = hold_file[['Player']]
406
+
407
+ leg_outcomes = players_only[['Player', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
408
+
409
+ final_outcomes = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
410
+
411
+ elif prop_type_var != 'Sim all':
412
+ if prop_type_var == "points":
413
+ prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
414
+ prop_df = prop_df.loc[prop_df['prop_type'] == 'points']
415
+ prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
416
+ prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
417
+ prop_df = prop_df.loc[prop_df['Prop'] != 0]
418
+ st.table(prop_df)
419
+ 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))
420
+ 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))
421
+ df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
422
+ elif prop_type_var == "rebounds":
423
+ prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
424
+ prop_df = prop_df.loc[prop_df['prop_type'] == 'rebounds']
425
+ prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
426
+ prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
427
+ prop_df = prop_df.loc[prop_df['Prop'] != 0]
428
+ st.table(prop_df)
429
+ 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))
430
+ 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))
431
+ df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
432
+ elif prop_type_var == "assists":
433
+ prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
434
+ prop_df = prop_df.loc[prop_df['prop_type'] == 'assists']
435
+ prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
436
+ prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
437
+ prop_df = prop_df.loc[prop_df['Prop'] != 0]
438
+ st.table(prop_df)
439
+ 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))
440
+ 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))
441
+ df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
442
+ elif prop_type_var == "PRA":
443
+ prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
444
+ prop_df = prop_df.loc[prop_df['prop_type'] == 'PRA']
445
+ prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
446
+ prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
447
+ prop_df = prop_df.loc[prop_df['Prop'] != 0]
448
+ st.table(prop_df)
449
+ 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))
450
+ 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))
451
+ df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
452
+ elif prop_type_var == "points+rebounds":
453
+ prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
454
+ prop_df = prop_df.loc[prop_df['prop_type'] == 'points+rebounds']
455
+ prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
456
+ prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
457
+ prop_df = prop_df.loc[prop_df['Prop'] != 0]
458
+ st.table(prop_df)
459
+ 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))
460
+ 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))
461
+ df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
462
+ elif prop_type_var == "points+assists":
463
+ prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
464
+ prop_df = prop_df.loc[prop_df['prop_type'] == 'points+assists']
465
+ prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
466
+ prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
467
+ prop_df = prop_df.loc[prop_df['Prop'] != 0]
468
+ st.table(prop_df)
469
+ 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))
470
+ 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))
471
+ df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
472
+ elif prop_type_var == "rebounds+assists":
473
+ prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
474
+ prop_df = prop_df.loc[prop_df['prop_type'] == 'rebounds+assists']
475
+ prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
476
+ prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
477
+ prop_df = prop_df.loc[prop_df['Prop'] != 0]
478
+ st.table(prop_df)
479
+ 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))
480
+ 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))
481
+ df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
482
+
483
+ prop_dict = dict(zip(df.Player, df.Prop))
484
+ over_dict = dict(zip(df.Player, df.Over))
485
+ under_dict = dict(zip(df.Player, df.Under))
486
+
487
+ total_sims = 5000
488
+
489
+ df.replace("", 0, inplace=True)
490
+
491
+ if prop_type_var == 'points':
492
+ df['Median'] = df['Points']
493
+ elif prop_type_var == 'rebounds':
494
+ df['Median'] = df['Rebounds']
495
+ elif prop_type_var == 'assists':
496
+ df['Median'] = df['Assists']
497
+ elif prop_type_var == 'PRA':
498
+ df['Median'] = df['Points'] + df['Rebounds'] + df['Assists']
499
+ elif prop_type_var == 'points+rebounds':
500
+ df['Median'] = df['Points'] + df['Rebounds']
501
+ elif prop_type_var == 'points+assists':
502
+ df['Median'] = df['Points'] + df['Assists']
503
+ elif prop_type_var == 'rebounds+assists':
504
+ df['Median'] = df['Assists'] + df['Rebounds']
505
+
506
+ flex_file = df
507
+ flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes'] * .25)
508
+ flex_file['Ceiling'] = flex_file['Median'] + 10 + (flex_file['Minutes'] * .25)
509
+ flex_file['STD'] = (flex_file['Median']/4)
510
+ flex_file['Prop'] = flex_file['Player'].map(prop_dict)
511
+ flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
512
+
513
+ hold_file = flex_file
514
+ overall_file = flex_file
515
+ prop_file = flex_file
516
+
517
+ overall_players = overall_file[['Player']]
518
+
519
+ for x in range(0,total_sims):
520
+ prop_file[x] = prop_file['Prop']
521
+
522
+ prop_file = prop_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
523
+
524
+ for x in range(0,total_sims):
525
+ overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
526
+
527
+ overall_file=overall_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
528
+
529
+ players_only = hold_file[['Player']]
530
+
531
+ player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
532
+
533
+ prop_check = (overall_file - prop_file)
534
+
535
+ players_only['Mean_Outcome'] = overall_file.mean(axis=1)
536
+ players_only['10%'] = overall_file.quantile(0.1, axis=1)
537
+ players_only['90%'] = overall_file.quantile(0.9, axis=1)
538
+ players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
539
+ players_only['Imp Over'] = players_only['Player'].map(over_dict)
540
+ players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
541
+ players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
542
+ players_only['Imp Under'] = players_only['Player'].map(under_dict)
543
+ players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
544
+ players_only['Prop'] = players_only['Player'].map(prop_dict)
545
+ players_only['Prop_avg'] = players_only['Prop'].mean() / 100
546
+ players_only['prop_threshold'] = .10
547
+ players_only = players_only.loc[players_only['Mean_Outcome'] > 0]
548
+ players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
549
+ players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
550
+ players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
551
+ players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
552
+ players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
553
+ players_only['Edge'] = players_only['Bet_check']
554
+
555
+ players_only['Player'] = hold_file[['Player']]
556
+
557
+ final_outcomes = players_only[['Player', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
558
 
559
  final_outcomes = final_outcomes.sort_values(by='Edge', ascending=False)
560