def calc_max_safe_lvr(max_drawdown, base_lvr, buffer=0.0):
    """Calculates maximum safe LVR to have historically avoided a margin call

    Args:
        max_drawdown (float): Maximum historically observed drawdown
        base_lvr (float): Max LVR allowed
        buffer (float, optional): Defaults to 0.0. LVR buffer that triggers a drawdown

    Returns:
        float: Decimal representation of max historically safe LVR
    """

    max_drawdown = max_drawdown if max_drawdown < 0 else -1 * max_drawdown

    return (100 + max_drawdown) * (base_lvr + buffer)