Functional Weave
Code in Python

lending.ltv Unreviewed

Loan-to-value ratio in basis points, and the band it falls in from a band table you supply.

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

Pinned by 17 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 consumer-credit compliance specialist 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 lending 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 consumer-credit compliance specialist review how you use it, before anyone relies on the output. Provided “as is” under its licence, without warranty.

What it does

Loan-to-value: the loan as a share of the property's value, in basis points (7500 = 75%), and which band of the lender's table it falls in. Mortgage pricing is set by LTV band, so the band is what a rate lookup needs.

## Bands are yours, and inclusive

For example

  • loan_to_value(£225,000.00, £300,000.00, bands ×5) → rate 75%, band 75% LTV £225,000 on a £300,000 house is exactly 75%
  • loan_to_value(£225,000.01, £300,000.00, bands ×5) → rate 75.01%, band 85% LTV a penny over 75% is the 85% band
  • loan_to_value(£180,000.00, £300,000.00, bands ×5) → rate 60%, band 60% LTV £180,000 on £300,000 is exactly 60%

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 loan_to_value(loan: Money, property_value: Money, bands: Sequence[LtvBand]) -> LtvResult
loanMoneythe amount borrowed or outstanding, zero or more
property_valueMoneythe valuation or price, whichever is lower by the lender's policy; greater than zero
bandsLtvBand[]ceilings in strictly ascending order; a loan belongs to the first band it fits under
returnsLtvResult

The types it declares, generated into your project

@dataclass(frozen=True)
class LtvBand:
    """One row of a lender's LTV table."""

    #: the band's ceiling, inclusive: 7500 = up to and including 75%
    max_basis_points: int
    #: e.g. "75% LTV"
    label: str

@dataclass(frozen=True)
class LtvResult:
    """The ratio and its band."""

    #: loan / value, rounded up to the next basis point
    basis_points: int
    #: the first band whose ceiling the exact ratio is within; null above the top band
    band: Optional[str]

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

from fune.lending.ltv import loan_to_value  # lending.ltv@^1
impl/python.py · 39 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 typing import Sequence

from .lending_ltv_types import LtvBand, LtvResult
from .math_round_div import round_div  ← from math.round-div ^1.0.0 · built alongside by fune
from .money_amount import Money  ← from money.amount ^1.0.0 · built alongside by fune

#: Above this, loan * 10000 is no longer exact as a JavaScript number.
_MAX_LOAN = 900719925474


def loan_to_value(loan: Money, property_value: Money, bands: Sequence[LtvBand]) -> LtvResult:
    """Loan-to-value, and the band from the lender's table.

    The band is chosen on the exact ratio, loan * 10000 <= ceiling * value,
    never on a rounded percentage, so 75.004% is not "75%". The reported basis
    points are rounded up, which agrees: a whole ceiling is met exactly when
    the rounded-up ratio is within it.
    """
    if loan.currency != property_value.currency:
        raise ValueError("currency mismatch: %s and %s" % (loan.currency, property_value.currency))
    if property_value.minor <= 0:
        raise ValueError("propertyValue must be greater than zero, received %r" % (property_value.minor,))
    if loan.minor < 0:
        raise ValueError("loan must not be negative, received %r" % (loan.minor,))
    if loan.minor > _MAX_LOAN:
        raise ValueError("loan must be at most %d minor units" % (_MAX_LOAN,))
    if len(bands) == 0:
        raise ValueError("bands must not be empty")
    for i, band in enumerate(bands):
        ceiling = band.max_basis_points
        if isinstance(ceiling, bool) or not isinstance(ceiling, int) or ceiling < 1:
            raise ValueError("band ceilings must be whole basis points of 1 or more, received %r" % (ceiling,))
        if i > 0 and ceiling <= bands[i - 1].max_basis_points:
            raise ValueError("band ceilings must be in strictly ascending order")
    basis_points = round_div(loan.minor * 10000, property_value.minor, "up")
    for band in bands:
        if basis_points <= band.max_basis_points:
            return LtvResult(basis_points=basis_points, band=band.label)
    return LtvResult(basis_points=basis_points, band=None)

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 lending.ltv
Download for Python lending.ltv-1.0.1-python.fune · 17,284 bytes sha256 ba48062c3c33be274de81f285bd4775f893f32f14cfed222edf6f0aa31436ba7

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

