fantasy football draft optimization in r - hrug

27
Fantasy Football Draft Optimization in R Ed Goodwin, CFA

Upload: egoodwintx

Post on 08-Jan-2017

310 views

Category:

Data & Analytics


2 download

TRANSCRIPT

Page 1: Fantasy Football Draft Optimization in R - HRUG

Fantasy Football Draft Optimization in R

Ed Goodwin, CFA

Page 2: Fantasy Football Draft Optimization in R - HRUG

What is this fantasy football stuff anyway?

• All participants compete in a league, and draft players from the NFL in a virtual draft. Based on the real life performance of the athletes, participants score points. Each league can have different rules around scoring, drafting, and trading players.

Page 3: Fantasy Football Draft Optimization in R - HRUG

Our League Rules

• Snake draft

• Standard ESPN scoring

• 9 starter players, and 7 bench players

Page 4: Fantasy Football Draft Optimization in R - HRUG

Number of hours of football Ed watched last season

0

Page 5: Fantasy Football Draft Optimization in R - HRUG

The problems to solve?

• How do we rank players for each position?

• How do we choose the best team?

• How do we handle the realities of a live draft? Everyone is trying to draft the best available players every round.

Page 6: Fantasy Football Draft Optimization in R - HRUG

Workflow• Think about the problem and

come up with some initial thoughts

• Read a lot of blogs on fantasy football

• Prototype and iterate

• Test

• Revise

Page 7: Fantasy Football Draft Optimization in R - HRUG

Constraints

• Time

• Knowledge

Page 8: Fantasy Football Draft Optimization in R - HRUG

Initial Thoughts• Where do we get data? Screen scraping

• How to determine the best players to draft? Use historic data to forecast performance

• How do we pick the best team? Optimize for the best risk adjusted score (whatever that means)

• How do we handle the draft? Need to recalculate the best team based on who has been selected already

Page 9: Fantasy Football Draft Optimization in R - HRUG

Exploratory Graphics• ggplot2

and dplyr

Page 10: Fantasy Football Draft Optimization in R - HRUG
Page 11: Fantasy Football Draft Optimization in R - HRUG
Page 12: Fantasy Football Draft Optimization in R - HRUG

Some good sources for fantasy football optimization

• fantasyfootballanalytics.com

• advancedfootballanalytics.com

• thehuddle.com

• fftoday.com

Page 13: Fantasy Football Draft Optimization in R - HRUG

My Solution

csv Data File

MySQL

Sequel Pro (UI)

R Linear Optimizer

ESPN Draft Site

Page 14: Fantasy Football Draft Optimization in R - HRUG

MySQL Database

Page 15: Fantasy Football Draft Optimization in R - HRUG
Page 16: Fantasy Football Draft Optimization in R - HRUG

Linear Optimizer

• Uses RMySQL package to connect to database

• Uses Rglpk to run the linear optimization

Page 17: Fantasy Football Draft Optimization in R - HRUG

Linear Optimizer Logic• Select two sets of players from the database

• Players that are still available to draft

• Players that I have drafted

• Set rules based on whether I am filling my starting lineup or filling my bench

• Based on the number of open slots I have on my team, select players to draft for the open slots that

• Maximizes my expected points

• Keeps my risk within a stated threshold

• Satisfies the rules about what positions can make up a team

Page 18: Fantasy Football Draft Optimization in R - HRUG

RMySQL• Package to connect to

MySQL databases

• Use dbConnect() function to establish connection

• Use dbGetQuery() function to run SQL statements against database

Page 19: Fantasy Football Draft Optimization in R - HRUG

Rglpk - R/GNU Linear Programming Kit

• Tools to create generalized linear models in R

• Rglpk_solve_LP() function used to solve for optimization with constraints

Page 20: Fantasy Football Draft Optimization in R - HRUG

Rglpk_solve_LP() requires:

• obj vector you are trying to maximize

• mat matrix of constraints

• dir vector of constraint “directions” (i.e. “>=“, “==“, or “<“, etc.)

• rhs vector of right hand side of the constraints

• types vector of character types of constraints (“B” for binary, “C” for continuous, “I” for integer)

• max specifies whether the goal is to maximize (“TRUE”) or minimize (“FALSE”) the solution

Page 21: Fantasy Football Draft Optimization in R - HRUG

Set your constraints

Page 22: Fantasy Football Draft Optimization in R - HRUG
Page 23: Fantasy Football Draft Optimization in R - HRUG

Set rhs constraints

Page 24: Fantasy Football Draft Optimization in R - HRUG

Optimized Starter Team

Page 25: Fantasy Football Draft Optimization in R - HRUG

Lessons Learned• Scrub your data

• Run mock drafts ahead of time

• Vet out your assumptions

• Think through the correlations

• Replacement value more important than point value

Page 26: Fantasy Football Draft Optimization in R - HRUG

Lessons Learned

• Shake out the optimization rules

• Don’t weight one team too heavy in your lineup

• There’s still a lot of luck involved (Andrew Luck)

Page 27: Fantasy Football Draft Optimization in R - HRUG

Next Steps

• Weekly projections to optimize waiver wire trades

• Screen scraping

• Bench optimization