Functional Weave
Code in Rust

insurance.loss-ratio Unreviewed

Loss ratio, expense ratio and combined ratio in basis points, from earned premium, incurred claims and expenses.

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

Pinned by 12 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 three headline underwriting ratios for a period, in basis points (6500 = 65%):

- **loss ratio** = incurred claims / earned premium - **expense ratio** = expenses / earned premium - **combined ratio** = (incurred claims + expenses) / earned premium

For example

  • loss_ratios(£1,000,000.00, £650,000.00, £300,000.00, half-up) → loss ratio basis points 65%, expense ratio basis points 30%, combined ratio basis points 95% 65% claims and 30% expenses make a 95% combined ratio
  • loss_ratios(£3.00, £1.00, £1.00, half-up) → loss ratio basis points 33.33%, expense ratio basis points 33.33%, combined ratio basis points 66.67% the combined ratio is rounded once: 33.33% and 33.33% but 66.67% together
  • loss_ratios(£3.00, £1.00, £1.00, down) → loss ratio basis points 33.33%, expense ratio basis points 33.33%, combined ratio basis points 66.66% the same rounded down

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 loss_ratios(earned_premium: &Money, incurred_claims: &Money, expenses: &Money, mode: &str) -> LossRatios
earned_premiumMoneypremium earned in the period, more than 0
incurred_claimsMoneyclaims incurred in the period; negative when reserve releases outweigh new claims
expensesMoneyacquisition and administration expenses, commission included
modeRoundingModehow each ratio rounds to a whole basis point
returnsLossRatios

The type it declares, generated into your project

/// The three ratios, each in basis points: 6500 = 65%.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct LossRatios {
    pub loss_ratio_basis_points: i64,
    pub expense_ratio_basis_points: i64,
    /// claims plus expenses over premium, rounded once; may differ by 1 from the sum of the other two
    pub combined_ratio_basis_points: i64,
}

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

fune!(insurance.loss-ratio@^1);  // then call loss_ratios(…)
impl/rust.rs · 42 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.

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::math_round_div::round_div;  ← from math.round-div ^1.0.0 · built alongside by fune
use super::money_amount::{assert_same_currency, money_from_value, Money};  ← from money.amount ^1.0.0 · built alongside by fune

/// Loss, expense and combined ratios against earned premium, in basis points.
///
/// The combined ratio is worked from claims plus expenses, rounded once, not
/// by adding the two rounded ratios, so it can differ from their sum by one
/// basis point: 1.00 and 1.00 on 3.00 are 33.33% each but 66.67% together.
///
/// # Panics
/// Panics on mixed currencies or an earned premium that is not positive.
pub fn loss_ratios(earned_premium: &Money, incurred_claims: &Money, expenses: &Money, mode: &str) -> LossRatios {
    assert_same_currency(earned_premium, incurred_claims);
    assert_same_currency(earned_premium, expenses);
    if earned_premium.minor <= 0 {
        panic!("earnedPremium must be more than zero, received {}", earned_premium.minor);
    }
    let p = earned_premium.minor;
    LossRatios {
        loss_ratio_basis_points: round_div(incurred_claims.minor * 10000, p, mode),
        expense_ratio_basis_points: round_div(expenses.minor * 10000, p, mode),
        combined_ratio_basis_points: round_div((incurred_claims.minor + expenses.minor) * 10000, p, mode),
    }
}

pub fn loss_ratios_to_value(r: &LossRatios) -> Value {
    Value::obj(vec![
        ("lossRatioBasisPoints", Value::Int(r.loss_ratio_basis_points)),
        ("expenseRatioBasisPoints", Value::Int(r.expense_ratio_basis_points)),
        ("combinedRatioBasisPoints", Value::Int(r.combined_ratio_basis_points)),
    ])
}

pub fn fune_vector(args: &[Value]) -> Value {
    loss_ratios_to_value(&loss_ratios(
        &money_from_value(&args[0]),
        &money_from_value(&args[1]),
        &money_from_value(&args[2]),
        args[3].as_str(),
    ))
}

Install

fune build

