insurance.age-banding
Age at policy inception and the rating band it falls in, from a table of age bands.
1.0.0 (not the latest) · published 2026-10-03 by charlie · Anterra
Pinned by 18 tests, run in TypeScript, Python and Rust.
Not professional advice. This capability calculates insurance 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 an actuary review how you use it, before anyone relies on the output. Provided “as is” under its licence, without warranty.
What it does
The policyholder's (or driver's) age on the inception date, and the band of a rating table it falls in: "17-20", "21-24", "70+".
## Age
For example
age_band(2000-06-15, 2026-09-23, bands ×6)→ age 26, label 25-29 26 at inception is in the 25-29 bandage_band(2001-09-23, 2026-09-23, bands ×6)→ age 25, label 25-29 a birthday on the inception date counts: 25 that dayage_band(2001-09-23, 2026-09-22, bands ×6)→ age 24, label 21-24 the day before the 25th birthday is still 24
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.
pub fn age_band(birth_date: &str, inception_date: &str, bands: &[AgeBand]) -> AgeBanding
| birth_date | date | date of birth |
| inception_date | date | the date the age is taken on: inception or renewal, never today implicitly |
| bands | AgeBand[] | the bands, youngest first, not overlapping |
| returns | AgeBanding |
The types it declares, generated into your project
/// One band of ages, inclusive at both ends.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AgeBand {
pub label: String,
pub min_age: i64,
/// null for no upper limit, on the last band only
pub max_age: Option<i64>,
}
/// The age and its band.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AgeBanding {
/// completed years on the inception date
pub age: i64,
pub label: String,
}
Your code names it in one line, in the file that uses it
fune!(insurance.age-banding@^1); // then call age_band(…)
Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
use super::funejson::Value; ← the fune runtime: the JSON value the test vectors use; fune build keeps it only where a signature takes one
use super::dates_age::age; ← from dates.age ^1.0.0 · built alongside by fune
/// The policyholder's age on the inception date and the band it falls in.
///
/// Age is completed years by dates.age, so a 29 February birthday ages on
/// 1 March in other years. The bands are checked before use: youngest first,
/// inclusive at both ends, no overlaps, and only the last may be open-ended.
/// An age no band covers is an error, not the nearest band.
///
/// # Panics
/// Panics on malformed bands, dates dates.age refuses, or an age no band covers.
pub fn age_band(birth_date: &str, inception_date: &str, bands: &[AgeBand]) -> AgeBanding {
if bands.is_empty() {
panic!("bands must not be empty");
}
let mut previous_max: i64 = -1;
for (i, band) in bands.iter().enumerate() {
if band.min_age < 0 {
panic!("minAge must be a whole number of 0 or more, received {}", band.min_age);
}
if band.max_age.is_none() && i != bands.len() - 1 {
panic!("only the last band may have no maxAge: \"{}\" is not last", band.label);
}
if let Some(max) = band.max_age {
if max < band.min_age {
panic!("maxAge must be a whole number no less than minAge in band \"{}\"", band.label);
}
}
if band.min_age <= previous_max {
panic!(
"bands must be youngest first and not overlap: \"{}\" starts at {}",
band.label, band.min_age
);
}
previous_max = band.max_age.unwrap_or(i64::MAX);
}
let years = age(birth_date, inception_date);
for band in bands {
if years >= band.min_age && band.max_age.map_or(true, |max| years <= max) {
return AgeBanding {
age: years,
label: band.label.clone(),
};
}
}
panic!("no band for age {}", years)
}
pub fn fune_vector(args: &[Value]) -> Value {
let bands: Vec<AgeBand> = args[2]
.as_arr()
.iter()
.map(|b| {
if let Value::Float(f) = b.get("minAge") {
panic!("minAge must be a whole number of 0 or more, received {}", f);
}
if let Value::Float(_) = b.get("maxAge") {
panic!("maxAge must be a whole number no less than minAge in band \"{}\"", b.get("label").as_str());
}
AgeBand {
label: b.get("label").as_str().to_string(),
min_age: b.get("minAge").as_i64(),
max_age: if b.get("maxAge").is_null() { None } else { Some(b.get("maxAge").as_i64()) },
}
})
.collect();
let result = age_band(args[0].as_str(), args[1].as_str(), &bands);
Value::obj(vec![("age", Value::Int(result.age)), ("label", Value::str(&result.label))])
}Install
fune build
With that line in your source, in a Rust project (language rust in fune.project), fune build resolves it and its 1 dependency, pins them in fune.lock, downloads only the Rust 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. A crate’s build.rs runs it before every compile. Or pin a range in fune.project and build in one step:
fune add insurance.age-banding
The manifest, vectors and README with only the Rust implementation. Install it without the registry with fune add ./insurance.age-banding-1.0.0-rust.fune, or fetch it from a terminal with fune pull insurance.age-banding@1.0.0:rust.
The whole function, every language, is one file too: insurance.age-banding-1.0.0.fune, 20,379 bytes, sha256 1fa8cf97116e325b222b3dadce90daedf0ce8f6b20be718c01ed06f92392b407. 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 insurance.age-banding
after — your function gets the result and the arguments, and returns the final result.
// fune: after insurance.age-banding
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 dates.age in insurance.age-banding
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 insurance.age-banding --steps.
// fune: step insurance.age-banding 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 | |
|---|---|---|---|
| 26 at inception is in the 25-29 band | 2000-06-15, 2026-09-23, bands ×6 | → | age 26, label 25-29 |
| a birthday on the inception date counts: 25 that day | 2001-09-23, 2026-09-23, bands ×6 | → | age 25, label 25-29 |
| the day before the 25th birthday is still 24 | 2001-09-23, 2026-09-22, bands ×6 | → | age 24, label 21-24 |
| a 29 February birthday has not turned 21 on 28 February | 2004-02-29, 2025-02-28, bands ×6 | → | age 20, label 17-20 |
| and turns 21 on 1 March | 2004-02-29, 2025-03-01, bands ×6 | → | age 21, label 21-24 |
| in a leap year it turns on 29 February | 2004-02-29, 2028-02-29, bands ×6 | → | age 24, label 21-24 |
| the open top band | 1950-01-01, 2026-09-23, bands ×6 | → | age 76, label 70+ |
| exactly the youngest age | 2009-09-23, 2026-09-23, bands ×6 | → | age 17, label 17-20 |
| the upper edge of a band is inside it | 1976-09-24, 2026-09-23, bands ×6 | → | age 49, label 30-49 |
| a single open band covers everyone from its minimum | 1990-01-01, 2026-01-01, bands ×1 | → | age 36, label all |
Show the other 8 tests
| Case | Arguments | Expected | |
|---|---|---|---|
| too young for any band | 2010-01-01, 2026-09-23, bands ×6 | → | error: no band for age 16 |
| an age in a gap between bands is refused | 2004-01-01, 2026-09-23, bands ×2 | → | error: no band for age 22 |
| overlapping bands are refused | 2000-01-01, 2026-09-23, bands ×2 | → | error: bands must be youngest first and not overlap |
| an open band that is not last is refused | 2000-01-01, 2026-09-23, bands ×2 | → | error: only the last band may have no maxAge |
| a band whose maximum is below its minimum is refused | 2000-01-01, 2026-09-23, bands ×1 | → | error: maxAge must be a whole number no less than minAge |
| no bands is refused | 2000-01-01, 2026-09-23, | → | error: bands must not be empty |
| inception before birth is refused | 2026-09-23, 2026-01-01, bands ×6 | → | error: is before birthDate |
| a fractional minimum age is refused | 2000-01-01, 2026-09-23, bands ×1 | → | error: minAge must be a whole number |
More from the author
Completed years on `inceptionDate`, by `dates.age`: a birthday on the inception date counts, and a 29 February birthday ages on 1 March in other years (UK law), so someone born on 29 February 2004 is still 20 on 28 February 2025. The date is always passed in: insurers rate on the age at inception or renewal, never on the day the code runs, and a mid-term change is usually rated on the age at the start of the term.
## Bands
The band table is the insurer's, so it is an argument. Each band is inclusive at both ends in whole years; the last may have no upper limit (`maxAge` null). The table is checked first: youngest first, no overlaps, and only the last band open-ended. Gaps are allowed, and an age that falls in a gap, or below the first band, is an error naming the age rather than being put in the nearest band, because a quote for someone the table does not cover should stop, not be priced.
Look the label up in a factor table with `insurance.rating-factors`.
Files
| Path | Bytes |
|---|---|
| README.md | 1,137 |
| impl/python.py | 1,900 |
| impl/rust.rs | 2,813 |
| impl/typescript.ts | 1,932 |
| vectors.json | 8,489 |