James McCool
commited on
Commit
·
e8898ed
1
Parent(s):
9e303cb
Enhance volatility_preset function to include sport-specific logic for MLB, allowing dynamic adjustments in player selection based on team diversity. This update improves lineup generation accuracy by refining the handling of team constraints and optimizing the portfolio based on lineup edge.
Browse files
global_func/small_field_preset.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import pandas as pd
|
|
|
2 |
|
3 |
def small_field_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list, sport: str):
|
4 |
excluded_cols = ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Stack', 'Size', 'Win%', 'Lineup Edge', 'Weighted Own', 'Geomean', 'Diversity']
|
|
|
1 |
import pandas as pd
|
2 |
+
import numpy as np
|
3 |
|
4 |
def small_field_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list, sport: str):
|
5 |
excluded_cols = ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Stack', 'Size', 'Win%', 'Lineup Edge', 'Weighted Own', 'Geomean', 'Diversity']
|
global_func/volatility_preset.py
CHANGED
@@ -7,11 +7,29 @@ def volatility_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols:
|
|
7 |
|
8 |
for slack_var in range(1, 20):
|
9 |
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
rows_to_drop = []
|
13 |
working_portfolio = portfolio.copy()
|
14 |
-
working_portfolio = working_portfolio
|
15 |
working_portfolio = working_portfolio.reset_index(drop=True)
|
16 |
curr_own_type_max = working_portfolio.loc[0, 'Diversity'] + (slack_var / 20 * working_portfolio.loc[0, 'Diversity'])
|
17 |
|
@@ -23,7 +41,7 @@ def volatility_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols:
|
|
23 |
|
24 |
working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True)
|
25 |
concat_portfolio = pd.concat([concat_portfolio, working_portfolio])
|
26 |
-
|
27 |
if len(concat_portfolio) >= lineup_target:
|
28 |
return concat_portfolio.sort_values(by='Lineup Edge', ascending=False).head(lineup_target)
|
29 |
|
|
|
7 |
|
8 |
for slack_var in range(1, 20):
|
9 |
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
|
10 |
+
if sport == 'MLB':
|
11 |
+
for team in portfolio['Stack'].unique():
|
12 |
+
rows_to_drop = []
|
13 |
+
working_portfolio = portfolio.copy()
|
14 |
+
working_portfolio = working_portfolio[working_portfolio['Stack'] == team].sort_values(by='Lineup Edge', ascending = False)
|
15 |
+
working_portfolio = working_portfolio.reset_index(drop=True)
|
16 |
+
curr_own_type_max = working_portfolio.loc[0, 'Diversity'] + (slack_var / 20 * working_portfolio.loc[0, 'Diversity'])
|
17 |
|
18 |
+
for i in range(1, len(working_portfolio)):
|
19 |
+
if working_portfolio.loc[i, 'Diversity'] < curr_own_type_max:
|
20 |
+
rows_to_drop.append(i)
|
21 |
+
else:
|
22 |
+
curr_own_type_max = working_portfolio.loc[i, 'Diversity'] + (slack_var / 20 * working_portfolio.loc[i, 'Diversity'])
|
23 |
+
|
24 |
+
working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True)
|
25 |
+
concat_portfolio = pd.concat([concat_portfolio, working_portfolio])
|
26 |
+
|
27 |
+
if len(concat_portfolio) >= lineup_target:
|
28 |
+
return concat_portfolio.sort_values(by='Lineup Edge', ascending=False).head(lineup_target)
|
29 |
+
else:
|
30 |
rows_to_drop = []
|
31 |
working_portfolio = portfolio.copy()
|
32 |
+
working_portfolio = working_portfolio.sort_values(by='Lineup Edge', ascending = False)
|
33 |
working_portfolio = working_portfolio.reset_index(drop=True)
|
34 |
curr_own_type_max = working_portfolio.loc[0, 'Diversity'] + (slack_var / 20 * working_portfolio.loc[0, 'Diversity'])
|
35 |
|
|
|
41 |
|
42 |
working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True)
|
43 |
concat_portfolio = pd.concat([concat_portfolio, working_portfolio])
|
44 |
+
|
45 |
if len(concat_portfolio) >= lineup_target:
|
46 |
return concat_portfolio.sort_values(by='Lineup Edge', ascending=False).head(lineup_target)
|
47 |
|