Tuesday, October 20, 2015

DFS and Optimization: Simple Optimization

Now that we have data, let's actually get into the point of having this data: choosing what players to play each day. For our first go, we're going to take a simple approach. We'll start out with just pitchers and maximizing over just one metric, game score. This will allow us to get a refresher in how to run an optimization problem in R and create a set of code that we will be able build out in the future.

First step is merging the datasets that have the two data points we need. Using this dataset, we'll create an empty Integer Program. Our decision variables will be binary variables representing if we will choose that player or not. The IP will have two constraints:

  1. We must select 2 pitchers
  2. The total salary used must be below a threshold
Using lpSolve, we can construct the problem and solve it. The results are interesting as it's easy to see what players were optimal selection. That being said, this is just a start.


Tuesday, October 13, 2015

DFS and Optimization: Data

Like any analytics problem, let's start by getting our hands on data. For the optimization problem, we'll need at least two pieces of information:

  1. Salary information per player
  2. Player information (position, league)
  3. Player statistics / metrics to measure value

Ideally we could download this information straight from Draft Kings. However, I didn't want to create an account and it didn't seem straight forward. I took the easier route using Google to find someone that was already posting some of the data I needed.

Draft King Salaries

It was a bit difficult to access the salary information directly on draft kings, but RotoGuru is nice enough to post the daily data for us. Using the httr, dplyr and stringr packages was easy enough to scrape his website and pull down the salary data.

ESPN Game Score

Next up was some metrics and statistics for each player. My first though was go to ESPN, they have everything right? Well, yes, however, it wasn't easy to grab. Their daily notes section gives lots of tips on who to pick up, including a nice metric called Game Score for pitchers. Here's some code that we'll use to grab that data.

Fangraphs Advanced Metrics

Well, game score is certainly handy, but it'd be nice to have a great metric for hitters too. Since I'm a SABR person, I figured why not go for some advanced metrics. Fangraphs is a great site with articles discussing baseball in terms of advanced metrics and hosting an accompanying glossary for those unfamiliar with them. Here's the code for downloading that data:

Tuesday, October 6, 2015

Daily Fantasy Sports and Optimization

One of the newest trends in fantasy sports is the Daily Fantasy Sports (DFS) leagues such as Draft Kings. These leagues allow you to draft a new team each day with a set budget in order to fill out your team. Each league can be slightly different, but the general idea is the same: maximize the points each player can score for you while remaining under budget. This becomes an opportunity to find "deals" everyday so you can spend money on players likely to score you high points, while taking risks on cheaper players that might score above their usual production. The next few posts will talk about the data involved, analysis to determine useful data, and the optimization problem you can run every day to maximize output. As of right now, here's the few posts I plan to do in the near future:

  1. Downloading the data from ESPN, Draft Kings, and Fangraphs.
  2. Simple optimization over pitchers
  3. Good indicators of performance in that day's games
  4. Optimization of an entire team
  5. Adding a little uncertainty to the optimization
  6. Wrap up into a Shiny app
I hope that in the end you'll pick up on some useful R code and a little understanding of how you can use optimization in fantasy sports.