KnapKings: DFS Optimizer

CS701 Final Project Report

Greg Dray Dylan Mortimer Middlebury College Middlebury College Middlebury, VT Middlebury, VT [email protected] [email protected]

ABSTRACT players the chance to treat each day as a new season with a In our project we focused on the problem of daily fantasy chance at instant gratification and monetary prizes. Daily sports (DFS) lineup optimization and the open source ac- fantasy’s cash prizes have enticed many to contribute to the cessibility of such optimization. DFS websites are generally $3 billion plus that the industry takes in as entry fees each dominated by a very small percentage of users who pay a ma- year. Not all that surprisingly thanks to the huge poten- jority of entry fees and account for the majority of winnings. tial payouts, DFS are dominated by a minority of ‘sharks’ These players presumably often use optimization methods who make up a majority of the entry fees and win a dispro- themselves. The ultimate goal of our project was to create a portionately large percentage of prizes. The dominance of collection of accessible and user friend software tools to pro- these sharks make it notoriously difficult for casual players vide users looking to play DFS casually a better opportunity to enjoy success on sites like DraftKings and Fanduel. for success. In creating our own optimizer, we took a dy- The inspiration for this project came from wanting to con- namic programming approach, implementing a customized tribute to a package of tools that could level the playing version of the 0-1 Knapsack Algorithm. The algorithm was field for casual DFS players to any nontrivial degree. In able to take player projections, player salaries, positions to recent years many have suggested that anyone (the sharks be filled, and budget as inputs and output a lineup opti- excluded) playing DFS is a ‘sucker’ and destined to lose in mized with respect to total projected points. In an attempt the long run. We’ve attempted to give the so-called ‘suckers’ to make our optimizer accessible and easy to use for anyone a chance by providing functionality to optimize daily fantasy we built a collection of functions into a Python package and lineups with respect to total projected fantasy points. This uploaded it to pip, called KnapKings. The package includes isn’t a novel idea in and of itself. Many lineup optimizers a driver program that allows users to see their customized already exist for public use. The problem is that the major- daily optimized lineups after choosing parameters like sport, ity of these tools cost a subscription fee or have ‘premium fantasy platform and projection system. Using the driver features’. In our eyes, ‘casual’ players shouldn’t need to program, users can also directly influence the outcome of pay $300 a year to have a fighting chance at breaking even. lineups by ‘locking’ or ‘dropping’ players, all without need- We’ve created our own lineup optimizer made up of an auto- ing to interact with the actual code. In order to make our mated data scraping/aggregating process, user-driven player optimizer useful for casual players we aggregated the nec- pool customization functionality, and a dynamic program- essary input data ourselves by scraping projections, prices, ming 0-1 Knapsack optimizing algorithm. This paper will and other necessary data from various online resources. In cover each part of our optimization pipeline in greater detail, about three weeks of testing the long-term success of enter- discuss the actual success that lineups generated by our op- ing our optimizer’s lineups in single-entry $1 competitions, timizer have had in competitions, and evaluate the viability we found the optimizer appeared to win money in competi- of our optimizer as a useful daily fantasy tool. tions more often than not, leading to long term net-winnings. We are encouraged by these results and are hopeful that we 2. PROBLEM STATEMENT have in fact created a set of tools that can fairly easily allow Our project aimed to create a set of tools to algorithmi- inexperienced daily fantasy players (e.g. ourselves) to enjoy cally generate winning DFS lineups. We focused on NBA success while still allowing for user input and control. competitions because there were consistently NBA competi- tions being held to test on. We also focused on single-entry Keywords Tournament competitions and single-entry 50/50 competi- tions. Single-entry Tournament competitions involve each CS701; LATEX; entrant being able to submit one lineup with winnings being awarded based on where each lineup places. In single-entry 1. INTRODUCTION 50/50 competitions each entrant can submit one lineup and Since their rise to popularity, DFS platforms DraftKings the top 50% of lineups win a certain amount. We tested and Fanduel have revolutionized the fantasy sports industry. on only $1 competitions so payouts for 50/50 competitions Unlike the traditional fantasy sports format where players were always $1.80. We decided to focus on single-entry and join a league and draft a team at the beginning of the year, $1 competitions due to funding constraints (we didn’t get sticking with that same team all year with the ability to add, any). drop, and trade players, DraftKings and Fanduel have given To be valid entries, lineups need to follow three main con- straints. The sum of salaries of all players in a lineup must dynamic programming approach is much faster than any be less than or equal to the competition’s ‘salary cap’. The greedy approach and we estimate that any advantage in ac- salary cap is generally $50,000 for DraftKings and $60,000 curacy that a greedy approach has in theory is probably for Fanduel. All positions must be filled. Lineups can- negated when so many constraints have to be put in place not contain more than four players from one team. Our to make its runtime reasonable. project focused on implementing a modified dynamic pro- gramming 0-1 Knapsack algorithm to generate the optimal lineup, given these constraints. As input, our algorithm 4. METHODS needed to take in the list of players available for each lineup position, each player’s salary, and each player’s projected 4.1 Web Scraping and Data Processing fantasy points. We also wanted to be able to generate mul- The first implementation step was to get player data. tiple optimized lineups to assist users in multi-entry compe- Specifically, we needed the following: titions. In order to utilize our algorithm we needed to collect and • Name: Essential for returning a coherent lineup to the clean the data necessary to input. We needed to find data user. sources with player salaries, projections, and eligible posi- tions. We then needed to find a way to scrape or request • Salary: how much the player costs to hire. This de- the data and clean and package it into a format digestible pends on his recent performance and other proprietary by our implemented knapsack algorithm. metrics. Set by each fantasy contest website. A final but important sub problem was giving users the ability to influence the lineup generating process by ‘locking’ • Position: what position the player plays in the game. players into their lineups or excluding them from the player This depends on the fantasy contest website, as DraftK- pool fed to our algorithm. ings allows players to be hired for more than one po- All of the functionality described in this section also needed sition (but not be hired twice in the same lineup), but to be packaged in a user-friendly but malleable form. We Fanduel only allows players one specific position. decided to aim to build a Python package with functionality to let the user generate lineups with minimal execution of • Projection: expected number of fantasy points the code while also allowing the user to implement the use of player will score in a specific slate of games. Based alternative data sources or to optimize for different sports on proprietary data/algorithms and no objective mea- and different types of competitions. sure exists. • Team: requ