Skip to content

Instantly share code, notes, and snippets.

@pathikrit
Created August 16, 2016 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pathikrit/fce3c5eae21493bba59e1751ca4e2217 to your computer and use it in GitHub Desktop.
Save pathikrit/fce3c5eae21493bba59e1751ca4e2217 to your computer and use it in GitHub Desktop.
Mortgage Math

Input

p := Original Principal amount
apr := Annual Percentage Rate
t := Number of years of loan

Calcuation:

r := apr/100/12                    # monthly interest rate
n := 12 * t                        # number of monthly payments

c(x) := 1 - (1 + r)^(-x)

m := p*r/c(n)                      # monthly payment

balance(i) := p*c(n-i)/c(n)        # balance at the end of the ith month

principal(i) := balance(i-1) - balance(i)    # principal part of the ith monthly loan payment
interest(i)  := m - principal(i)             # interest part of the ith month loan payment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment