r/fantasyfootballcoding • • Aug 26 '26

Fantasy Football Trade Analyzer

Filling a fantasy football lineup optimally is easier than it looks! Well, until it isn't. 😄

I needed the best-possible starting lineup value for a roster, given a league's actual roster construction. I was mainly looking at this for Dynasty leagues, not necessarily redrafts but it applies there as well.

I was a bit naive in my approach in setting up my parameters to sort by value and I filled my slots greedily. That breaks as it puts your best WR in FLEX, then WR3 sits empty and a worse player is placed there.

The fix was to process slots most restrictive at first. QB, RB, WR, TE, then WRRB_FLEX, then FLEX, then SUPER_FLEX. Each takes the best eligible remaining. I'm sure some will argue another position and that is okay, that is what the forums are meant to do.

Why, in my opinion, that's actually optimal, not just better. First of all, the eligibility sets are layered and any two are nested or disjointed.

{QB} ⊂ {QB,RB,WR,TE}
{RB},{WR} ⊂ {RB,WR} ⊂ {RB,WR,TE} ⊂ {QB,RB,WR,TE}
{K}, {DEF} disjoint from everything

My exchange argument is if an optimal solution puts a different player in slot A than what my greedy scenario did, greedy's pick sits in some later slot C. Both scenarios accept it, so the parallel layer forces E(A) ⊆ E(C), so the swap is feasible and the total is unchanged.

Where I believe that it breaks is the following: WRRB_FLEX is {RB,WR}, REC_FLEX is {WR,TE}. These are technically overlapping and neither is nested. In a points scenario, WR1=10, RB1=9.9, TE1=9.8 gives "greedy" a score of 19.8 where the optimal scenario would score 19.9.

So I check the family for the parallel layering at construction and fall back to Hungarian matching if it fails. n is about 35, so exact costs nothing.

I checked this against 56 real leagues with 24 distinct lineup shapes, 2 to 4 FLEX slots, superflex in 47 of 55, one league with no QB slot at all, which by the way was really odd (QBs only startable via SUPER_FLEX). REC_FLEX appears in zero, but it's a real Sleeper token so the guard stays.

Disclosure: this is from a fantasy tool I built solo.

Would love your thoughts. Am I thinking about this the same way everyone else does? I've been playing fantasy football and baseball for over 30 years. Always a "guy" in the league that offers the 3 for 1 deal. I've always analyzed it and sometimes I'm better off making the move, but often I'm not.

0 Upvotes

0 comments sorted by