Functional Weave
Code in TypeScript

insurance.claim-reserve Unreviewed

Claim reserve history: paid, recovered, outstanding and incurred after each transaction, and the movement.

1.0.1 · published 2026-10-03 by charlie · Anterra

Pinned by 14 tests, run in TypeScript, Python and Rust.

Unreviewed. This capability’s implementations agree in every language and pass its published test vectors, which were worked out from the official sources cited. But no qualified actuary has yet checked those vectors, or confirmed that the capability covers the cases it claims. Treat it as a draft. Do not use it for real people, money or decisions without your own expert review. Once a qualified reviewer signs off, this notice is replaced with their name, qualification and the date. Each new version needs fresh sign-off.

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 history of one claim's figures: after each transaction, what has been paid, what has been recovered, the outstanding case reserve, the incurred total and the movement in incurred.

incurred = paid - recovered + outstanding

For example

  • claimReserveHistory(transactions ×6, GBP) → ×6 a claim's life: reserve, part payment, strengthening, an overpayment of the reserve, a recovery, closure
  • claimReserveHistory(, GBP) → no transactions, no positions
  • claimReserveHistory(transactions ×2, GBP) → ×2 a claim withdrawn: the reserve released to nil is a negative movement

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 claimReserveHistory(transactions: readonly ClaimTransaction[], currency: string): readonly ReservePosition[]
transactionsClaimTransaction[]one claim's transactions in date order; same-day ones in the order they happened
currencystringthe claim's currency
returnsReservePosition[]the claim's position after each transaction, in the same order

The types it declares, generated into your project

export type ClaimTransactionKind = "reserve" | "payment" | "recovery";

/** One event on a claim. */
export interface ClaimTransaction {
  readonly date: string;
  /** reserve sets the outstanding estimate; payment pays; recovery brings money back */
  readonly kind: ClaimTransactionKind;
  /** reserve: the new outstanding estimate, 0 or more; payment and recovery: more than 0 */
  readonly amount: Money;
}

/** The claim after one transaction. */
export interface ReservePosition {
  readonly date: string;
  readonly kind: ClaimTransactionKind;
  /** paid to date */
  readonly paid: Money;
  /** salvage and subrogation recovered to date */
  readonly recovered: Money;
  /** the case reserve: what is still expected to be paid */
  readonly outstanding: Money;
  /** paid minus recovered plus outstanding */
  readonly incurred: Money;
  /** the change in incurred this transaction made */
  readonly movement: Money;
}

Your code names it in one line, in the file that uses it

import { claimReserveHistory } from "#fune/insurance.claim-reserve@^1";
impl/typescript.ts · 63 lines · open · raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

import { epochDayFromIso } from "./dates_add_days.ts";  ← from dates.add-days ^1.0.0 · built alongside by fune
import { assertSameCurrency, money } from "./money_amount.ts";  ← from money.amount ^1.0.0 · built alongside by fune
import { type ClaimTransaction, type ReservePosition } from "./insurance_claim_reserve_types.ts";

/**
 * A claim's position after each transaction: paid, recovered, the outstanding
 * case reserve, and incurred = paid - recovered + outstanding.
 *
 * A payment erodes the outstanding reserve by what it pays, never below zero:
 * a payment larger than the reserve raises incurred by the excess, which is
 * how an under-reserved claim shows up. A reserve transaction sets the
 * outstanding estimate outright. The movement is what each transaction did to
 * incurred, the figure that goes through the accounts.
 */
export function claimReserveHistory(transactions: readonly ClaimTransaction[], currency: string): readonly ReservePosition[] {
  const zero = money(0, currency);
  let paid = 0;
  let recovered = 0;
  let outstanding = 0;
  let incurred = 0;
  let previousDay: number | null = null;
  let previousDate = "";
  const out: ReservePosition[] = [];
  for (const t of transactions) {
    const day = epochDayFromIso(t.date);
    if (previousDay !== null && day < previousDay) {
      throw new RangeError(`transactions must be in date order: ${t.date} comes after ${previousDate}`);
    }
    previousDay = day;
    previousDate = t.date;
    assertSameCurrency(zero, t.amount);
    if (t.kind === "reserve") {
      if (t.amount.minor < 0) {
        throw new RangeError(`a reserve must not be negative, received ${t.amount.minor} on ${t.date}`);
      }
      outstanding = t.amount.minor;
    } else if (t.kind === "payment" || t.kind === "recovery") {
      if (t.amount.minor <= 0) {
        throw new RangeError(`a ${t.kind} must be more than zero, received ${t.amount.minor} on ${t.date}`);
      }
      if (t.kind === "payment") {
        paid += t.amount.minor;
        outstanding = Math.max(outstanding - t.amount.minor, 0);
      } else {
        recovered += t.amount.minor;
      }
    } else {
      throw new RangeError(`unknown transaction kind "${t.kind}": use reserve, payment or recovery`);
    }
    const now = paid - recovered + outstanding;
    out.push({
      date: t.date,
      kind: t.kind,
      paid: money(paid, currency),
      recovered: money(recovered, currency),
      outstanding: money(outstanding, currency),
      incurred: money(now, currency),
      movement: money(now - incurred, currency),
    });
    incurred = now;
  }
  return out;
}

