Skip to content

Instantly share code, notes, and snippets.

@kovrov
Created May 27, 2019 22:21
Show Gist options
  • Save kovrov/4d66890630661a3174e1c06e8290a2c8 to your computer and use it in GitHub Desktop.
Save kovrov/4d66890630661a3174e1c06e8290a2c8 to your computer and use it in GitHub Desktop.
Amortization table
def amortization(loan, apr, years, extra=0):
rate = apr / 100 / 12
periods = years * 12
payment = (loan * rate) / (1 - pow(1 + rate, -periods))
balance = loan
for period in range(periods):
if balance <= 0:
return
interest = balance * rate
principal = payment - interest + extra
balance -= principal
yield period, interest, principal, balance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment