Functional Weave
Code in TypeScript

lending.ltv@1.0.0

README.md

1,477 bytes · view raw

# lending.ltv

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

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.