dfspy
is a Daily Fantasy Sports lineup optimization package for Python.- The main optimization algorithm scrapes current data from web sources, and uses machine learning algorithms and convex optimization to return optimal lineups for the current NFL week.
Table of contents
From terminal:
git clone https://github.com/jason-r-becker/dfspy.git
Using Anaconda, from terminal:
cd dfspy/
conda create -n dfspy python=3.7
source activate dfspy
pip install -U pip
pip install -r requirements.txt
The data directory organization is shown below, structured
<season year>/<week>/<player position>/<source>.csv
.
Source name files contain projections from said source whereas STATS.csv
contains the true realized stats. Week 0 refers to full season projections/stats.
data
├── 2016
├── 2017
└── 2018
├── 0
├── 1
├── ...
└── 17
├── DST
├── K
├── QB
├── RB
├── TE
└── WR
├── CBS.csv
├── ESPN.csv
├── FFToday.csv
├── FantasyPros.csv
├── NFL.csv
├── RTSports.csv
├── STATS.csv
└── Yahoo.csv
Historical projections and stats as well as current projections can be scraped
with the scrape_data.py
module. The following command line options are
used to specify scraping parameters.
Setting | Command Line Keyword | Default |
---|---|---|
Sources | -s, --sources | All Projection Sources |
Week(s) of the season | -w, --weeks | Current Week |
Season Year(s) | -y, --years | Current Season |
For example, scraping projections for the current week can be accomplished:
python scrape_data.py
To specify historical projections to scrape, command line options can be used. To scrape full season projections from 2018:
python scrape_data.py -w 0 -y 2018
Similarly for all individual weeks (or specified weeks):
python scrape_data.py -w 1-17 -y 2018
All data (full season and weekly) for given years can also be scaped:
python scrape_data.py -w all -y 2016-2018
Finally, true realized stats can be scraped by specifying the source. Similarly any individual source can be scraped.
python scrape_data.py -w all -y 2016-2018 -s STATS
All source code is hosted on GitHub. Contributions are welcome.
The main developer(s):