Install

fune build

With that line in your source, in a TypeScript project (language typescript in fune.project), fune build resolves it and its 2 dependencies, 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 insurance.claim-reserve
Download for TypeScript insurance.claim-reserve-1.0.1-typescript.fune · 22,211 bytes sha256 aa3c6fe5e25ce2b78fe8f2d2c51e1b4c4b74f6277ee744d1a6a353d4b3ae0481

The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./insurance.claim-reserve-1.0.1-typescript.fune, or fetch it from a terminal with fune pull insurance.claim-reserve@1.0.1:typescript.

The whole function, every language, is one file too: insurance.claim-reserve-1.0.1.fune, 28,921 bytes, sha256 36fadf22a15bc9a0a8ff4a780f9c86d616fdf776b90d5c8689674c66f2246539. 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.claim-reserve

after — your function gets the result and the arguments, and returns the final result.

// fune: after insurance.claim-reserve

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.add-days in insurance.claim-reserve
// fune: replace money.amount in insurance.claim-reserve

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.claim-reserve --steps.

// fune: step insurance.claim-reserve 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.

CaseArgumentsExpected
a claim's life: reserve, part payment, strengthening, an overpayment of the reserve, a recovery, closure transactions ×6, GBP → ×6
no transactions, no positions , GBP →
a claim withdrawn: the reserve released to nil is a negative movement transactions ×2, GBP → ×2
a payment with no reserve set raises incurred by the whole payment transactions ×1, GBP → ×1
a payment within the reserve moves nothing transactions ×2, GBP → ×2
a reserve cut after a payment transactions ×3, GBP → ×3
recoveries can take incurred below zero on a claim recovered in full with costs transactions ×2, GBP → ×2
transactions out of date order are refused transactions ×2, GBP → error: transactions must be in date order: 2026-01-01 comes after 2026-02-01
a negative reserve is refused transactions ×1, GBP → error: a reserve must not be negative
a zero payment is refused transactions ×1, GBP → error: a payment must be more than zero
Show the other 4 tests
CaseArgumentsExpected
a negative recovery is refused transactions ×1, GBP → error: a recovery must be more than zero
an unknown kind is refused transactions ×1, GBP → error: unknown transaction kind
a transaction in another currency is refused transactions ×1, GBP → error: currency mismatch
a malformed date is refused transactions ×1, GBP → error: is not a real calendar date

More from the author

## Transactions

- **reserve**: the claims handler's new estimate of what is still to be paid. It sets `outstanding` outright (0 closes the claim or releases the reserve). - **payment**: money paid out. It adds to `paid` and erodes `outstanding` by the same amount, never below zero. A payment within the reserve therefore leaves incurred unchanged; one larger than the reserve raises incurred by the difference, which is how an under-reserved claim shows up. - **recovery**: salvage, subrogation or third-party recoveries received. They reduce net incurred. A claim recovered in full with costs can show negative incurred.

`movement` is the change in incurred made by each transaction: the figure that goes through the claims account for the period, and what a development triangle is built from. Summing the movements in a period gives that period's incurred movement.

Transactions must be in date order; same-day transactions keep the order given, so a payment and the reserve change that follows it on one day come out as two positions. Dates are checked as real calendar dates.

Not covered: IBNR and other reserves not held against a specific claim, reserve currency conversion, and claims handling expenses (pass them as payments if your reporting counts them in incurred).

## Before you rely on this

**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 above, and have an actuary review how you use it, before anyone relies on the output. Provided "as is" under its licence, without warranty.

**Unreviewed.** This capability's implementations agree in every language and pass its published test vectors, which were worked out from the official sources cited. But no qualified actuary has yet checked those vectors, or confirmed that the capability covers the cases it claims. Treat it as a draft. Do not use it for real people, money or decisions without your own expert review. Once a qualified reviewer signs off, this notice is replaced with their name, qualification and the date. Each new version needs fresh sign-off.

1.0.1 marks it unreviewed. The code and the tests are unchanged.

Files

PathBytes
README.md2,627
impl/python.py2,622
impl/rust.rs3,848
impl/typescript.ts2,514
vectors.json11,487