Fantasy Football Draft Optimization in R - HRUG
-
Upload
egoodwintx -
Category
Data & Analytics
-
view
310 -
download
2
Transcript of Fantasy Football Draft Optimization in R - HRUG
![Page 1: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/1.jpg)
Fantasy Football Draft Optimization in R
Ed Goodwin, CFA
![Page 2: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/2.jpg)
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](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/3.jpg)
Our League Rules
• Snake draft
• Standard ESPN scoring
• 9 starter players, and 7 bench players
![Page 4: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/4.jpg)
Number of hours of football Ed watched last season
0
![Page 5: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/5.jpg)
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](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/6.jpg)
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](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/7.jpg)
Constraints
• Time
• Knowledge
![Page 8: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/8.jpg)
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](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/9.jpg)
Exploratory Graphics• ggplot2
and dplyr
![Page 10: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/10.jpg)
![Page 11: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/11.jpg)
![Page 12: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/12.jpg)
Some good sources for fantasy football optimization
• fantasyfootballanalytics.com
• advancedfootballanalytics.com
• thehuddle.com
• fftoday.com
![Page 13: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/13.jpg)
My Solution
csv Data File
MySQL
Sequel Pro (UI)
R Linear Optimizer
ESPN Draft Site
![Page 14: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/14.jpg)
MySQL Database
![Page 15: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/15.jpg)
![Page 16: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/16.jpg)
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](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/17.jpg)
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](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/18.jpg)
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](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/19.jpg)
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](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/20.jpg)
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](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/21.jpg)
Set your constraints
![Page 22: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/22.jpg)
![Page 23: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/23.jpg)
Set rhs constraints
![Page 24: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/24.jpg)
Optimized Starter Team
![Page 25: Fantasy Football Draft Optimization in R - HRUG](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/25.jpg)
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](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/26.jpg)
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](https://reader031.fdocuments.us/reader031/viewer/2022030305/5871f23f1a28ab5c348b5c45/html5/thumbnails/27.jpg)
Next Steps
• Weekly projections to optimize waiver wire trades
• Screen scraping
• Bench optimization