Spaces:
Running
Running
James McCool
commited on
Commit
·
3963b80
1
Parent(s):
192168c
Refactor prop simulation interface: updated DataFrame columns to include 'Trending Over' and 'Trending Under', reorganized layout for better usability, and improved simulation logic for player props. Enhanced data handling for prop categories and added functionality for downloading projections.
Browse files
app.py
CHANGED
@@ -147,7 +147,7 @@ prop_format = {'L3 Success': '{:.2%}', 'L6_Success': '{:.2%}', 'L10_success': '{
|
|
147 |
all_sim_vars = ['NFL_GAME_PLAYER_PASSING_YARDS', 'NFL_GAME_PLAYER_RUSHING_YARDS', 'NFL_GAME_PLAYER_PASSING_ATTEMPTS', 'NFL_GAME_PLAYER_PASSING_TOUCHDOWNS', 'NFL_GAME_PLAYER_PASSING_COMPLETIONS', 'NFL_GAME_PLAYER_RUSHING_ATTEMPTS',
|
148 |
'NFL_GAME_PLAYER_RECEIVING_RECEPTIONS', 'NFL_GAME_PLAYER_RECEIVING_YARDS', 'NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS']
|
149 |
pick6_sim_vars = ['Rush + Rec Yards', 'Rush + Rec TDs', 'Passing Yards', 'Passing Attempts', 'Passing TDs', 'Completions', 'Rushing Yards', 'Receptions', 'Receiving Yards']
|
150 |
-
sim_all_hold = pd.DataFrame(columns=['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge'])
|
151 |
|
152 |
tab1, tab2, tab3, tab4, tab5, tab6, tab7 = st.tabs(["Game Betting Model", 'Prop Market', "QB Projections", "RB/WR/TE Projections", "Player Prop Trends", "Player Prop Simulations", "Stat Specific Simulations"])
|
153 |
|
@@ -476,334 +476,347 @@ with tab7:
|
|
476 |
non_qb_stats = non_qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
477 |
team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
|
478 |
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
526 |
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
prop_dict = dict(zip(prop_df.Player, prop_df.Prop))
|
539 |
-
prop_type_dict = dict(zip(prop_df.Player, prop_df.prop_type))
|
540 |
-
book_dict = dict(zip(prop_df.Player, prop_df.book))
|
541 |
-
over_dict = dict(zip(prop_df.Player, prop_df.Over))
|
542 |
-
under_dict = dict(zip(prop_df.Player, prop_df.Under))
|
543 |
-
|
544 |
-
player_df['book'] = player_df['Player'].map(book_dict)
|
545 |
-
player_df['Prop'] = player_df['Player'].map(prop_dict)
|
546 |
-
player_df['prop_type'] = player_df['Player'].map(prop_type_dict)
|
547 |
-
|
548 |
-
df = player_df.reset_index(drop=True)
|
549 |
-
|
550 |
-
team_dict = dict(zip(df.Player, df.Team))
|
551 |
-
|
552 |
-
total_sims = 1000
|
553 |
-
|
554 |
-
df.replace("", 0, inplace=True)
|
555 |
-
|
556 |
-
if prop == "NFL_GAME_PLAYER_PASSING_YARDS" or prop == "Passing Yards":
|
557 |
-
df['Median'] = df['pass_yards']
|
558 |
-
elif prop == "NFL_GAME_PLAYER_RUSHING_YARDS" or prop == "Rushing Yards":
|
559 |
-
df['Median'] = df['rush_yards']
|
560 |
-
elif prop == "NFL_GAME_PLAYER_PASSING_ATTEMPTS" or prop == "Passing Attempts":
|
561 |
-
df['Median'] = df['pass_att']
|
562 |
-
elif prop == "NFL_GAME_PLAYER_PASSING_TOUCHDOWNS" or prop == "Passing TDs":
|
563 |
-
df['Median'] = df['pass_tds']
|
564 |
-
elif prop == "NFL_GAME_PLAYER_RUSHING_ATTEMPTS" or prop == "Rushing Attempts":
|
565 |
-
df['Median'] = df['rush_att']
|
566 |
-
elif prop == "NFL_GAME_PLAYER_RECEIVING_RECEPTIONS" or prop == "Receptions":
|
567 |
-
df['Median'] = df['rec']
|
568 |
-
elif prop == "NFL_GAME_PLAYER_RECEIVING_YARDS" or prop == "Receiving Yards":
|
569 |
-
df['Median'] = df['rec_yards']
|
570 |
-
elif prop == "NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS" or prop == "Receiving TDs":
|
571 |
-
df['Median'] = df['rec_tds']
|
572 |
-
elif prop == "Rush + Rec Yards":
|
573 |
-
df['Median'] = df['rush_yards'] + df['rec_yards']
|
574 |
-
elif prop == "Rush + Rec TDs":
|
575 |
-
df['Median'] = df['rush_tds'] + df['rec_tds']
|
576 |
-
|
577 |
-
flex_file = df.copy()
|
578 |
-
flex_file['Floor'] = flex_file['Median'] * .25
|
579 |
-
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * 1.75)
|
580 |
-
flex_file['STD'] = flex_file['Median'] / 4
|
581 |
-
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
582 |
-
flex_file = flex_file[['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
583 |
-
|
584 |
-
hold_file = flex_file.copy()
|
585 |
-
overall_file = flex_file.copy()
|
586 |
-
prop_file = flex_file.copy()
|
587 |
-
|
588 |
-
overall_players = overall_file[['Player']]
|
589 |
-
|
590 |
-
for x in range(0,total_sims):
|
591 |
-
prop_file[x] = prop_file['Prop']
|
592 |
-
|
593 |
-
prop_file = prop_file.drop(['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
594 |
-
|
595 |
-
for x in range(0,total_sims):
|
596 |
-
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
597 |
-
|
598 |
-
overall_file=overall_file.drop(['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
599 |
-
|
600 |
-
players_only = hold_file[['Player']]
|
601 |
-
|
602 |
-
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
603 |
-
|
604 |
-
prop_check = (overall_file - prop_file)
|
605 |
-
|
606 |
-
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
607 |
-
players_only['Book'] = players_only['Player'].map(book_dict)
|
608 |
-
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
609 |
-
players_only['poisson_var'] = players_only.apply(calculate_poisson, axis=1)
|
610 |
-
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
611 |
-
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
612 |
-
players_only['Over'] = np_where(players_only['Prop'] <= 3, players_only['poisson_var'], prop_check[prop_check > 0].count(axis=1)/float(total_sims))
|
613 |
-
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
614 |
-
players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
|
615 |
-
players_only['Under'] = np_where(players_only['Prop'] <= 3, 1 - players_only['poisson_var'], prop_check[prop_check < 0].count(axis=1)/float(total_sims))
|
616 |
-
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
617 |
-
players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
|
618 |
-
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
619 |
-
players_only['prop_threshold'] = .10
|
620 |
-
players_only = players_only[players_only['Mean_Outcome'] > 0]
|
621 |
-
players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
|
622 |
-
players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
|
623 |
-
players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
|
624 |
-
players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
|
625 |
-
players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
|
626 |
-
players_only['Edge'] = players_only['Bet_check']
|
627 |
-
players_only['Prop Type'] = prop
|
628 |
-
|
629 |
-
players_only['Player'] = hold_file[['Player']]
|
630 |
-
players_only['Team'] = players_only['Player'].map(team_dict)
|
631 |
-
|
632 |
-
leg_outcomes = players_only[['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
|
633 |
-
sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
|
634 |
-
|
635 |
-
final_outcomes = sim_all_hold
|
636 |
-
st.write(f'finished {prop} for {books}')
|
637 |
|
638 |
-
|
639 |
|
640 |
-
|
|
|
641 |
|
642 |
-
|
643 |
-
prop_df_raw = prop_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
644 |
-
elif game_select_var == 'Pick6':
|
645 |
-
prop_df_raw = pick_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
646 |
-
|
647 |
-
for books in book_selections:
|
648 |
-
prop_df = prop_df_raw[prop_df_raw['book'] == books]
|
649 |
-
|
650 |
-
if prop_type_var == "NFL_GAME_PLAYER_PASSING_YARDS":
|
651 |
-
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_PASSING_YARDS']
|
652 |
-
elif prop_type_var == "Passing Yards":
|
653 |
-
prop_df = prop_df[prop_df['prop_type'] == 'Passing Yards']
|
654 |
-
elif prop_type_var == "NFL_GAME_PLAYER_RUSHING_YARDS":
|
655 |
-
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_RUSHING_YARDS']
|
656 |
-
elif prop_type_var == "Rushing Yards":
|
657 |
-
prop_df = prop_df[prop_df['prop_type'] == 'Rushing Yards']
|
658 |
-
elif prop_type_var == "NFL_GAME_PLAYER_PASSING_ATTEMPTS":
|
659 |
-
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_PASSING_ATTEMPTS']
|
660 |
-
elif prop_type_var == "Passing Attempts":
|
661 |
-
prop_df = prop_df[prop_df['prop_type'] == 'Passing Attempts']
|
662 |
-
elif prop_type_var == "NFL_GAME_PLAYER_PASSING_TOUCHDOWNS":
|
663 |
-
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_PASSING_TOUCHDOWNS']
|
664 |
-
elif prop_type_var == "Passing TDs":
|
665 |
-
prop_df = prop_df[prop_df['prop_type'] == 'Passing TDs']
|
666 |
-
elif prop_type_var == "NFL_GAME_PLAYER_RUSHING_ATTEMPTS":
|
667 |
-
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_RUSHING_ATTEMPTS']
|
668 |
-
elif prop_type_var == "Rushing Attempts":
|
669 |
-
prop_df = prop_df[prop_df['prop_type'] == 'Rushing Attempts']
|
670 |
-
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_RECEPTIONS":
|
671 |
-
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_RECEIVING_RECEPTIONS']
|
672 |
-
elif prop_type_var == "Receptions":
|
673 |
-
prop_df = prop_df[prop_df['prop_type'] == 'Receptions']
|
674 |
-
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_YARDS":
|
675 |
-
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_RECEIVING_YARDS']
|
676 |
-
elif prop_type_var == "Receiving Yards":
|
677 |
-
prop_df = prop_df[prop_df['prop_type'] == 'Receiving Yards']
|
678 |
-
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS":
|
679 |
-
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS']
|
680 |
-
elif prop_type_var == "Receiving TDs":
|
681 |
-
prop_df = prop_df[prop_df['prop_type'] == 'Receiving TDs']
|
682 |
-
elif prop_type_var == "Rush + Rec Yards":
|
683 |
-
prop_df = prop_df[prop_df['prop_type'] == 'Rush + Rec Yards']
|
684 |
-
elif prop_type_var == "Rush + Rec TDs":
|
685 |
-
prop_df = prop_df[prop_df['prop_type'] == 'Rush + Rec TDs']
|
686 |
-
|
687 |
-
prop_df = prop_df[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
688 |
-
prop_df = prop_df.rename(columns={"over_prop": "Prop"})
|
689 |
-
prop_df['Over'] = 1 / prop_df['over_line']
|
690 |
-
prop_df['Under'] = 1 / prop_df['under_line']
|
691 |
-
|
692 |
-
prop_dict = dict(zip(prop_df.Player, prop_df.Prop))
|
693 |
-
prop_type_dict = dict(zip(prop_df.Player, prop_df.prop_type))
|
694 |
-
book_dict = dict(zip(prop_df.Player, prop_df.book))
|
695 |
-
over_dict = dict(zip(prop_df.Player, prop_df.Over))
|
696 |
-
under_dict = dict(zip(prop_df.Player, prop_df.Under))
|
697 |
-
|
698 |
-
player_df['book'] = player_df['Player'].map(book_dict)
|
699 |
-
player_df['Prop'] = player_df['Player'].map(prop_dict)
|
700 |
-
player_df['prop_type'] = player_df['Player'].map(prop_type_dict)
|
701 |
-
|
702 |
-
df = player_df.reset_index(drop=True)
|
703 |
-
|
704 |
-
team_dict = dict(zip(df.Player, df.Team))
|
705 |
-
|
706 |
-
total_sims = 1000
|
707 |
-
|
708 |
-
df.replace("", 0, inplace=True)
|
709 |
-
|
710 |
-
if prop_type_var == "NFL_GAME_PLAYER_PASSING_YARDS" or prop_type_var == "Passing Yards":
|
711 |
-
df['Median'] = df['pass_yards']
|
712 |
-
elif prop_type_var == "NFL_GAME_PLAYER_RUSHING_YARDS" or prop_type_var == "Rushing Yards":
|
713 |
-
df['Median'] = df['rush_yards']
|
714 |
-
elif prop_type_var == "NFL_GAME_PLAYER_PASSING_ATTEMPTS" or prop_type_var == "Passing Attempts":
|
715 |
-
df['Median'] = df['pass_att']
|
716 |
-
elif prop_type_var == "NFL_GAME_PLAYER_PASSING_TOUCHDOWNS" or prop_type_var == "Passing TDs":
|
717 |
-
df['Median'] = df['pass_tds']
|
718 |
-
elif prop_type_var == "NFL_GAME_PLAYER_RUSHING_ATTEMPTS" or prop_type_var == "Rushing Attempts":
|
719 |
-
df['Median'] = df['rush_att']
|
720 |
-
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_RECEPTIONS" or prop_type_var == "Receptions":
|
721 |
-
df['Median'] = df['rec']
|
722 |
-
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_YARDS" or prop_type_var == "Receiving Yards":
|
723 |
-
df['Median'] = df['rec_yards']
|
724 |
-
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS" or prop_type_var == "Receiving TDs":
|
725 |
-
df['Median'] = df['rec_tds']
|
726 |
-
elif prop_type_var == "Rush + Rec Yards":
|
727 |
-
df['Median'] = df['rush_yards'] + df['rec_yards']
|
728 |
-
elif prop_type_var == "Rush + Rec TDs":
|
729 |
-
df['Median'] = df['rush_tds'] + df['rec_tds']
|
730 |
-
|
731 |
-
flex_file = df.copy()
|
732 |
-
flex_file['Floor'] = flex_file['Median'] * .25
|
733 |
-
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * 1.75)
|
734 |
-
flex_file['STD'] = flex_file['Median'] / 4
|
735 |
-
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
736 |
-
flex_file = flex_file[['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
737 |
-
|
738 |
-
hold_file = flex_file.copy()
|
739 |
-
overall_file = flex_file.copy()
|
740 |
-
prop_file = flex_file.copy()
|
741 |
-
|
742 |
-
overall_players = overall_file[['Player']]
|
743 |
-
|
744 |
-
for x in range(0,total_sims):
|
745 |
-
prop_file[x] = prop_file['Prop']
|
746 |
-
|
747 |
-
prop_file = prop_file.drop(['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
748 |
-
|
749 |
-
for x in range(0,total_sims):
|
750 |
-
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
751 |
-
|
752 |
-
overall_file=overall_file.drop(['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
753 |
-
|
754 |
-
players_only = hold_file[['Player']]
|
755 |
-
|
756 |
-
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
757 |
-
|
758 |
-
prop_check = (overall_file - prop_file)
|
759 |
-
|
760 |
-
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
761 |
-
players_only['Book'] = players_only['Player'].map(book_dict)
|
762 |
-
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
763 |
-
players_only['poisson_var'] = players_only.apply(calculate_poisson, axis=1)
|
764 |
-
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
765 |
-
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
766 |
-
players_only['Over'] = np_where(players_only['Prop'] <= 3, players_only['poisson_var'], prop_check[prop_check > 0].count(axis=1)/float(total_sims))
|
767 |
-
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
768 |
-
players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
|
769 |
-
players_only['Under'] = np_where(players_only['Prop'] <= 3, 1 - players_only['poisson_var'], prop_check[prop_check < 0].count(axis=1)/float(total_sims))
|
770 |
-
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
771 |
-
players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
|
772 |
-
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
773 |
-
players_only['prop_threshold'] = .10
|
774 |
-
players_only = players_only[players_only['Mean_Outcome'] > 0]
|
775 |
-
players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
|
776 |
-
players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
|
777 |
-
players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
|
778 |
-
players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
|
779 |
-
players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
|
780 |
-
players_only['Edge'] = players_only['Bet_check']
|
781 |
-
players_only['Prop Type'] = prop_type_var
|
782 |
-
|
783 |
-
players_only['Player'] = hold_file[['Player']]
|
784 |
-
players_only['Team'] = players_only['Player'].map(team_dict)
|
785 |
-
|
786 |
-
leg_outcomes = players_only[['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
|
787 |
-
sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
|
788 |
-
|
789 |
-
final_outcomes = sim_all_hold
|
790 |
-
st.write(f'finished {prop_type_var} for {books}')
|
791 |
-
|
792 |
-
final_outcomes = final_outcomes.dropna()
|
793 |
-
if game_select_var == 'Pick6':
|
794 |
-
final_outcomes = final_outcomes.drop_duplicates(subset=['Player', 'Prop Type'])
|
795 |
-
final_outcomes = final_outcomes.sort_values(by='Edge', ascending=False)
|
796 |
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
809 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
all_sim_vars = ['NFL_GAME_PLAYER_PASSING_YARDS', 'NFL_GAME_PLAYER_RUSHING_YARDS', 'NFL_GAME_PLAYER_PASSING_ATTEMPTS', 'NFL_GAME_PLAYER_PASSING_TOUCHDOWNS', 'NFL_GAME_PLAYER_PASSING_COMPLETIONS', 'NFL_GAME_PLAYER_RUSHING_ATTEMPTS',
|
148 |
'NFL_GAME_PLAYER_RECEIVING_RECEPTIONS', 'NFL_GAME_PLAYER_RECEIVING_YARDS', 'NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS']
|
149 |
pick6_sim_vars = ['Rush + Rec Yards', 'Rush + Rec TDs', 'Passing Yards', 'Passing Attempts', 'Passing TDs', 'Completions', 'Rushing Yards', 'Receptions', 'Receiving Yards']
|
150 |
+
sim_all_hold = pd.DataFrame(columns=['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Trending Over', 'Over%', 'Imp Under', 'Trending Under', 'Under%', 'Bet?', 'Edge'])
|
151 |
|
152 |
tab1, tab2, tab3, tab4, tab5, tab6, tab7 = st.tabs(["Game Betting Model", 'Prop Market', "QB Projections", "RB/WR/TE Projections", "Player Prop Trends", "Player Prop Simulations", "Stat Specific Simulations"])
|
153 |
|
|
|
476 |
non_qb_stats = non_qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
477 |
team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
|
478 |
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
479 |
+
|
480 |
+
settings_container = st.empty()
|
481 |
+
df_hold_container = st.empty()
|
482 |
+
export_container = st.empty()
|
483 |
+
|
484 |
+
with settings_container.container():
|
485 |
+
col1, col2, col3, col4 = st.columns([3, 3, 3, 3])
|
486 |
+
with col1:
|
487 |
+
game_select_var = st.selectbox('Select prop source', options = ['Aggregate', 'Pick6'])
|
488 |
+
with col2:
|
489 |
+
book_select_var = st.selectbox('Select book', options = ['ALL', 'BET_365', 'DRAFTKINGS', 'FANDUEL', 'MGM', 'UNIBET', 'WILLIAM_HILL'])
|
490 |
+
if book_select_var == 'ALL':
|
491 |
+
book_selections = ['BET_365', 'DRAFTKINGS', 'FANDUEL', 'MGM', 'UNIBET', 'WILLIAM_HILL']
|
492 |
+
else:
|
493 |
+
book_selections = [book_select_var]
|
494 |
+
if game_select_var == 'Aggregate':
|
495 |
+
prop_df = prop_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
496 |
+
elif game_select_var == 'Pick6':
|
497 |
+
prop_df = pick_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
498 |
+
book_selections = ['Pick6']
|
499 |
+
with col3:
|
500 |
+
if game_select_var == 'Aggregate':
|
501 |
+
prop_type_var = st.selectbox('Select prop category', options = ['All Props', 'NFL_GAME_PLAYER_PASSING_YARDS', 'NFL_GAME_PLAYER_RUSHING_YARDS', 'NFL_GAME_PLAYER_PASSING_ATTEMPTS', 'NFL_GAME_PLAYER_PASSING_TOUCHDOWNS', 'NFL_GAME_PLAYER_RUSHING_ATTEMPTS',
|
502 |
+
'NFL_GAME_PLAYER_RECEIVING_RECEPTIONS', 'NFL_GAME_PLAYER_RECEIVING_YARDS', 'NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS'])
|
503 |
+
elif game_select_var == 'Pick6':
|
504 |
+
prop_type_var = st.selectbox('Select prop category', options = ['All Props', 'Rush + Rec Yards', 'Rush + Rec TDs', 'Passing Yards', 'Passing Attempts', 'Passing TDs', 'Rushing Attempts', 'Rushing Yards', 'Receptions', 'Receiving Yards', 'Receiving TDs'])
|
505 |
+
with col4:
|
506 |
+
st.download_button(
|
507 |
+
label="Download Prop Source",
|
508 |
+
data=convert_df_to_csv(prop_df),
|
509 |
+
file_name='NFL_prop_source.csv',
|
510 |
+
mime='text/csv',
|
511 |
+
key='prop_source',
|
512 |
+
)
|
513 |
+
|
514 |
+
if st.button('Simulate Prop Category'):
|
515 |
+
|
516 |
+
with df_hold_container.container():
|
517 |
+
if prop_type_var == 'All Props':
|
518 |
+
if game_select_var == 'Aggregate':
|
519 |
+
prop_df_raw = prop_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
520 |
+
sim_vars = ['NFL_GAME_PLAYER_PASSING_YARDS', 'NFL_GAME_PLAYER_RUSHING_YARDS', 'NFL_GAME_PLAYER_PASSING_ATTEMPTS', 'NFL_GAME_PLAYER_PASSING_TOUCHDOWNS', 'NFL_GAME_PLAYER_RUSHING_ATTEMPTS',
|
521 |
+
'NFL_GAME_PLAYER_RECEIVING_RECEPTIONS', 'NFL_GAME_PLAYER_RECEIVING_YARDS', 'NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS']
|
522 |
+
elif game_select_var == 'Pick6':
|
523 |
+
prop_df_raw = pick_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
524 |
+
sim_vars = ['Rush + Rec Yards', 'Rush + Rec TDs', 'Passing Yards', 'Passing Attempts', 'Passing TDs', 'Rushing Attempts', 'Rushing Yards', 'Receptions', 'Receiving Yards', 'Receiving TDs']
|
525 |
+
|
526 |
+
player_df = overall_stats.copy()
|
527 |
+
|
528 |
+
for prop in sim_vars:
|
529 |
+
|
530 |
+
for books in book_selections:
|
531 |
+
prop_df = prop_df_raw[prop_df_raw['book'] == books]
|
532 |
+
prop_df = prop_df[prop_df['prop_type'] == prop]
|
533 |
+
prop_df = prop_df[~((prop_df['over_prop'] < 15) & (prop_df['prop_type'] == 'NFL_GAME_PLAYER_RUSHING_YARDS'))]
|
534 |
+
prop_df = prop_df[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
535 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
536 |
+
prop_df['Over'] = 1 / prop_df['over_line']
|
537 |
+
prop_df['Under'] = 1 / prop_df['under_line']
|
538 |
+
|
539 |
+
prop_dict = dict(zip(prop_df.Player, prop_df.Prop))
|
540 |
+
prop_type_dict = dict(zip(prop_df.Player, prop_df.prop_type))
|
541 |
+
book_dict = dict(zip(prop_df.Player, prop_df.book))
|
542 |
+
over_dict = dict(zip(prop_df.Player, prop_df.Over))
|
543 |
+
under_dict = dict(zip(prop_df.Player, prop_df.Under))
|
544 |
+
trending_over_dict = dict(zip(prop_df.Player, prop_df['Trending Over']))
|
545 |
+
trending_under_dict = dict(zip(prop_df.Player, prop_df['Trending Under']))
|
546 |
+
|
547 |
+
player_df['book'] = player_df['Player'].map(book_dict)
|
548 |
+
player_df['Prop'] = player_df['Player'].map(prop_dict)
|
549 |
+
player_df['prop_type'] = player_df['Player'].map(prop_type_dict)
|
550 |
+
player_df['Trending Over'] = player_df['Player'].map(trending_over_dict)
|
551 |
+
player_df['Trending Under'] = player_df['Player'].map(trending_under_dict)
|
552 |
+
|
553 |
+
df = player_df.reset_index(drop=True)
|
554 |
+
|
555 |
+
team_dict = dict(zip(df.Player, df.Team))
|
556 |
+
|
557 |
+
total_sims = 1000
|
558 |
+
|
559 |
+
df.replace("", 0, inplace=True)
|
560 |
+
|
561 |
+
if prop == "NFL_GAME_PLAYER_PASSING_YARDS" or prop == "Passing Yards":
|
562 |
+
df['Median'] = df['pass_yards']
|
563 |
+
elif prop == "NFL_GAME_PLAYER_RUSHING_YARDS" or prop == "Rushing Yards":
|
564 |
+
df['Median'] = df['rush_yards']
|
565 |
+
elif prop == "NFL_GAME_PLAYER_PASSING_ATTEMPTS" or prop == "Passing Attempts":
|
566 |
+
df['Median'] = df['pass_att']
|
567 |
+
elif prop == "NFL_GAME_PLAYER_PASSING_TOUCHDOWNS" or prop == "Passing TDs":
|
568 |
+
df['Median'] = df['pass_tds']
|
569 |
+
elif prop == "NFL_GAME_PLAYER_RUSHING_ATTEMPTS" or prop == "Rushing Attempts":
|
570 |
+
df['Median'] = df['rush_att']
|
571 |
+
elif prop == "NFL_GAME_PLAYER_RECEIVING_RECEPTIONS" or prop == "Receptions":
|
572 |
+
df['Median'] = df['rec']
|
573 |
+
elif prop == "NFL_GAME_PLAYER_RECEIVING_YARDS" or prop == "Receiving Yards":
|
574 |
+
df['Median'] = df['rec_yards']
|
575 |
+
elif prop == "NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS" or prop == "Receiving TDs":
|
576 |
+
df['Median'] = df['rec_tds']
|
577 |
+
elif prop == "Rush + Rec Yards":
|
578 |
+
df['Median'] = df['rush_yards'] + df['rec_yards']
|
579 |
+
elif prop == "Rush + Rec TDs":
|
580 |
+
df['Median'] = df['rush_tds'] + df['rec_tds']
|
581 |
|
582 |
+
flex_file = df.copy()
|
583 |
+
flex_file['Floor'] = flex_file['Median'] * .25
|
584 |
+
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * 1.75)
|
585 |
+
flex_file['STD'] = flex_file['Median'] / 4
|
586 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
587 |
+
flex_file = flex_file[['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
588 |
+
|
589 |
+
hold_file = flex_file.copy()
|
590 |
+
overall_file = flex_file.copy()
|
591 |
+
prop_file = flex_file.copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
592 |
|
593 |
+
overall_players = overall_file[['Player']]
|
594 |
|
595 |
+
for x in range(0,total_sims):
|
596 |
+
prop_file[x] = prop_file['Prop']
|
597 |
|
598 |
+
prop_file = prop_file.drop(['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
599 |
|
600 |
+
for x in range(0,total_sims):
|
601 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
602 |
+
|
603 |
+
overall_file=overall_file.drop(['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
604 |
+
|
605 |
+
players_only = hold_file[['Player']]
|
606 |
+
|
607 |
+
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
608 |
+
|
609 |
+
prop_check = (overall_file - prop_file)
|
610 |
+
|
611 |
+
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
612 |
+
players_only['Book'] = players_only['Player'].map(book_dict)
|
613 |
+
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
614 |
+
players_only['Trending Over'] = players_only['Player'].map(trending_over_dict)
|
615 |
+
players_only['Trending Under'] = players_only['Player'].map(trending_under_dict)
|
616 |
+
players_only['poisson_var'] = players_only.apply(calculate_poisson, axis=1)
|
617 |
+
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
618 |
+
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
619 |
+
players_only['Over'] = np_where(players_only['Prop'] <= 3, players_only['poisson_var'], prop_check[prop_check > 0].count(axis=1)/float(total_sims))
|
620 |
+
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
621 |
+
players_only['Over%'] = players_only[["Over", "Imp Over", "Trending Over"]].mean(axis=1)
|
622 |
+
players_only['Under'] = np_where(players_only['Prop'] <= 3, 1 - players_only['poisson_var'], prop_check[prop_check < 0].count(axis=1)/float(total_sims))
|
623 |
+
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
624 |
+
players_only['Under%'] = players_only[["Under", "Imp Under", "Trending Under"]].mean(axis=1)
|
625 |
+
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
626 |
+
players_only['prop_threshold'] = .10
|
627 |
+
players_only = players_only[players_only['Mean_Outcome'] > 0]
|
628 |
+
players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
|
629 |
+
players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
|
630 |
+
players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
|
631 |
+
players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
|
632 |
+
players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
|
633 |
+
players_only['Edge'] = players_only['Bet_check']
|
634 |
+
players_only['Prop Type'] = prop
|
635 |
+
|
636 |
+
players_only['Player'] = hold_file[['Player']]
|
637 |
+
players_only['Team'] = players_only['Player'].map(team_dict)
|
638 |
+
|
639 |
+
leg_outcomes = players_only[['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Trending Over', 'Over%', 'Imp Under', 'Trending Under', 'Under%', 'Bet?', 'Edge']]
|
640 |
+
sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
|
641 |
+
|
642 |
+
final_outcomes = sim_all_hold
|
643 |
+
st.write(f'finished {prop} for {books}')
|
644 |
+
|
645 |
+
elif prop_type_var != 'All Props':
|
646 |
+
|
647 |
+
player_df = overall_stats.copy()
|
648 |
+
|
649 |
+
if game_select_var == 'Aggregate':
|
650 |
+
prop_df_raw = prop_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
651 |
+
elif game_select_var == 'Pick6':
|
652 |
+
prop_df_raw = pick_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
653 |
+
|
654 |
+
for books in book_selections:
|
655 |
+
prop_df = prop_df_raw[prop_df_raw['book'] == books]
|
656 |
+
|
657 |
+
if prop_type_var == "NFL_GAME_PLAYER_PASSING_YARDS":
|
658 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_PASSING_YARDS']
|
659 |
+
elif prop_type_var == "Passing Yards":
|
660 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Passing Yards']
|
661 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RUSHING_YARDS":
|
662 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_RUSHING_YARDS']
|
663 |
+
elif prop_type_var == "Rushing Yards":
|
664 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Rushing Yards']
|
665 |
+
elif prop_type_var == "NFL_GAME_PLAYER_PASSING_ATTEMPTS":
|
666 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_PASSING_ATTEMPTS']
|
667 |
+
elif prop_type_var == "Passing Attempts":
|
668 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Passing Attempts']
|
669 |
+
elif prop_type_var == "NFL_GAME_PLAYER_PASSING_TOUCHDOWNS":
|
670 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_PASSING_TOUCHDOWNS']
|
671 |
+
elif prop_type_var == "Passing TDs":
|
672 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Passing TDs']
|
673 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RUSHING_ATTEMPTS":
|
674 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_RUSHING_ATTEMPTS']
|
675 |
+
elif prop_type_var == "Rushing Attempts":
|
676 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Rushing Attempts']
|
677 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_RECEPTIONS":
|
678 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_RECEIVING_RECEPTIONS']
|
679 |
+
elif prop_type_var == "Receptions":
|
680 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Receptions']
|
681 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_YARDS":
|
682 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_RECEIVING_YARDS']
|
683 |
+
elif prop_type_var == "Receiving Yards":
|
684 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Receiving Yards']
|
685 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS":
|
686 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS']
|
687 |
+
elif prop_type_var == "Receiving TDs":
|
688 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Receiving TDs']
|
689 |
+
elif prop_type_var == "Rush + Rec Yards":
|
690 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Rush + Rec Yards']
|
691 |
+
elif prop_type_var == "Rush + Rec TDs":
|
692 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Rush + Rec TDs']
|
693 |
+
|
694 |
+
prop_df = prop_df[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
695 |
+
prop_df = prop_df.rename(columns={"over_prop": "Prop"})
|
696 |
+
prop_df['Over'] = 1 / prop_df['over_line']
|
697 |
+
prop_df['Under'] = 1 / prop_df['under_line']
|
698 |
+
|
699 |
+
prop_dict = dict(zip(prop_df.Player, prop_df.Prop))
|
700 |
+
prop_type_dict = dict(zip(prop_df.Player, prop_df.prop_type))
|
701 |
+
book_dict = dict(zip(prop_df.Player, prop_df.book))
|
702 |
+
over_dict = dict(zip(prop_df.Player, prop_df.Over))
|
703 |
+
under_dict = dict(zip(prop_df.Player, prop_df.Under))
|
704 |
+
trending_over_dict = dict(zip(prop_df.Player, prop_df['Trending Over']))
|
705 |
+
trending_under_dict = dict(zip(prop_df.Player, prop_df['Trending Under']))
|
706 |
+
|
707 |
+
player_df['book'] = player_df['Player'].map(book_dict)
|
708 |
+
player_df['Prop'] = player_df['Player'].map(prop_dict)
|
709 |
+
player_df['prop_type'] = player_df['Player'].map(prop_type_dict)
|
710 |
+
player_df['Trending Over'] = player_df['Player'].map(trending_over_dict)
|
711 |
+
player_df['Trending Under'] = player_df['Player'].map(trending_under_dict)
|
712 |
+
|
713 |
+
df = player_df.reset_index(drop=True)
|
714 |
+
|
715 |
+
team_dict = dict(zip(df.Player, df.Team))
|
716 |
+
|
717 |
+
total_sims = 1000
|
718 |
+
|
719 |
+
df.replace("", 0, inplace=True)
|
720 |
+
|
721 |
+
if prop_type_var == "NFL_GAME_PLAYER_PASSING_YARDS" or prop_type_var == "Passing Yards":
|
722 |
+
df['Median'] = df['pass_yards']
|
723 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RUSHING_YARDS" or prop_type_var == "Rushing Yards":
|
724 |
+
df['Median'] = df['rush_yards']
|
725 |
+
elif prop_type_var == "NFL_GAME_PLAYER_PASSING_ATTEMPTS" or prop_type_var == "Passing Attempts":
|
726 |
+
df['Median'] = df['pass_att']
|
727 |
+
elif prop_type_var == "NFL_GAME_PLAYER_PASSING_TOUCHDOWNS" or prop_type_var == "Passing TDs":
|
728 |
+
df['Median'] = df['pass_tds']
|
729 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RUSHING_ATTEMPTS" or prop_type_var == "Rushing Attempts":
|
730 |
+
df['Median'] = df['rush_att']
|
731 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_RECEPTIONS" or prop_type_var == "Receptions":
|
732 |
+
df['Median'] = df['rec']
|
733 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_YARDS" or prop_type_var == "Receiving Yards":
|
734 |
+
df['Median'] = df['rec_yards']
|
735 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS" or prop_type_var == "Receiving TDs":
|
736 |
+
df['Median'] = df['rec_tds']
|
737 |
+
elif prop_type_var == "Rush + Rec Yards":
|
738 |
+
df['Median'] = df['rush_yards'] + df['rec_yards']
|
739 |
+
elif prop_type_var == "Rush + Rec TDs":
|
740 |
+
df['Median'] = df['rush_tds'] + df['rec_tds']
|
741 |
+
|
742 |
+
flex_file = df.copy()
|
743 |
+
flex_file['Floor'] = flex_file['Median'] * .25
|
744 |
+
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * 1.75)
|
745 |
+
flex_file['STD'] = flex_file['Median'] / 4
|
746 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
747 |
+
flex_file = flex_file[['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
748 |
+
|
749 |
+
hold_file = flex_file.copy()
|
750 |
+
overall_file = flex_file.copy()
|
751 |
+
prop_file = flex_file.copy()
|
752 |
|
753 |
+
overall_players = overall_file[['Player']]
|
754 |
+
|
755 |
+
for x in range(0,total_sims):
|
756 |
+
prop_file[x] = prop_file['Prop']
|
757 |
+
|
758 |
+
prop_file = prop_file.drop(['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
759 |
+
|
760 |
+
for x in range(0,total_sims):
|
761 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
762 |
+
|
763 |
+
overall_file=overall_file.drop(['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
764 |
+
|
765 |
+
players_only = hold_file[['Player']]
|
766 |
+
|
767 |
+
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
768 |
+
|
769 |
+
prop_check = (overall_file - prop_file)
|
770 |
+
|
771 |
+
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
772 |
+
players_only['Book'] = players_only['Player'].map(book_dict)
|
773 |
+
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
774 |
+
players_only['Trending Over'] = players_only['Player'].map(trending_over_dict)
|
775 |
+
players_only['Trending Under'] = players_only['Player'].map(trending_under_dict)
|
776 |
+
players_only['poisson_var'] = players_only.apply(calculate_poisson, axis=1)
|
777 |
+
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
778 |
+
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
779 |
+
players_only['Over'] = np_where(players_only['Prop'] <= 3, players_only['poisson_var'], prop_check[prop_check > 0].count(axis=1)/float(total_sims))
|
780 |
+
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
781 |
+
players_only['Over%'] = players_only[["Over", "Imp Over", "Trending Over"]].mean(axis=1)
|
782 |
+
players_only['Under'] = np_where(players_only['Prop'] <= 3, 1 - players_only['poisson_var'], prop_check[prop_check < 0].count(axis=1)/float(total_sims))
|
783 |
+
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
784 |
+
players_only['Under%'] = players_only[["Under", "Imp Under", "Trending Under"]].mean(axis=1)
|
785 |
+
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
786 |
+
players_only['prop_threshold'] = .10
|
787 |
+
players_only = players_only[players_only['Mean_Outcome'] > 0]
|
788 |
+
players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
|
789 |
+
players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
|
790 |
+
players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
|
791 |
+
players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
|
792 |
+
players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
|
793 |
+
players_only['Edge'] = players_only['Bet_check']
|
794 |
+
players_only['Prop Type'] = prop_type_var
|
795 |
+
|
796 |
+
players_only['Player'] = hold_file[['Player']]
|
797 |
+
players_only['Team'] = players_only['Player'].map(team_dict)
|
798 |
+
|
799 |
+
leg_outcomes = players_only[['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Trending Over', 'Over%', 'Imp Under', 'Trending Under', 'Under%', 'Bet?', 'Edge']]
|
800 |
+
sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
|
801 |
+
|
802 |
+
final_outcomes = sim_all_hold
|
803 |
+
st.write(f'finished {prop_type_var} for {books}')
|
804 |
+
|
805 |
+
final_outcomes = final_outcomes.dropna()
|
806 |
+
if game_select_var == 'Pick6':
|
807 |
+
final_outcomes = final_outcomes.drop_duplicates(subset=['Player', 'Prop Type'])
|
808 |
+
final_outcomes = final_outcomes.sort_values(by='Edge', ascending=False)
|
809 |
+
|
810 |
+
with df_hold_container:
|
811 |
+
df_hold_container = st.empty()
|
812 |
+
st.dataframe(final_outcomes.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
813 |
+
with export_container:
|
814 |
+
export_container = st.empty()
|
815 |
+
st.download_button(
|
816 |
+
label="Export Projections",
|
817 |
+
data=convert_df_to_csv(final_outcomes),
|
818 |
+
file_name='NFL_prop_proj.csv',
|
819 |
+
mime='text/csv',
|
820 |
+
key='prop_proj',
|
821 |
+
)
|
822 |
+
|