Special thanks to swanson, who authored this repo, which mine is heavily based off of.
Pre-reqs:
- Python 2 but NOT Python 3 compatible yet (currently working on implementation)
- ortools
pip install -r requirements.txt
To run, download your desired week's salaries on DraftKings, and then run:
bash scripts/prepare_nfl_contest_data.sh
Note that this script will error out if the CSV from DraftKings is not in ~/Downloads
.
Next, scrape data from FantasyPros or Rotogrinders and allow for some mismatched data between the two sources:
python optimize.py -mp 100 -s y -source nfl_rotogrinders
Or, use your own projection source:
python optimize.py -mp 100 -s n -projection_file "/Users/benbrostoff/Downloads/my_projections.csv"
Note that any projection file you provide must include playername
and points
as header names.
One important note here is that passing in y
for the scrape option will create current-projections.csv
. However, once you've scraped once, there's no need to do again.
Force a QB/WR or QB/TE combination from a particular team. For instance, if I wanted a guaranteed Cam Newton / Greg Olsen duo:
python optimize.py -mp 100 -duo CAR -dtype TE
Another example pairing Antonio Brown and Ben Roethlisberger:
python optimize.py -mp 100 -duo PIT -dtype WR
Limit same team representation except for QB / skill player combos. Example:
python optimize.py -mp 100 -limit y
Run the optimizer multiple times and continually eliminate pre-optimized players from the lineup. For instance, to run three different iterations and generate three different sets of players:
python optimize.py -i 3
At any time, you can get a list of all possible options via:
python optimize.py --help
DraftKings allows uploading up to 500 lineups using a single CSV file. You can learn more about DraftKings' support for lineup uploads here. This tool supports generating an uploadable CSV file containing the generated optimized lineups.
To use this feature:
- Download the weekly salaries CSV from DraftKings (containing player name, DK-estimated points, salary, etc).
- Run
bash scripts/prepare_<nba/nfl>_contest_data.sh
. - Download the CSV upload template and get the file location (probably something like
~/Downloads/DKSalaries.csv
). Note - this file has the same name as the weekly salaries CSV when downloaded from DraftKings, which can be confusing. - Run
python optimize.py -pids <upload_tpl_location>
. Remember to specify league, constraints, number of iterations to run, etc. - Upload the newly generated file to DraftKings from
data/current-upload.csv
.
One nice workflow is to run the optimizer with the -keep_pids
flag after you create your CSV; this option will put future optimizations in the same CSV file.
Projected ownership percentages as of this writing could be downloaded from DFS Report. If you download the CSV, you can filter on projected ownership percentage. For example, only include players below 15% owned.
python optimize.py -po_location 'data/ownership.csv' -po 15
An NBA option exists for NBA contests. After downloading the DraftKings salaries for a contest:
bash scripts/prepare_nba_contest_data.sh
Currently, Rotogrinders and Numberfire are the only available datasources:
python optimize.py -l NBA -source nba_rotogrinders
python optimize.py -l NBA -source nba_number_fire
A WNBA option is available, but users must provide their own projection source:
bash scripts/prepare_nba_contest_data.sh
python optimize.py -l WNBA -projection_file "/Users/benbrostoff/Downloads/my_projections.csv" -s No