Giter Site home page Giter Site logo

zlisto / daily-fantasy-baseball-contests-in-draftkings Goto Github PK

View Code? Open in Web Editor NEW
37.0 4.0 27.0 41 KB

This is the code for constructing a portfolio of lineups for DraftKings baseball contests with a top heavy payoff structure. This code is based on the paper Picking Winners Using Integer Programming by David Hunter, Juan Pablo Vielma, and Tauhid Zaman (https://arxiv.org/abs/1604.01455).

Julia 100.00%
fantasy-sports

daily-fantasy-baseball-contests-in-draftkings's Introduction

Fantasy Baseball Lineups Optimization Code

This is the code for constructing a portfolio of lineups for DraftKings baseball contests with a top heavy payoff structure. This code is based on the paper Picking Winners Using Integer Programming by David Hunter, Juan Pablo Vielma, and Tauhid Zaman. Below are details on the required software, and instructions on how to run different variations of the code.

Required Software

To start off, you should download Julia from the corresponding site above. Then, open Julia and run the following commands

julia> Pkg.add("JuMP")
julia> Pkg.add("DataFrames")
julia> Pkg.add("GLPKMathProgInterface")
julia> Pkg.add("MathProgBase")

As we noted in the paper, GLPK and Cbc are both open-source solvers. This code uses GLPK because we found that it was slightly faster in practice for the formulations considered. For those that want to build more sophisticated models, they can buy Gurobi. Please consult the JuMP homepage for details on how to use different solvers. JuMP makes it easy to change between a number of open-source and commercial solvers.

Downloading the Code

You can download the code and the example csv files by calling

$ git clone https://github.com/zlisto/dailyfantasybaseball

Alternatively, you can download the zip file from above.

Running the Code

Open the file optimize_multiple_lineups_baseball.jl. By default the code will create 150 lineups with a maximum overlap of 6 players between each lineup, and a stack of 5 consecutive batters. To change this, see lines 13, 16, and 19 in the file. For instance, if you want to create 10 lineups with a maximum overlap of 4 players, and a stack of 3 consecutive batters you change lines 13, 16, and 19 to the following

num_lineups = 10
num_overlap = 4
stack_size = 3

Lastly, you can change the path_pitchers, path_hitters, and path_to_output variables defined on line 25, 26, and 29 respectively, to the name of the corresponding files for the pitcher and hitter projections and the output lineups.

Good luck!

DK Mafia

daily-fantasy-baseball-contests-in-draftkings's People

Contributors

zlisto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

daily-fantasy-baseball-contests-in-draftkings's Issues

Customization questions

New Julia user so after playing with the source code for a little bit, I’m wondering if anyone can help.

I’m interested to see if/how this can be customized to FanDuel constraints. Salary requirement are easy to change but I’m getting errors when trying to lock in positions. Fanduel uses a “C/1b” position that can be either a catcher or first basemen and one utility player that can be any field position. I’m trying the suggestion from an earlier issue, I’m getting several error codes.

Also, is there a way in Julia to set exposure? For example if I only want 40 percent of the payer pool how would I go about making an addition constraint?

Suggestions would be greatly appreciated. Please let me know if I can provide any additional information.

Error when running real data

I had the program running with the test data that was given. When I tried to apply real data, I get this error. I've matched the all of the new data variables to the given data, and I can't figure out why it won't run. Any advice/help would be much appreciated. Thanks.

ERROR: LoadError: MethodError: no method matching parse(::Int64)
Closest candidates are:
parse(::Type{IPv4}, ::AbstractString) at socket.jl:167
parse(::Type{IPv6}, ::AbstractString) at socket.jl:218
parse(::Type{DateTime}, ::AbstractString, ::DateFormat{Symbol("yyyy-mm-dd\THH:MM:SS.s"),Tuple{Base.Dates.DatePart{'y'},Base.Dates.Delim{Char,1},Base.Dates.DatePart{'m'},Base.Dates.Delim{Char,1},Base.Dates.DatePart{'d'},Base.Dates.Delim{Char,1},Base.Dates.DatePart{'H'},Base.Dates.Delim{Char,1},Base.Dates.DatePart{'M'},Base.Dates.Delim{Char,1},Base.Dates.DatePart{'S'},Base.Dates.Delim{Char,1},Base.Dates.DatePart{'s'}}}) at dates\parse.jl:202
...
Stacktrace:
[1] clean_order(::Array{Union{Int64, Missings.Missing},1}) at C:\Users\vince\Desktop\Real-FBP\data_cleaning.jl:13
[2] read_player_data(::String, ::String) at C:\Users\vince\Desktop\Real-FBP\data_cleaning.jl:63
[3] create_lineups(::Int64, ::Int64, ::Int64, ::#baseball_formulation, ::String, ::String, ::String) at C:\Users\vince\Desktop\Real-FBP\data_cleaning.jl:198
[4] include_from_node1(::String) at .\loading.jl:576
[5] include(::String) at .\sysimg.jl:14
while loading C:\Users\vince\Desktop\Real-FBP\optimize_multiple_lineups_baseball.jl, in expression starting on line 44

ERROR: LoadError: UndefVarError: DataArrays not defined

I'm getting the following error when I run the program:

ERROR: LoadError: UndefVarError: DataArrays not defined Stacktrace: [1] clean_order(::Array{Union{Missings.Missing, String},1}) at /Users/escism/Desktop/DFS/Baseball/data_cleaning.jl:10 [2] read_player_data(::String, ::String) at /Users/escism/Desktop/DFS/Baseball/data_cleaning.jl:61 [3] create_lineups(::Int64, ::Int64, ::Int64, ::#baseball_formulation, ::String, ::String, ::String) at /Users/escism/Desktop/DFS/Baseball/data_cleaning.jl:196 [4] include_from_node1(::String) at ./loading.jl:576 [5] include(::String) at ./sysimg.jl:14 while loading /Users/escism/Desktop/DFS/Baseball/optimize_multiple_lineups_baseball.jl, in expression starting on line 44

Any insight in how to fix and edit that issue?

Problem running the code. MethodError: no method matching sum(::GenericAffExpr{Float64,VariableRef}; i=1:616)

When I run the code optimize_multiple_lineups_baseball.jl I get the following error:

MethodError: no method matching sum(::GenericAffExpr{Float64,VariableRef}; i=1:616)
Closest candidates are:
sum(::Any) at reduce.jl:511 got unsupported keyword argument "i"
sum(::Any, !Matched::StaticArrays.StaticArray{var"#s171",T,N} where N where var"#s171"<:Tuple; dims) where T at C:\Users\VM.julia\packages\StaticArrays\l7lu2\src\mapreduce.jl:251 got unsupported keyword argument "i"
sum(::Any, !Matched::AbstractArray; dims) at reducedim.jl:723 got unsupported keyword argument "i"
...
macro expansion at rewrite.jl:227 [inlined]
macro expansion at macros.jl:830 [inlined]
baseball_formulation(::DataFrame, ::Array{Int64,2}, ::Int64, ::Int64, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Array{Int64,2}, ::Array{Int64,2}, ::Array{Int64,2}, ::Array{Int64,2}) at baseball_formulations3.jl:64
create_lineups(::Int64, ::Int64, ::Int64, ::typeof(baseball_formulation), ::String, ::String, ::String) at data_cleaning3.jl:434
top-level scope at optimize_multiple_lineups_baseball3.jl:75
include_string(::Function, ::Module, ::String, ::String) at loading.jl:1088

I would greatly appreciate your help to move forward

Greetings

The code is looking to run 'Gurobi'

The code is trying to run Gurobi by default and not the GLPK solver, any advice would be appreciated.

ERROR: LoadError: Failed to precompile Gurobi [2e9cd046-0924-5485-92f1-d5272153d98b]

Help w Julia

I'm pretty new to coding and seems like I got the 4 packages installed okay but then I get stuck. I can't figure out how to even copy/paste my errors from Julia. Very frustrating. Anyway I am using the Windows Powershell of Julia because I don't know how to switch to anything else or what to do.

I am stuck here

Downloading the Code
You can download the code and the example csv files by calling

$ git clone https://github.com/zlisto/dailyfantasybaseball
Alternatively, you can download the zip file from above.

I have no clue what to enter into Julia to make this happen. Anything I try gives back ERROR: syntax: extra token "clone" after end of expression or some such thing. Help!
Also help me get out of this powershell mode if possible

ERROR: LoadError: DimensionMismatch

Can anyone help me with this error? Full text below, and Line 44 string beneath:


ERROR LANGUAGE


LoadError: DimensionMismatch("mismatch in dimension 1 (expected 1 got 671)")
Stacktrace:
[1] _cs(::Int64, ::Bool, ::Int64, ::Int64) at ./abstractarray.jl:1193
[2] _cshp at ./abstractarray.jl:1189 [inlined]
[3] cat_shape(::Tuple{Bool,Bool}, ::Tuple{Int64,Int64}, ::Tuple{Int64}) at ./abstractarray.jl:1170 (repeats 2 times)
[4] cat_t(::Type{T} where T, ::Type{T} where T, ::Void, ::Vararg{Any,N} where N) at ./abstractarray.jl:1203
[5] hcat(::Void, ::Array{Int64,1}) at ./abstractarray.jl:1301
[6] create_lineups(::Int64, ::Int64, ::Int64, ::#baseball_formulation, ::String, ::String, ::String) at /Users/NAME/Desktop/GitHub_MLB_Code/data_cleaning.jl:439
[7] include_from_node1(::String) at ./loading.jl:576
[8] include(::String) at ./sysimg.jl:14
while loading /Users/NAME/Desktop/GitHub_MLB_Code/optimize_multiple_lineups_baseball.jl, in expression starting on line 44


Line 44 string:


create_lineups(num_lineups, num_overlap, stack_size, formulation, path_pitchers, path_hitters,  path_to_output);
telapsed = toq();

println("\nCalculated DraftKings baseball lineups.\n\tNumber of lineups = ", num_lineups, " \n\tStack size = ",stack_size,
"\n\tOverlap = ", num_overlap,"\n" )

println("Took ", telapsed/60.0, " minutes to calculate ", num_lineups, " lineups")

println("Saving data to file ",path_to_output,"\nDK Mafia 4 life")

request for finding some data information

Dear prof,

Sorry to interrupt you!

I am a phd student, and I also now study on this topic. I want to consult where I can find the information of the line and power play line in the daily hocky sports. I have tried to find it, but I failed.

Thanks a lot for your help sincerely!

hitters and pitchers csv file?

Hi, where do you download the hitters and pitchers csv file from? I've checked sites like rotogrinders and the data you can download as csv has way less columns than the 2016-08-12 csv files referenced in the sample code? Can someone share more details on how to get this data on a daily basis? Thanks

Methodology behind the programs

This isn't really an issue, but more a question regarding your logic. I don't see a general question option though versus issues. Sorry if this is a Github sin.

In your hockey program, you had the players separated into goalies and skaters. In that program, you were also filling one slot for a utility player.
In the baseball program, it appears the pitchers and batters are combined into players_lineup, then selected from there. In the baseball program, there is no utility player.

I'm wanting to add a utility player to the baseball program. Was there a reason you separated the players in the program where you had a utility player or could I just modify the baseball constraints to resemble the ones from lines 519-537 in the hockey program and fill the csv similar to the data_cleaning file on lines 92-152. It appears an array isn't necessary for utility players because of the constraint from the hockey program. Am I right? Please provide your insight. I'm new to Julia and trying to make some modifications. Thanks.

Missing Constraint

line 30 #only keep 4th order and earlier batters, cuz they make more points
On line 30 of the baseball_formulations program, you mention the batting order constraint, but I did not see the actual constraint in any of the programs. If the constraint is there, please tell me where. I'd like to adjust it. Otherwise, can you please provide the constraint that is missing?

Julia Question

Hi,

I am trying to learn more programming, but I am not familiar with Julia. I am working on a mac and I got everything installed, but I cannot run the script. Could someone please give me some guidance? I moved the zip to my desktop. Thanks in advance.

ERROR: LoadError: LoadError: UndefVarError: @defVar not defined

I'm getting the following error. Please advise.

ERROR: LoadError: LoadError: UndefVarError: @defvar not defined
Stacktrace:
[1] top-level scope
[2] include at ./boot.jl:326 [inlined]
[3] include_relative(::Module, ::String) at ./loading.jl:1038
[4] include(::Module, ::String) at ./sysimg.jl:29
[5] include(::String) at ./client.jl:403
[6] top-level scope at none:0
in expression starting at /Users/johnsmith/Downloads/Daily-Fantasy-Baseball-Contests-in-DraftKings-master/baseball_formulations.jl:59
in expression starting at /Users/johnsmith/Downloads/Daily-Fantasy-Baseball-Contests-in-DraftKings-master/baseball_formulations.jl:31

Versions of software / software packages

I'm trying to run this code, but I cannot as it seems to be using an older version of Julia / associated packages. Can you share the versions of Julia / each package used?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.