The whole function, every language, is one file too: lending.ltv-1.0.1.fune, 22,236 bytes, sha256 63eed277bff3fe7d0cbfa30ba2ea54b4c963b0e535b95f461a1043a8f7bd4a3c. 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 lending.ltv

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

# fune: after lending.ltv

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 lending.ltv
# fune: replace money.amount in lending.ltv

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 lending.ltv --steps.

# fune: step lending.ltv 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
£225,000 on a £300,000 house is exactly 75% £225,000.00, £300,000.00, bands ×5 → rate 75%, band 75% LTV
a penny over 75% is the 85% band £225,000.01, £300,000.00, bands ×5 → rate 75.01%, band 85% LTV
£180,000 on £300,000 is exactly 60% £180,000.00, £300,000.00, bands ×5 → rate 60%, band 60% LTV
a small loan is in the lowest band £50,000.00, £400,000.00, bands ×5 → rate 12.5%, band 60% LTV
a ratio with a fraction of a basis point rounds up £100,000.00, £300,000.00, bands ×5 → rate 33.34%, band 60% LTV
95% exactly £285,000.00, £300,000.00, bands ×5 → rate 95%, band 95% LTV
above the top band has no band £290,000.00, £300,000.00, bands ×5 → rate 96.67%, band —
negative equity: more than 100% £330,000.00, £300,000.00, bands ×5 → rate 110%, band —
a zero loan is 0% £0.00, £300,000.00, bands ×5 → rate 0%, band 60% LTV
one band table £90,000.00, £100,000.00, bands ×1 → rate 90%, band all
Show the other 7 tests
CaseArgumentsExpected
a zero value is refused £1.00, £0.00, bands ×5 → error: propertyValue must be greater than zero
a negative loan is refused -£0.01, £1.00, bands ×5 → error: loan must not be negative
an empty band table is refused £1.00, £10.00, → error: bands must not be empty
bands out of order are refused £1.00, £10.00, bands ×2 → error: strictly ascending
a zero ceiling is refused £1.00, £10.00, bands ×1 → error: band ceilings must be whole basis points
mixed currencies are refused £1.00, €10.00, bands ×5 → error: currency mismatch
a loan beyond exact arithmetic is refused £9,007,199,254.75, £10,000,000,000.00, bands ×5 → error: loan must be at most

More from the author

The band table is an argument, because every lender's differs. Each band is a ceiling, inclusive: a band of 7500 holds everything up to and including 75%. Bands must be in strictly ascending order, and the loan goes in the first band whose ceiling it is within. Above the top band, `band` is null: the loan is outside the table (for example negative equity above 100%), which the caller must handle rather than silently getting the top band.

## Exact at the boundary

The band is decided on the exact ratio, never on a rounded percentage: £225,000 on £300,000 is exactly 75% and is in the 75% band; one penny more is 75.0000033% and is not. The reported `basisPoints` is rounded up (math.round-div "up"), so it never understates the ratio, and it always agrees with the band: a whole ceiling holds the exact ratio exactly when it holds the rounded-up one.

## What it does not do

It does not decide which value to use (valuation or purchase price, usually the lower) or add fees to the loan; pass the figures your policy uses. A zero loan is 0%. The value must be positive, and the loan at most about £9 billion in pence (900,719,925,474 minor units), where loan × 10000 stays exact in every language.

## Before you rely on this

**Not professional advice.** This capability calculates lending 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 a consumer-credit compliance specialist 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 consumer-credit compliance specialist 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,607
impl/python.py1,965
impl/rust.rs2,770
impl/typescript.ts1,992
vectors.json8,641