Helper Functions for Calculating Fantasy Points

This is going to be one of our shorter blog posts, but if you’re into daily fantasy basketball betting, it’s a must read! One of the most basic but overlooked areas in building a fantasy points model is – how exactly are we even defining fantasy points? Does it vary from website to website? Does a point count more than a rebound? Wouldn’t it be nice to have a configurable function that takes in weights and outputs the correct fantasy points scored by a player, as measured by a particular website’s (draftkings, fanduel) statistical weighted combination used to create fantasy points? That’s exactly what we’re going to outline below.

Below is a simple function we wrote that takes in your major stat category weights, and implements a vectorized calculation of fantasy points for all the rows in your dataframe. (If you aren’t aware of what dataframe means in this context, see our first two blog posts here and here.

def calculate_fpts(PTS_weight, P3M_weight,REB_weight, AST_weight, STL_weight, BLK_weight,TOV_weight):
    full_df["FPTS"] = (PTS_weight * full_df["PTS"]) + (P3M_weight * full_df["3PM"]) + (REB_weight * full_df["REB"]) + (AST_weight *  full_df["AST"]) + (STL_weight * full_df["STL"]) + (BLK_weight * full_df["BLK"]) - (TOV_weight * full_df["TOV"])

    return full_df["FPTS"]

# Using draftkings weights to calculate fpts
full_df["FPTS"] = full_df.apply(lambda x : calculate_fpts(1,0.5,1.25,1.5,2,2,0.5), axis=1)

The only thing you have make sure of is that your column names match up with ours above. We’re using standard basketball abbreviations so there shouldn’t be any confusion (Points -> PTS, Rebounds -> REB), and so on.

Next is a calculation that is almost always overlooked, and could be leading to incorrect predictions in your sports betting model. That calculation is the double-double and/or triple-double. The assumption is the readers of this article knows what a double-double and triple-double are, but how exactly could we go about adding this as a factor in our overall fantasy points calculation above? DraftKings adds 1.5 fantasy points if a player gets a double-double, and 3 fantasy points for a triple-double. So for someone like Russell Westbrook who is (used to be) a triple-double machine, if you simply ignore this calculation, you’ll consistently underpredict his fantasy points. There are more efficient ways of doing the calculation that what we’ve listed below, but the good part about our function is that it’s extremely intuitive and easy to interpret. 

def calculate_triple_double(PTS, REB, AST, STL, BLK):
    count = 0
    if PTS >= 10:
        count += 1

    if REB >= 10:
        count += 1
    if AST >= 10:
        count += 1
    if STL >= 10:
        count += 1
    if BLK >= 10:
        count += 1
    if count == 2:
        return 1.5
    elif count >= 3:
        return 3
        return 0
full_df["TRIPLE_DOUBLE"] = full_df.apply(lambda x : calculate_triple_double(x["PTS"], x["REB"], x["AST"], x["STL"], x["BLK"]), axis=1)


In summary, if you’re serious about building a basketball betting model, keep these two functions handy – they’ll come up over and over again and there’s no need to constantly recreate the logic.

Share your love