Skip to content

A collection of tutorials and recipes to use optimization for winning Fantasy Premier League :)

License

Notifications You must be signed in to change notification settings

mn047/FPL-Optimization-Tools

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FPL Optimization Repository

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.

Tutorials

If you are interested in using optimization for FPL, see my YouTube tutorials on the subject.

Python

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

Excel

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)

Instructions

Steps

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 without sample extension

    cd data
    cp login.json.sample login.json
  • Download FPLReview projections and save it under data and rename it to fplreview.csv

  • Edit values inside login.json file:

    {
      "email": "[email protected]",
      "password": "mypassword"
    }
  • Navigate to run directory

    cd ..\run

    And run either solve_regular.py (for regular GW solve) or solve_wildcard.py (for wildcard optimization)
    See instructions below.

Multi-period GW optimization

  • 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 horizon
    • ft_value: value assigned to the extra free transfer
    • itb_value: value assigned to having 1.0 extra budget
    • no_future_transfer: true or false whether you want to plan future transfers or not
    • randomized: true or false whether you would like to add random noise to EV
    • banned: list of banned player IDs
    • locked: list of player IDs to always have during the horizon (e.g. 233 for Salah)
    • delete_tmp: true or false whether to delete generated temporary files after solve
    • secs: time limit for the solve (in seconds)
    • use_cmd: whether to use os.system or subprocess for running solver, default is false
    • future_transfer_limit: upper bound how many transfers are allowed in future GWs
    • no_transfer_gws: list of GW numbers where transfers are not allowed
    • booked_transfers: list of booked transfers for future gameweeks. needs to have a gw key and at least one of transfer_in or transfer_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 GW
    • hit_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
    

License

Apache-2.0 License

About

A collection of tutorials and recipes to use optimization for winning Fantasy Premier League :)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 82.6%
  • Python 17.4%