Functional Weave
Code in Python

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.

def loss_ratios(earned_premium: Money, incurred_claims: Money, expenses: Money, mode: RoundingMode) -> 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

@dataclass(frozen=True)
class LossRatios:
    """The three ratios, each in basis points: 6500 = 65%."""

    loss_ratio_basis_points: int
    expense_ratio_basis_points: int
    #: claims plus expenses over premium, rounded once; may differ by 1 from the sum of the other two
    combined_ratio_basis_points: int

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

from fune.insurance.loss_ratio import loss_ratios  # insurance.loss-ratio@^1
impl/python.py · 22 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.

from .insurance_loss_ratio_types import LossRatios
from .math_round_div import RoundingMode, round_div  ← from math.round-div ^1.0.0 · built alongside by fune
from .money_amount import Money, assert_same_currency  ← from money.amount ^1.0.0 · built alongside by fune


def loss_ratios(earned_premium: Money, incurred_claims: Money, expenses: Money, mode: RoundingMode) -> LossRatios:
    """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.
    """
    assert_same_currency(earned_premium, incurred_claims)
    assert_same_currency(earned_premium, expenses)
    if earned_premium.minor <= 0:
        raise ValueError("earnedPremium must be more than zero, received %d" % (earned_premium.minor,))
    p = earned_premium.minor
    return 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),
    )

Install

fune build

With that line in your source, in a Python project (language python in fune.project), fune build resolves it and its 2 dependencies, pins them in fune.lock, downloads only the Python 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.loss-ratio
Download for Python insurance.loss-ratio-1.0.1-python.fune · 10,924 bytes sha256 d3d6347c26dbef37918200e25a893ab611ca058c4d74468242a32e592c466e4a

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

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