The goal of coach is to provide functions to optimize lineups for a variety of sites (draftkings, fanduel, fantasydraft) and sports (nba, mlb, nfl, nhl). Not every site/sport combination has been created yet. If you want something added, file an issue.
You can install the released version of coach from github with:
devtools::install_github("zamorarr/coach")
Load the library.
library(coach)
Load lineup data exported from a fantasy site and read it in. Check the documention of the read_*_*
functions for instructions on how to export the data. For example, for Draftkings you have to goto https://www.draftkings.com/lineup/upload and select the sport and slate data to export.
data <- read_dk("mydata.csv")
print(data)
#> # A tibble: 1,015 x 7
#> player_id player team position salary fpts_avg fpts_proj
#> <chr> <chr> <chr> <chr> <int> <dbl> <dbl>
#> 1 11191729 Le'Veon Bell PIT RB 9400 24.7 NA
#> 2 11192254 Todd Gurley II LAR RB 9300 26.5 NA
#> 3 11191754 David Johnson ARI RB 8800 14 NA
#> 4 11191533 Antonio Brown PIT WR 8600 24.6 NA
#> 5 11192632 Alvin Kamara NO RB 8500 19.9 NA
#> 6 11191840 DeAndre Hopkins HOU WR 8300 21.7 NA
#> 7 11192079 Davante Adams GB WR 7800 16.1 NA
#> 8 11192140 Michael Thomas NO WR 7800 17.6 NA
#> 9 11192363 Ezekiel Elliott DAL RB 7700 21.9 NA
#> 10 11193133 Julio Jones ATL WR 7600 17.3 NA
#> # ... with 1,005 more rows
Add your custom projections into a column called fpts_proj
. This is very important! If your projections aren’t good then your optimized lineups won’t be good either. For this example we’ll just add some random noise to the player’s season average fantasy points.
n <- nrow(data)
data$fpts_proj <- rnorm(n, data$fpts_avg)
print(data)
#> # A tibble: 1,015 x 7
#> player_id player team position salary fpts_avg fpts_proj
#> <chr> <chr> <chr> <chr> <int> <dbl> <dbl>
#> 1 11191729 Le'Veon Bell PIT RB 9400 24.7 25.2
#> 2 11192254 Todd Gurley II LAR RB 9300 26.5 26.4
#> 3 11191754 David Johnson ARI RB 8800 14 13.8
#> 4 11191533 Antonio Brown PIT WR 8600 24.6 24.4
#> 5 11192632 Alvin Kamara NO RB 8500 19.9 19.5
#> 6 11191840 DeAndre Hopkins HOU WR 8300 21.7 22.6
#> 7 11192079 Davante Adams GB WR 7800 16.1 15.2
#> 8 11192140 Michael Thomas NO WR 7800 17.6 16.9
#> 9 11192363 Ezekiel Elliott DAL RB 7700 21.9 21.7
#> 10 11193133 Julio Jones ATL WR 7600 17.3 14.6
#> # ... with 1,005 more rows
Build a fantasy model. This model contains all the constraints imposed by the site and sport.
model <- model_dk_nfl(data)
Generate three optimized lineups using your projections and the fantasy model
optimize_generic(data, model, L = 3)
#> [[1]]
#> # A tibble: 9 x 7
#> player_id player team position salary fpts_avg fpts_proj
#> <chr> <chr> <chr> <chr> <int> <dbl> <dbl>
#> 1 11192254 Todd Gurley II LAR RB 9300 26.5 26.4
#> 2 11191533 Antonio Brown PIT WR 8600 24.6 24.4
#> 3 11191859 Odell Beckham Jr. NYG WR 7000 18.5 19.7
#> 4 11192767 Deshaun Watson HOU QB 6700 26.3 26.4
#> 5 11191861 Jarvis Landry CLE WR 5500 16.4 16.5
#> 6 11191680 Chris Thompson WAS RB 4700 15.9 15.8
#> 7 11191758 Cameron Brate TB TE 3000 8.94 10.4
#> 8 11191868 Kapri Bibbs WAS RB 3000 13.6 14.5
#> 9 11191358 Buccaneers TB DST 2000 6.75 9.66
#>
#> [[2]]
#> # A tibble: 9 x 7
#> player_id player team position salary fpts_avg fpts_proj
#> <chr> <chr> <chr> <chr> <int> <dbl> <dbl>
#> 1 11191533 Antonio Brown PIT WR 8600 24.6 24.4
#> 2 11191859 Odell Beckham Jr. NYG WR 7000 18.5 19.7
#> 3 11192543 Kareem Hunt KC RB 6900 19.3 21.0
#> 4 11192767 Deshaun Watson HOU QB 6700 26.3 26.4
#> 5 11191538 Travis Kelce KC TE 6400 16.4 17.8
#> 6 11191861 Jarvis Landry CLE WR 5500 16.4 16.5
#> 7 11191367 Frank Gore MIA RB 3700 11.2 13.4
#> 8 11191868 Kapri Bibbs WAS RB 3000 13.6 14.5
#> 9 11191358 Buccaneers TB DST 2000 6.75 9.66
#>
#> [[3]]
#> # A tibble: 9 x 7
#> player_id player team position salary fpts_avg fpts_proj
#> <chr> <chr> <chr> <chr> <int> <dbl> <dbl>
#> 1 11192254 Todd Gurley II LAR RB 9300 26.5 26.4
#> 2 11191533 Antonio Brown PIT WR 8600 24.6 24.4
#> 3 11191859 Odell Beckham Jr. NYG WR 7000 18.5 19.7
#> 4 11192767 Deshaun Watson HOU QB 6700 26.3 26.4
#> 5 11191861 Jarvis Landry CLE WR 5500 16.4 16.5
#> 6 11191367 Frank Gore MIA RB 3700 11.2 13.4
#> 7 11193209 Eagles PHI DST 3000 10.8 11.7
#> 8 11191758 Cameron Brate TB TE 3000 8.94 10.4
#> 9 11191868 Kapri Bibbs WAS RB 3000 13.6 14.5