DFS_Portfolio_Manager / global_func /large_field_preset.py
James McCool
Replace distribute_preset with hedging_preset to manage player exposure in lineup generation. Update app.py to reflect the new preset option and remove the obsolete distribute_preset function. This change enhances the flexibility of lineup strategies by allowing users to hedge against high-exposure players while maintaining performance metrics.
119b2bf
raw
history blame
1.68 kB
import pandas as pd
def large_field_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list):
excluded_cols = ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Stack', 'Size', 'Win%', 'Lineup Edge', 'Weighted Own', 'Geomean', 'Similarity Score']
player_columns = [col for col in portfolio.columns if col not in excluded_cols]
for slack_var in range(1, 20):
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
for team in portfolio['Stack'].unique():
rows_to_drop = []
working_portfolio = portfolio.copy()
working_portfolio = working_portfolio[working_portfolio['Stack'] == team].sort_values(by='Finish_percentile', ascending = True)
working_portfolio = working_portfolio.reset_index(drop=True)
curr_own_type_max = working_portfolio.loc[0, 'Own'] + (slack_var / 20 * working_portfolio.loc[0, 'Own'])
for i in range(1, len(working_portfolio)):
if working_portfolio.loc[i, 'Own'] > curr_own_type_max:
rows_to_drop.append(i)
else:
curr_own_type_max = working_portfolio.loc[i, 'Own'] + (slack_var / 20 * working_portfolio.loc[i, 'Own'])
working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True)
concat_portfolio = pd.concat([concat_portfolio, working_portfolio])
if len(concat_portfolio) >= lineup_target:
return concat_portfolio.sort_values(by='Finish_percentile', ascending=True).head(lineup_target)
return concat_portfolio.sort_values(by='Finish_percentile', ascending=True)