def remaining_balance(loan: float, interest_rate: float, years: int, payments: int) -> float:
    """
    Calculate the remaining loan balance

    :param loan: initial loan amount
    :param interest_rate: interest rate
    :param years: loan term in years
    :param payments: total number of payments made
    :return: remaning balance
    """
    r = interest_rate / 1200  # monthly interest rate
    m = r + 1
    n = years * 12
    remaining = loan * (((m ** n) - (m ** payments)) / ((m ** n) - 1))
    return remaining