DimaKudosh / pydfs-lineup-optimizer

Daily Fantasy Sports lineup optimzer for all popular daily fantasy sports sites
MIT License
418 stars 157 forks source link

Max Team Exposure #95

Closed austinjohnson closed 4 years ago

austinjohnson commented 4 years ago

Is there a way to remove pitchers from the player pool that is counted as max team exposure. Here is my reason, you can easily control pitcher max exposure by just setting their exposure by name or in a spreadsheet, however batters takes more work because there are more of them. The reason is because tonight I set Miami max exposure to 10% and the pitcher took up most of this exposure. I would rather batters take up the exposure than the Pitcher.

BenikaH commented 4 years ago

I'm interested in this as well. Maybe we can add a set team max exposure function?

DimaKudosh commented 4 years ago

Max exposure for teams counted for team stacks, so if you want to exclude pitchers from team exposure you should exclude pitchers from stacks. Single users isn't used for team exposures.

@BenikaH Team exposure was added in previous release https://pydfs-lineup-optimizer.readthedocs.io/en/latest/rules.html#teams-exposures

BenikaH commented 4 years ago

Didn't see that. Thanks Dima!

austinjohnson commented 4 years ago
import pulp
from pulp.solvers import CPLEX_PY
from pydfs_lineup_optimizer import get_optimizer, Site, Sport,CSVLineupExporter
from pydfs_lineup_optimizer.solvers.pulp_solver import PuLPSolver
import time

start_time = time.time()
class CustomPuLPSolver(PuLPSolver):
    LP_SOLVER = pulp.CPLEX_PY(msg=0)
optimizer = get_optimizer(Site.FANDUEL, Sport.BASEBALL, solver=CustomPuLPSolver)
optimizer.load_players_from_csv("/Users/austi/Desktop/FantasySports/MLB/Daily_Data/PLAYERS_LIST.csv")
optimizer.restrict_positions_for_opposing_team(['P'], ['1B','C','2B','3B','SS','OF','UTIL'])
optimizer.set_team_stacking([4], for_positions=['1B', '2B', '3B', 'C', 'SS', 'OF','UTIL'])
lineups = optimizer.set_deviation(0.3, 0.3)
optimizer.set_teams_max_exposure(
    {
       'LOS':   0.02, 'SEA': 0.02, 'ATL': 0.02,
       'TEX':   0.03, 'TOR': 0.04, 'WAS': 0.04,
       'CWS':   0.04, 'NYM': 0.04, 'STL': 0.04,
       'OAK':   0.04, 'PHI': 0.04, 'CHC': 0.04,
       'KAN':   0.04, 'COL': 0.04, 'MIA': 0.04,
       'SFG':   0.04, 'ARI': 0.05, 'PIT': 0.05,
       'LAA':   0.05, 'BAL': 0.05, 'HOU': 0.05,
       'TAM':   0.05, 'NYY': 0.06, 'SDP': 0.07,
    })
lineups = list(optimizer.optimize(150, max_exposure=.4, randomness=True))
for lineup in lineups:
    print(lineup)
exporter = CSVLineupExporter(lineups)
exporter.export('MLB_result_new.csv')
print(round(((time.time() - start_time)/60)), "minute run time")
austinjohnson commented 4 years ago

MLB_result_new.xlsx

austinjohnson commented 4 years ago

PLAYERS_LIST.xlsx

austinjohnson commented 4 years ago

@DimaKudosh I don't know if I made a mistake or if the team exposure doesn't work how I think it does, but using this code and the player list the max exposures don't match up

DimaKudosh commented 4 years ago

Team exposure works only with stacking, in your code sample you set stack with 4 players, so exposure for team will be number of lineups where 4 players with positions ['1B', '2B', '3B', 'C', 'SS', 'OF','UTIL'] from team / total lineups. Pitchers are not counted in your case