def calc_drawdown(df, price_col, window_size):
    """Calculates drawdown

    Reference: https://www.investopedia.com/terms/d/drawdown.asp

    Args:
        df (data.frame): Price history dataframe
        price_col (str): Column name for price data
        window_size (int): How many units to look back. Units change based on aggregate provided

    Returns:
        data.frame: Original dataframe with drawdown appended
    """

    # Calculate rolling prior maximum to compare against current price
    prior_max = df[price_col].rolling(window=window_size, min_periods=1).max()

    # Calculate percentage change, aka drawdown
    df["market_drawdown"] = (df[price_col] / prior_max - 1.0) * 100
    df["market_drawdown"].replace(-100, 0, inplace=True)

    return df