An explicit formula for the constant payment (PMT) of a loan whose interest rate changes from period to period, with a machine-checked proof in Lean 4 and Mathlib. Published by ALTA Software.
The textbook annuity formula assumes one interest rate for the whole loan, and a monthly rate of annual rate / 12. When interest accrues daily, at annual rate / day-count basis times the actual days in each month, every month has its own rate and the textbook formula no longer repays the loan exactly. An explicit formula for this case, with an optional balloon balance at the end, was derived at ALTA Software around 2006. It holds for any sequence of non-negative per-period rates, not only day-count rates.
The full derivation is in the technical note docs/pmt_variable.md. Because the formula is used to compute real payments, it has also been verified by a proof assistant: Lean checks every step of the proof, so the formula is correct for every number of periods and every choice of rates that meets the stated assumptions, not just for the cases someone tested.
The formula and its original handwritten proof are by Niko Pachuashvili
(c. 2006). The Lean 4 formalisation, both the theorem statements and the proofs,
was generated by Claude Code, starting from the original summary of the
derivation (pmt_ne, Appendix A.1 of the technical note) and the hint that the
proof was by induction. Lean's kernel checks every proof, so their correctness
does not depend on who wrote them.
Scans of the original handwritten proof from around 2006 are in docs/original/, and Appendix A of the technical note explains them.
n ≥ 1periods,L: loan amount,b: balloon, the balance that remains after periodn,r_1, …, r_n: the interest rate of each period,c: the constant payment (the PMT),x_1, …, x_n: the principal part of each payment (payment minus interest).
The schedule equations say that each payment is interest on the outstanding balance plus a principal part, and that the principal parts repay everything except the balloon:
L · r_1 + x_1 = c
(L − x_1) · r_2 + x_2 = c
…
(L − x_1 − … − x_{n−1}) · r_n + x_n = c
x_1 + x_2 + … + x_n = L − b
L · ∏_{i=1}^{n} (1 + r_i) − b
c = ─────────────────────────────────────────
1 + ∑_{i=2}^{n} ∏_{j=i}^{n} (1 + r_j)
Below, P_n = ∏_{i=1}^{n} (1 + r_i) is the numerator's product and
S_n = 1 + ∑_{i=2}^{n} ∏_{j=i}^{n} (1 + r_j) the denominator.
With all rates equal, the formula reduces to the textbook annuity payment.
For an implementation:
- Compute
cwith the formula above. Rates must be non-negative (r_i ≥ 0); thenS_n ≥ 1and the division is always defined. - Build the schedule period by period: start with balance
B_0 = L; in periodithe interest isB_{i−1} · r_i, the principal part isx_i = c − B_{i−1} · r_i, and the new balance isB_i = B_{i−1} − x_i. In exact arithmetic the balance after the last period is exactlyb, and this is the only schedule with a constant payment. - Check the inputs:
- Positive payment:
c > 0exactly whenb < L · P_n. A balloon smaller than the loan (b < L) is always enough. - No negative amortisation: a principal part is negative when that
period's interest exceeds the payment, which happens when one period is
much longer than the others. A simple check that rules it out for every
period is
c ≥ L · max r_i. The exact per-period condition is in Section 7 of the technical note.
- Positive payment:
Rounding to currency units is outside the scope of the proof (see Scope).
All names live in the PMT namespace.
| File | Theorem | Statement |
|---|---|---|
PMT/Basic.lean |
partial_sum |
Partial-sum identity: if the first k schedule equations hold, the first k principal parts sum to c · S_k + L · (1 − P_k). |
PMT/Basic.lean |
pmt_mul |
The key identity c · S_n = L · P_n − b, i.e. the formula with the division multiplied out. |
PMT/Basic.lean |
pmt_formula |
PMT formula. If the schedule equations hold and 1 + r_i > 0 for every period, then c = (L · P_n − b) / S_n. |
PMT/Converse.lean |
pmt_converse |
Converse: if c · S_n = L · P_n − b, the explicit schedule (balance B_0 = L, B_k = B_{k−1} · (1 + r_k) − c, principal x_i = c − B_{i−1} · r_i) satisfies the schedule equations and ends with balance b. |
PMT/Converse.lean |
pmt_iff |
Characterisation. For 1 + r_i > 0: a schedule with constant payment c exists if and only if c equals the formula. |
PMT/Converse.lean |
schedule_unique |
For a given payment c, the schedule equations determine every principal part: x_i = c − B_{i−1} · r_i (over any commutative ring). |
PMT/Converse.lean |
pmt_unique |
Uniqueness. For 1 + r_i > 0: two solutions of the n + 1 schedule equations in the n + 1 unknowns c, x_1, …, x_n have the same c and the same x_i. With pmt_iff, the system has exactly one solution. |
PMT/Equal.lean |
pmt_equal |
Equal rates: if every r_i = ρ with ρ > −1 and ρ ≠ 0, the formula reduces to the textbook annuity payment c = ρ · (L · (1 + ρ)^n − b) / ((1 + ρ)^n − 1). |
PMT/Equal.lean |
pmt_equal_zero |
Zero rate: if every r_i = 0, then c = (L − b) / n. |
PMT/Positivity.lean |
pmt_pos_iff |
Positive payment. For 1 + r_i > 0: c > 0 if and only if b < L · P_n. |
PMT/Positivity.lean |
pmt_pos_of_balloon_lt |
For L ≥ 0, r_i ≥ 0 and b < L, the payment is positive. |
PMT/Positivity.lean |
principal_nonneg_iff, principal_nonneg_iff_one, principal_nonneg_iff_closed |
x_i ≥ 0 if and only if the payment covers the period's interest, B_{i−1} · r_i ≤ c; in terms of the data: L · r_1 ≤ c for i = 1, and L · P_{i−1} · r_i ≤ c · (1 + r_i · S_{i−1}) for i ≥ 2. |
PMT/Positivity.lean |
principal_nonneg_of_le |
No negative amortisation. For r_i ≥ 0: if L · r_i ≤ c for every period, every x_i ≥ 0. |
Notes on the assumptions:
- Interest rates are non-negative,
r_i ≥ 0(zero allowed). The theorems assume only the weaker condition1 + r_i > 0(each period's growth factor is positive), which every non-negative rate satisfies. It is what guarantees the denominatorS_nis positive, so the division is defined. - The identity
c · S_n = L · P_n − b(pmt_mul,pmt_converse) needs no such assumption: it is proved over any commutative ring, not only the real numbers.
- Install elan, the Lean toolchain manager:
https://github.com/leanprover/elan#installation
(on Windows, the PowerShell installer; on Linux/macOS, the
curl … | shone-liner). elan readslean-toolchainand downloads the exact Lean version (v4.37.0-rc1) automatically on first use. - A bash shell to run
scripts/verify.sh(Git Bash works on Windows). - Git and internet access to
github.comand to Mathlib's cache server: the firstlake exe cache getdownloads Mathlib's prebuilt cache (several GB), so Mathlib does not have to be compiled locally.
No other Lean knowledge is needed to run scripts/verify.sh.
lake exe cache get # once: download prebuilt Mathlib
lake build # build the library
scripts/verify.sh # build + check the axioms of the main theoremsscripts/verify.sh prints the axioms each main theorem depends on and ends with
OK: all theorems depend only on propext, Classical.choice, Quot.sound.
Those three are Lean's standard axioms. The script fails if any theorem uses
sorry (an unfinished proof) or any other axiom.
The build prints a warning that the files "import Mathlib ... designed for use with the module system"; it is expected and harmless.
Do not run lake update: lake-manifest.json and lean-toolchain pin the
exact Mathlib revision and Lean toolchain the proofs were verified with.
The proof is about exact arithmetic over the real numbers. It does not cover:
- rounding of payments, interest or balances to currency precision (e.g. cents), or the drift such rounding causes over a schedule;
- the behaviour of
System.Decimalor any other floating/fixed-point number type used by an implementation.
An implementation of the formula still needs its own tests for rounding.
Copyright 2026 ALTA Software.
Licensed under the Apache License, Version 2.0. This covers the Lean sources, the scripts and the documentation, including the technical note. See also NOTICE.