With that line in your source, in a Rust project (language rust in fune.project), fune build resolves it and its 2 dependencies, 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.loss-ratio
Download for Rust insurance.loss-ratio-1.0.1-rust.fune · 11,555 bytes sha256 2777a644097c2ce9f28441c6f9b92d977df03b25ca7f25b2f5e8203f16a46442

The manifest, vectors and README with only the Rust implementation. Install it without the registry with fune add ./insurance.loss-ratio-1.0.1-rust.fune, or fetch it from a terminal with fune pull insurance.loss-ratio@1.0.1:rust.

The whole function, every language, is one file too: insurance.loss-ratio-1.0.1.fune, 13,994 bytes, sha256 ead1e8afc8af61bdb43581a65bd1f4a3c88a8b48c6b97e1f1a676c0c8e05590e. 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.loss-ratio

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

// fune: after insurance.loss-ratio

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.round-div in insurance.loss-ratio
// fune: replace money.amount in insurance.loss-ratio

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.loss-ratio --steps.

// fune: step insurance.loss-ratio 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
65% claims and 30% expenses make a 95% combined ratio £1,000,000.00, £650,000.00, £300,000.00, half-up → loss ratio basis points 65%, expense ratio basis points 30%, combined ratio basis points 95%
the combined ratio is rounded once: 33.33% and 33.33% but 66.67% together £3.00, £1.00, £1.00, half-up → loss ratio basis points 33.33%, expense ratio basis points 33.33%, combined ratio basis points 66.67%
the same rounded down £3.00, £1.00, £1.00, down → loss ratio basis points 33.33%, expense ratio basis points 33.33%, combined ratio basis points 66.66%
an underwriting loss: combined above 100% £1,000.00, £1,200.00, £250.00, half-up → loss ratio basis points 120%, expense ratio basis points 25%, combined ratio basis points 145%
no claims £1,000.00, £0.00, £300.00, half-up → loss ratio basis points 0%, expense ratio basis points 30%, combined ratio basis points 30%
reserve releases outweighing new claims give a negative loss ratio £1,000.00, -£50.00, £300.00, half-up → loss ratio basis points -5%, expense ratio basis points 30%, combined ratio basis points 25%
half a basis point rounds to even £200.00, £0.01, £0.00, half-even → loss ratio basis points 0%, expense ratio basis points 0%, combined ratio basis points 0%
half a basis point rounds up half-up £200.00, £0.01, £0.00, half-up → loss ratio basis points 0.01%, expense ratio basis points 0%, combined ratio basis points 0.01%
a negative half rounds away from zero half-up £200.00, -£0.01, £0.00, half-up → loss ratio basis points -0.01%, expense ratio basis points 0%, combined ratio basis points -0.01%
no earned premium is refused £0.00, £1.00, £0.00, half-up → error: earnedPremium must be more than zero
Show the other 2 tests
CaseArgumentsExpected
negative earned premium is refused -£1.00, £1.00, £0.00, half-up → error: earnedPremium must be more than zero
claims in another currency are refused £1.00, €1.00, £0.00, half-up → error: currency mismatch

More from the author

Below 10000 (100%) the book made an underwriting profit.

## Choices

- Everything is over **earned** premium, the usual UK and IFRS 17 practice and what most published combined ratios use. US statutory reporting puts expenses over *written* premium instead; for that, call this twice or work the expense ratio with `math.round-div` directly. - The combined ratio is worked from the totals and rounded once, not by adding two rounded ratios, so it can differ by one basis point from their sum (1.00 and 1.00 on 3.00: 33.33% + 33.33%, combined 66.67%). If a report must add up, show the combined ratio from this and derive the display of the others from it, not the other way round. - Incurred claims may be negative in a period where reserve releases outweigh new claims (see `insurance.claim-reserve` for incurred movements), and the ratio is then negative rather than refused. - Earned premium must be more than zero: a ratio over nothing is undefined. - What counts as an expense (commission, acquisition costs, claims handling costs) is the caller's reporting policy.

## 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,443
impl/python.py1,169
impl/rust.rs1,784
impl/typescript.ts1,176
vectors.json4,178