banking.savings-aer
AER (annual equivalent rate) from a gross nominal rate and how often interest is paid, to two decimal places.
1.0.0 · published 2026-10-03 by charlie · Anterra
Pinned by 14 tests, run in TypeScript, Python and Rust.
Not professional advice. This capability calculates investment figures from published rules. It is a software component for developers, not financial advice. Rules change and every rate here has an effective date. Check that the dates cover your case. Verify results against the official sources listed in its README, and have a financial adviser review how you use it, before anyone relies on the output. Provided “as is” under its licence, without warranty.
What it does
The AER (Annual Equivalent Rate) of a savings account from its gross rate and how often it pays interest: the rate that, paid and compounded once a year, gives the same return. UK savings advertising must quote it, so accounts that pay monthly and yearly can be compared.
## The rule
For example
savingsAer(5.8%, 12)→ 596 Practice Note worked example 5: 5.8% paid monthly is 5.96% AERsavingsAer(6%, 1)→ 600 Practice Note worked example 1: interest paid once a year, AER equals the gross ratesavingsAer(5%, 2)→ 506 paid half-yearly
The function
The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.
export function savingsAer(grossRateBasisPoints: number, paymentsPerYear: number): number
| grossRateBasisPoints | int | the gross annual rate, 0 to 100000; 580 = 5.8% |
| paymentsPerYear | int | how often interest is paid and compounded: 1 to 365 |
| returns | int | the AER in basis points, i.e. a percentage to two decimal places: 596 = 5.96% |
Your code names it in one line, in the file that uses it
import { savingsAer } from "#fune/banking.savings-aer@^1";
/**
* The AER of a gross rate paid `paymentsPerYear` times a year:
* (1 + i / n)^n − 1, per the UK Finance / BSA AER Practice Note formula (d),
* rounded half-up to two decimal places of a percent (a whole basis point).
*
* With i = b / 10000 and D = 10000 × n the exact value in basis points is
* 10000 × ((D + b)^n − D^n) / D^n, computed in integers and rounded once.
*/
export function savingsAer(grossRateBasisPoints: number, paymentsPerYear: number): number {
if (!Number.isInteger(grossRateBasisPoints) || grossRateBasisPoints < 0 || grossRateBasisPoints > 100000) {
throw new RangeError(`grossRateBasisPoints must be between 0 and 100000, received ${grossRateBasisPoints}`);
}
if (!Number.isInteger(paymentsPerYear) || paymentsPerYear < 1 || paymentsPerYear > 365) {
throw new RangeError(`paymentsPerYear must be between 1 and 365, received ${paymentsPerYear}`);
}
const n = BigInt(paymentsPerYear);
const d = 10000n * n;
const whole = d ** n;
const numerator = 10000n * ((d + BigInt(grossRateBasisPoints)) ** n - whole);
// Half-up for a non-negative fraction: floor((2N + M) / 2M).
return Number((2n * numerator + whole) / (2n * whole));
}Install
fune build
With that line in your source, in a TypeScript project (language typescript in fune.project), fune build resolves it and its 1 dependency, pins them in fune.lock, downloads only the TypeScript package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:
fune add banking.savings-aer
The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./banking.savings-aer-1.0.0-typescript.fune, or fetch it from a terminal with fune pull banking.savings-aer@1.0.0:typescript.
The whole function, every language, is one file too: banking.savings-aer-1.0.0.fune, 9,250 bytes, sha256 c56d71d3e9015670eff51ce4aa5368744bbd1301c9d9d60a8e5fbb287083612e. It installs into a project of any language.
Customise it in your app
The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.
before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.
// fune: before banking.savings-aer
after — your function gets the result and the arguments, and returns the final result.
// fune: after banking.savings-aer
replace — inside this capability’s code only, calls to a dependency go to your function, with the same signature. Other capabilities that use it are unaffected; write in * to replace it everywhere.
// fune: replace math.big-integer in banking.savings-aer
step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show banking.savings-aer --steps.
// fune: step banking.savings-aer after <n|label>
Tests
A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.
| Case | Arguments | Expected | |
|---|---|---|---|
| Practice Note worked example 5: 5.8% paid monthly is 5.96% AER | 5.8%, 12 | → | 596 |
| Practice Note worked example 1: interest paid once a year, AER equals the gross rate | 6%, 1 | → | 600 |
| paid half-yearly | 5%, 2 | → | 506 |
| paid quarterly | 5%, 4 | → | 509 |
| paid monthly at 12% is 12.68% | 12%, 12 | → | 1,268 |
| paid daily | 4.5%, 365 | → | 460 |
| paid weekly | 4.5%, 52 | → | 460 |
| zero rate | 0%, 12 | → | 0 |
| a tiny rate still rounds to a whole basis point | 0.01%, 12 | → | 1 |
| a very high rate | 100%, 12 | → | 16,130 |
Show the other 4 tests
| Case | Arguments | Expected | |
|---|---|---|---|
| 4.5% paid monthly is 4.59%, not 4.60% | 4.5%, 12 | → | 459 |
| a negative rate is refused | -0.1%, 12 | → | error: grossRateBasisPoints must be between 0 and 100000 |
| zero payments a year is refused | 5%, 0 | → | error: paymentsPerYear must be between 1 and 365 |
| more than daily is refused | 5%, 366 | → | error: paymentsPerYear must be between 1 and 365 |
More from the author
The UK Finance / Building Societies Association "Annual Equivalent Rate (AER) Practice Note" (January 2025, which replaced the 1985-2024 "Code of Conduct for the Advertising of Interest Bearing Accounts" and its AER appendix) gives, where interest is paid more often than annually, formula (d):
AER = ((1 + i / (n × 100))^n − 1) × 100
with i the gross annual rate in percent and n the number of times a year it is paid. Guideline A5: "AERs are to be rounded and displayed up to two decimal places." Its worked example 5: 5.8% paid monthly is 5.956...%, an AER of 5.96%; worked example 1: interest paid once a year has an AER equal to the gross rate. Both are vectors here.
Source: https://www.ukfinance.org.uk/policy-and-guidance/guidance/annual-equivalent-rate-aer-practice-note (PDF: https://www.ukfinance.org.uk/system/files/2025-02/Annual%20Equivalent%20Rate%20AER%20practice%20note_0.pdf), read 2026-09-23.
## Exact, then rounded once
The rate is b basis points, so with D = 10000 × n the AER in basis points is exactly 10000 × ((D + b)^n − D^n) / D^n. That is computed in integers (`bigint`, Python `int`, `math.big-integer` in Rust; for daily interest D^n has about 2,400 digits) and rounded half-up to a whole basis point, which is two decimal places of a percent. "Rounded" in A5 is read as the usual half-up; there is no floating-point step where 4.595% could become 4.5949999%.
## What it does not do
The Practice Note's general formula (a) also covers bonuses, rates that step up, deposits during the term and terms other than a year; those need the cash flows and an iterative solve, and are not this function. This is the fixed-rate, whole-year, single-deposit case of formula (d), which is what a headline AER almost always is. The rate is gross (before tax), 0 to 100000 basis points, and interest is paid 1 to 365 times a year.
Files
| Path | Bytes |
|---|---|
| README.md | 2,173 |
| impl/python.py | 1,064 |
| impl/rust.rs | 1,358 |
| impl/typescript.ts | 1,190 |
| vectors.json | 1,511 |