## Saturday, July 30, 2011

### Fantasy Football Optimisation

Some friends challenged me to a game called fantasy "football" where you pretend to be a Russian billionaire. Not the bit where you steal natural resources off the population but where you buy a bunch of poncy overpaid foreigners who flounce around and earn insane amounts of money.

While I'm ranting about "football". Why do football ads always say it has "the beauty of a dance". If you like dancing that much go to the ballet

Anyway So I have to pretend to know something about this "football" which I dont but I do know a bit about optimization and more about copying stuff. I remembered this old R package article about optimising for fantasy football. This was written by prasoonsharma and I have just reused his code.

I scraped last seasons scores off the fantasy premierleague website. Some parsing turned this into the correct format. You can download the cleaned up data here

The constraints for this version of the game are slightly different than the one prasoonsharma was playing. This means you need more goalies, have more money to spend on players and other such changes.

The best single team for last season would have been
`        Player Club Pos Price Pts1         Hart  MCI  GK    70 1755     Al-Habsi  WIG  GK    45 12548    Ivanovic  CHE DEF    70 14449        Huth  STO DEF    60 13851      Hughes  FUL DEF    50 12954    Bardsley  SUN DEF    50 12355     Johnson  WOL DEF    50 120197       Adam  LIV MID    90 192200    Dempsey  FUL MID    85 168201   N'Zogbia  WIG MID    75 167210     Jarvis  WOL MID    60 133212     Barton  NEW MID    60 131386   Berbatov  MUN STR    95 176388 Odemwingie  WBA STR    75 171393   Davies K  BOL STR    65 132`

with a total score of 2224 points. You get to change the team every week in the real game. This optimisation is just if you got to pick one team and leave it.

Picking a fantasy football team involves
1. Predicting how many points each player will score that week
2. Optimising based on this prediction so you pick the team that covers all the rule constraints that scores the most points.

This code carries out the second part. If you have a prediction for how many points players will score that is better than
"exactly the same amount they scored last season" you can change the data with your new prediction and run it (or I can run it for you if you want). A web app that allowed you to enter your player score predictions and ran an optimisation so that the best team that could be picked based on your predictions was then created might be useful. If you save the data in a new google doc and change the Pts values to your player predictions. Then post a link to that google doc in the comments I will run the optimisation for you.