fantasy football draft optimization in r - hrug

Post on 08-Jan-2017

310 Views

Category:

Data & Analytics

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Fantasy Football Draft Optimization in R

Ed Goodwin, CFA

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.

Our League Rules

• Snake draft

• Standard ESPN scoring

• 9 starter players, and 7 bench players

Number of hours of football Ed watched last season

0

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.

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

Constraints

• Time

• Knowledge

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

Exploratory Graphics• ggplot2

and dplyr

Some good sources for fantasy football optimization

• fantasyfootballanalytics.com

• advancedfootballanalytics.com

• thehuddle.com

• fftoday.com

My Solution

csv Data File

MySQL

Sequel Pro (UI)

R Linear Optimizer

ESPN Draft Site

MySQL Database

Linear Optimizer

• Uses RMySQL package to connect to database

• Uses Rglpk to run the linear optimization

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

RMySQL• Package to connect to

MySQL databases

• Use dbConnect() function to establish connection

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

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

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

Set your constraints

Set rhs constraints

Optimized Starter Team

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

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)

Next Steps

• Weekly projections to optimize waiver wire trades

• Screen scraping

• Bench optimization

top related