This repository is a collection of optimization tutorials and recipes for Fantasy Premier League (FPL).
Python code mainly use pandas for data management and sasoptpy for optimization modeling.
It is being actively developed. The content and the structure of the repository might change.
If you are interested in using optimization for FPL, see my YouTube tutorials on the subject.
Link: https://youtube.com/playlist?list=PLrIyJJU8_viOags1yudB_wyafRuTNs1Ed
Python tutorials include following topics
- Goalkeeper selection problem
- Single-period expected value maximization (squad, lineup, captain)
- Multi-period expected value maximization (squad, lineup, captain)
- Alternative solution generation
- Multi-objective optimization (2-Step and Weight methods)
- Bench decisions
- Auto-bench weights and iterative solution for nonlinear case
- Noise in expected values
- Sensitivity analysis
- Data collection from FPL API with login
- Wildcard (chip) optimization
Link: https://youtube.com/playlist?list=PLrIyJJU8_viOLw3BovPDx5QLKkCb8XOTp
My Excel tutorials are rather short but might give you an idea what optimization is capable of doing. Reach out to me if you need the raw data to give it a try.
- Goalkeeper selection problem
- Single-period expected value maximization (squad, lineup, captain)
- Multi-period expected value maximization (squad, lineup, captain)
You will need to follow steps below to install required platform and also optimization solver (CBC).
-
Download and install Python and Git to your machine
-
Download CBC optimization solver binary and add it to your environment path (example: https://youtu.be/DFXCXoR6Dvw?t=1642)
-
Clone the repository
git clone https://github.com/sertalpbilal/FPL-Optimization-Tools.git fpl-optimization -
Install required packages
cd fpl-optimization python -m pip install -r requirements.txt -
Download FPLReview projections and save it under
dataand rename it tofplreview.csv -
Navigate to
rundirectorycd ..\runAnd run either
solve_regular.py(for regular GW solve) orsolve_wildcard.py(for wildcard optimization)
See instructions below. -
Log in FPL from your browser and open https://fantasy.premierleague.com/api/my-team/MY_TEAM_ID/ after replacing
MY_TEAM_IDwith your team id. Copy the content of the page intorun\team.jsonfile, by creating one.A sample team.json file is provided for your reference:
team.json.sample
-
Edit content of
regular_settings.jsonfile{ "horizon": 5, "ft_value": 1.5, "itb_value": 0.2, "no_future_transfer": true, "randomized": false, "xmin_lb": 2, "banned": [], "locked": [], "delete_tmp": true, "secs": 300, "use_cmd": false, "future_transfer_limit": null, "no_transfer_gws": [], "booked_transfers": [], "use_wc": null, "use_bb": null, "use_fh": null, "chip_limits": {"bb": 0, "wc": 0, "fh": 0, "tc": 0}, "num_transfers": null, "hit_limit": null, "preseason": false, "cbc_path": "" }horizon: length of planning horizonft_value: value assigned to the extra free transferitb_value: value assigned to having 1.0 extra budgetno_future_transfer:trueorfalsewhether you want to plan future transfers or notrandomized:trueorfalsewhether you would like to add random noise to EVxmin_lb: cut-off for dropping players below this many minutes expectationbanned: list of banned player IDslocked: list of player IDs to always have during the horizon (e.g.233for Salah)delete_tmp:trueorfalsewhether to delete generated temporary files after solvesecs: time limit for the solve (in seconds)use_cmd: whether to useos.systemorsubprocessfor running solver, default isfalsefuture_transfer_limit: upper bound how many transfers are allowed in future GWsno_transfer_gws: list of GW numbers where transfers are not allowedbooked_transfers: list of booked transfers for future gameweeks. needs to have agwkey and at least one oftransfer_inortransfer_outwith the player ID (e.g.233for Salah),use_wc: GW to use wildcard (fixed)use_bb: GW to use bench boost (fixed)use_fh: GW to use free hit (fixed)chip_limits: how many chips of each kind can be used by solver (you need to set it to at least 1 when force using a chip)num_transfers: fixed number of transfers for this GWhit_limit: limit on total hits can be taken by the solver for entire horizonpreseason: solve flag for GW1 where team data is not importantcbc_path: binary location of the cbc solver (binfolder)
-
Run the multi-period optimization
python solve_regular.py
-
Find the optimal plans under
run\resultsdirectory with timestamp> cd results > ls regular_2021-11-04_10-00-00.csv