DFS_Portfolio_Manager / global_func /hedging_preset.py
James McCool
Update import statements in hedging_preset.py to reflect new module structure. This change ensures proper access to small_field_preset and large_field_preset functions, enhancing code organization and maintainability.
10c821a
raw
history blame
1.66 kB
import pandas as pd
import math
from global_func.small_field_preset import small_field_preset
from global_func.large_field_preset import large_field_preset
def hedging_preset(portfolio: pd.DataFrame, lineup_target: int, projections_file: pd.DataFrame):
excluded_cols = ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Stack', 'Size', 'Win%', 'Lineup Edge', 'Weighted Own', 'Geomean', 'Similarity Score']
check_own_df = projections_file.copy()
check_own_df = check_own_df.sort_values(by='Own', ascending=False)
top_owned = check_own_df['player_names'].head(3).tolist()
concat_portfolio = pd.DataFrame(columns=portfolio.columns)
for players in top_owned:
working_df = portfolio.copy()
# Create mask for lineups that contain any of the removed players
player_columns = [col for col in working_df.columns if col not in excluded_cols]
remove_mask = working_df[player_columns].apply(
lambda row: not any(player in list(row) for player in players), axis=1
)
lock_mask = working_df[player_columns].apply(
lambda row: all(player in list(row) for player in players), axis=1
)
removed_df = working_df[remove_mask]
locked_df = working_df[lock_mask]
removed_lineups = small_field_preset(removed_df, math.ceil(lineup_target / 2), excluded_cols)
locked_lineups = large_field_preset(locked_df, math.ceil(lineup_target / 2), excluded_cols)
concat_portfolio = pd.concat([concat_portfolio, removed_lineups, locked_lineups])
return concat_portfolio.sort_values(by='median', ascending=False).head(lineup_target)