mortgagemath at a glance

Cent-accurate mortgage amortization for Python

mortgagemath 0.7.0 · rendered 2026-05-06

Produces fixed-rate and adjustable-rate mortgage amortization schedules that reproduce published lender, regulator, and textbook examples to the cent. Decimal end-to-end, stdlib-only.

Install and use

pip install mortgagemath
python -m mortgagemath        # post-install self-check

mortgagemath payment --principal 300000 --rate 6.5 --term-months 360
mortgagemath schedule --principal 300000 --rate 6.5 --term-months 360 \
    --format csv > schedule.csv

Worked example

from mortgagemath import us_30_year_fixed, periodic_payment, amortization_schedule

loan = us_30_year_fixed("300000", "6.5")
pmt = periodic_payment(loan)        # Decimal("1896.21")
sched = amortization_schedule(loan)  # closes at $0.00 on payment 360
# Payment Interest Principal Balance
1 $ 1,896.21 $ 1,625.00 $ 271.21 $ 299,728.79
240 $ 1,896.21 $ 909.89 $ 986.32 $ 166,992.91
360 $ 1,889.51 $ 10.18 $ 1,879.33 $ 0.00

Loan parameters

A wide variety of mortgage types can be represented by setting the parameters below. A robust test suite validates schedules from financial textbooks, regulatory documents, and other sources for US and Canadian mortgages, plus actuarial and finance-textbook examples, by choosing the right settings.

For common cases, start with a convenience constructor: us_30_year_fixed, us_15_year_fixed, canada_fixed_j2, us_actual_360_commercial, or fixed_payment_mortgage.

Required.

  • principal — original loan amount (Decimal)
  • annual_rate — annual interest rate as a percentage (Decimal)
  • term_months — loan term in calendar months

Optional.

  • amortization_period_months — set when ≠ term_months for balloon loans (Fannie Mae §1103 SARM, Canadian fixed-term mortgages)
  • start_date — issue date; required for ACTUAL_360
  • day_countTHIRTY_360 (US residential) · ACTUAL_360 (US commercial / SARM)
  • balance_trackingROUND_EACH (lender statements) · CARRY_PRECISION (Excel / CRE textbook)
  • payment_rounding / interest_roundingROUND_UP (US lender default) · ROUND_HALF_UP · ROUND_HALF_EVEN
  • compoundingMONTHLY (US) · SEMI_ANNUAL (Canadian j_2) · ANNUAL
  • payment_frequencyMONTHLY · SEMI_MONTHLY · BIWEEKLY · WEEKLY · QUARTERLY · ANNUAL
  • rate_schedule — list of RateChange (rate change at any payment, optional recast, optional payment cap with neg-am)
  • payment_override — pin the periodic payment to a chosen value; the schedule’s final row absorbs the residual (FHLBB 1935 “given-payment, find-term” convention)
  • fee_per_period — flat amount added to each Installment.payment on top of the closed-form interest+principal value (modern French assurance emprunteur; 1852 Crédit Foncier annuité loading)