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
-
Navigate to
data
directory and copy login file withoutsample
extensioncd data cp login.json.sample login.json
-
Download FPLReview projections and save it under
data
and rename it tofplreview.csv
-
Edit values inside
login.json
file:{ "email": "[email protected]", "password": "mypassword" }
-
Navigate to
run
directorycd ..\run
And run either
solve_regular.py
(for regular GW solve) orsolve_wildcard.py
(for wildcard optimization)
See instructions below.
-
Edit content of
regular_settings.json
file{ "horizon": 5, "ft_value": 1.5, "itb_value": 0.2, "no_future_transfer": false, "randomized": false, "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, }
horizon
: length of planning horizonft_value
: value assigned to the extra free transferitb_value
: value assigned to having 1.0 extra budgetno_future_transfer
:true
orfalse
whether you want to plan future transfers or notrandomized
:true
orfalse
whether you would like to add random noise to EVbanned
: list of banned player IDslocked
: list of player IDs to always have during the horizon (e.g.233
for Salah)delete_tmp
:true
orfalse
whether to delete generated temporary files after solvesecs
: time limit for the solve (in seconds)use_cmd
: whether to useos.system
orsubprocess
for running solver, default isfalse
future_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 agw
key and at least one oftransfer_in
ortransfer_out
with the player ID (e.g.233
for 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 horizon
-
Run the multi-period optimization
python solve_regular.py
-
Find the optimal plans under
run\results
directory with timestamp> cd results > ls regular_2021-11-04_10-00-00.csv