optimise_team: Optimise team

View source: R/optimise_team.R

optimise_teamR Documentation

Optimise team

Description

Solves the optimisation problem for a FPL team given a budget constraint, amount of players, and objective function.

Usage

optimise_team(
  objective = "points",
  bank = 1000,
  bench_value = 170,
  gk = 1,
  def = 3,
  mid = 4,
  fwd = 3,
  min_games = 1,
  custom_df = F,
  expected_points_adjust = F,
  ...
)

Arguments

objective

takes value 'points', 'ppg' or 'vapm', indicating whether we want to maximise the total points obtained over the course of the dataset (season), the points per game played, or value added per million.

bank

takes a numeric value indicating the budget available for our full team (team + bench). Enter the value in four digits so 100.0m would be 1000 - the default for the season start.

bench_value

before running the optimiser you'll want to have chosen your bench already (there is little point in optimising players on your bench as they will not earn you points a lot of the time). Enter the value of your chosen bench in four digits as per the bank parameter.

gk

number of goalkeepers we want to pick - most likely one. If rotating keepers, it can be useful to pick your goalkeepers and add both to your bench value, then set gk = 0. This prevents the goalkeeper being optimised as if it were in goal as set and forget.

def

number of defenders to pick in our optimal solution

mid

number of midfielders to pick in our optimal solution

fwd

number of forwards to pick in our optimal solution

min_games

the minimum number of games a player must have played to be considered for selection. This should be set when the objective function is 'ppg' so that players with high points per game but with relatively few games played are avoided.

custom_df

defaults to FALSE. If you want to make adjustments to the player data before optimising (eg. you want to exclude certain players from consideration) you can use the fetch_player_data() function and update the resulting dataset yourself. This dataset can be passed as the custom_df parameter.

expected_points_adjust

defaults to FALSE. Should we adjust points and points per game for the xA / xG? Data comes from understat.

Value

a data.frame of optimised solution.

Examples

df <- fetch_player_data()

# RUN OPTIMISATION  ON POINTS PER GAME FOR A 4-3-3 formation, with a bench value of 175 and minimum games of 13
result <- optimise_team(objective = 'ppg', custom_df = FALSE, bench_value = 175, gk = 1, def = 4, mid = 3, fwd = 3, min_games = 13)
sum(result$points_per_game)


# RUN OPTIMISATION  ON TOTAL POINTS FOR A 3-4-3 formation, with a bench value of 170
result <- optimise_team(objective = 'points', custom_df = FALSE, bench_value = 170, gk = 1, def = 3, mid = 4, fwd = 3)
sum(result$total_points)

# USING CUSTOM DATA TO FILTER OUT UNWANTED RESULTS
library(dplyr)
df <- fetch_player_data() %>%
  # must have played more than 13 games
  filter(games >= 13) %>%
  # I don't want to consider Milivojevic or Alonso
  filter(! id %in% c(134, 103))
# RUN OPTIMISATION WITH CUSTOM DATA (using custom_df = df option)
result <- optimise_team(objective = 'ppg', custom_df = df, bench_value = 175, gk = 1, def = 4, mid = 4, fwd = 2, min_games = 14)
sum(result$points_per_game)






Chrisjb/fploptimiser documentation built on Sept. 14, 2022, 8:50 a.m.