API reference

The loan module

The Loan object used to create and calculate various mortgage statistics.

class mortgage.loan.Installment(number, payment, interest, principal, total_interest, balance)

Bases: tuple

balance

Alias for field number 5

interest

Alias for field number 2

number

Alias for field number 0

payment

Alias for field number 1

principal

Alias for field number 3

total_interest

Alias for field number 4

class mortgage.loan.Loan(principal, interest, term, term_unit='years', compounded='monthly', currency='$')[source]

Bases: object

Loan object used to create a loan.

This object can calculate amortization schedule and show summary statistics for the loan.

Parameters:
  • principal – The original sum of money borrowed.
  • interest – The amount charged by lender for use of the assets.
  • term – The lifespan of the loan.
  • term_unit – Unit for the lifespan of the loan.
  • compounded – Frequency that interest is compounded
  • currency – Set the currency symbol for use with summarize
Usage:
>>> from mortgage import Loan
>>> Loan(principal=200000, interest=.04125, term=15)
<Loan principal=200000, interest=0.04125, term=15>
apr

Return the annual percentage rate (APR).

APR is the amount of interest on your total loan amount that you’ll pay annually (averaged over the full term of the loan)

Usage:
>>> from mortgage import Loan
>>> loan = Loan(principal=200000, interest=.06, term=15)
>>> loan.apr
Decimal('6.00')
Return type:Decimal
apy

Return the annual percentage yield (APY).

APY is the effective annual rate of return taking into account the effect of compounding interest.

Usage:
>>> from mortgage import Loan
>>> loan = Loan(principal=200000, interest=.06, term=15)
>>> loan.apy
Decimal('6.17')
Return type:Decimal
interest_to_principle

Return the percentage of the principal that is payed in interest over the life of the loan.

Usage:
>>> from mortgage import Loan
>>> loan = Loan(principal=200000, interest=.06, term=15)
>>> loan.interest_to_principle
51.9
Return type:float
monthly_payment

Return the total monthly payment (principal and interest) for the loan.

Usage:
>>> from mortgage import Loan
>>> loan = Loan(principal=200000, interest=.06, term=30)
>>> loan.monthly_payment
Decimal('1199.10')
schedule(nth_payment=None)[source]

Retrieve payment information for the nth payment.

Usage:
>>> from mortgage import Loan
>>> loan = Loan(principal=200000, interest=.06, term=30)
>>> loan.schedule(1)
Installment(number=1, payment=Decimal('1199.101050305504789182922487'), interest=Decimal('1E+3'), principal=Decimal('199.101050305504789182922487'), total_interest=Decimal('1000'), balance=Decimal('199800.8989496944952108170775'))
split_payment(number, amount)[source]

Split payment amount into principal and interest.

Parameters:
  • number (int) – the payment number (e.g. nth payment)
  • amount (Decimal) – the total payment amount to be split
Usage:
>>> from mortgage import Loan
>>> from decimal import Decimal
>>> loan = Loan(principal=200000, interest=.06, term=15)
>>> loan.split_payment(number=180, amount=Decimal(1199.10))
(Decimal('8.396585353715933437157525763'), Decimal('1190.703414646283975613372297'))
Return type:Tuple[Decimal, Decimal]
total_interest

Return the total interest paid over the life of the loan.

Usage:
>>> from mortgage import Loan
>>> loan = Loan(principal=200000, interest=.06, term=15)
>>> loan.total_interest
Decimal('103788.46')
Return type:Decimal
total_paid

Return the total amount paid (both principal and interest) over the life of the loan.

Usage:
>>> from mortgage import Loan
>>> loan = Loan(principal=200000, interest=.06, term=15)
>>> loan.total_paid
Decimal('303788.46')
Return type:Decimal
total_principal

Return the total principal paid over the life of the loan.

Usage:
>>> from mortgage import Loan
>>> loan = Loan(principal=200000, interest=.06, term=15)
>>> loan.total_principal
Decimal('200000.00')
Return type:Decimal
years_to_pay

Return the number of years it will take to pay off this loan given the payment schedule.

Usage:
>>> from mortgage import Loan
>>> loan = Loan(principal=200000, interest=.06, term=15)
>>> loan.years_to_pay
15.0
Return type:float