pydfs-lineup-optimizer
pydfs-lineup-optimizer copied to clipboard
Set specific ownership for certain numbers of players
Would it be possible to add a constraint to plug in a certain number of players that are below the ownership requirement? For example let's say I want three players out of my lineup to all be under 10% owned or I want one player under 10% owned and one player at under 4% owned.
Example:
optimer.set_ownership_cap_for_player(1, .10) # one player under 10% owned
optimer.set_ownership_cap_for_player(1, .04) # one player under 4% owned
Example 2:
optimer.set_ownership_cap_for_player(3, .10) # three players all under 10% owned
I'd do this at the front end by giving a projection boost to players with low ownership projections and a penalty for high ownership projections. You could run the optimizer multiple times and aggregate the lineups from applying different boost/penalty functions. This will create the desired effect or come close to it without needing any changes to the library.
Otherwise, the code conceptually is a constraint that the sum of players with max_ownership <= low_ownership_threshold must be >= min_owned_player_number. This is pseudo-code below, as I don't think it is a sum and the variable name is incorrect.
class MinOwnedPlayerRule(OptimizerRule):
def apply(self, solver):
if not self.optimizer.min_owned_player_pct and self.optimizer.min_owned_player_number:
return
min_owned_players = [variable for player, variable in self.players_dict.items()
if player.max_ownership <= self.optimizer.min_owned_player_pct]
solver.add_constraint(min_owned_players, None, SolverSign.GTE, self.optimizer.min_owned_player_number,
name='min_owned_player_%s' % ) # unsure what variable name should be here
The problem with changing projections is I don't want an entire lineup of low owned players. I just want x amount set to my preference and then the rest let the optimizer handle.
You won't end up with an entire lineup of low-owned players if you don't want to. The penalty can be large or small depending on the penalty function you use. For example, if you apply a penalty that is the logarithm of 1 - projected_ownership (as a decimal not an integer), then the penalty for .05 ownership is -0.05 and the penalty for .25 ownership is 0.29, which gives a relative boost of .24 to the low-owned player, which could get him or her into some lineups but won't lead to a lineup full of marginal players.
You may have to experiment a bit to get the results you are looking for, but that is true of the % ownership and # of players below that threshold, the values of which are highly speculative and require experimentation to get correct. How did you choose 10% and 3 players instead of 9.2% and 2 players? I'm not aware of a rigorous method to choose those numbers, so it had to be from trial and error and it probably varies based on the week, the sport, etc.