DFS_Portfolio_Manager / global_func /large_field_preset.py
James McCool
Refactor large_field_preset function to simplify ranking logic by removing median and finish percentile rankings, and adjust filtering criteria to focus on 'Finish_percentile' for team-based selection, enhancing accuracy in lineup targeting.
1107ea4
raw
history blame
1.46 kB
import pandas as pd
def large_field_preset(portfolio: pd.DataFrame, lineup_target: int):
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='median', ascending = False)
working_portfolio = working_portfolio.reset_index(drop=True)
curr_own_type_max = working_portfolio.loc[0, 'Finish_percentile'] + (slack_var / 20 * working_portfolio.loc[0, 'Finish_percentile'])
for i in range(1, len(working_portfolio)):
if working_portfolio.loc[i, 'Finish_percentile'] < curr_own_type_max:
rows_to_drop.append(i)
else:
curr_own_type_max = working_portfolio.loc[i, 'Finish_percentile'] + (slack_var / 20 * working_portfolio.loc[i, 'Finish_percentile'])
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)