Skip to content

An example: a workbook tried everywhere its inputs can go; the credit loss workbook fixed where it found a flaw - #112

Merged
matthewjones372 merged 7 commits into
mainfrom
claude/eager-keller-5jqwz9
Nov 19, 2026
Merged

matthewjones372 merged 7 commits into
mainfrom
claude/eager-keller-5jqwz9

Conversation

@matthewjones372

@matthewjones372 matthewjones372 commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

A spreadsheet model is checked by putting in a few cases and looking at the answers. audit reads a workbook with watershed-xlsx and runs it over the whole of its inputs' ranges, to find where it breaks, and against a later version of itself, to show what a change moved.

cargo run --release -p watershed-gpu --example audit
cargo run --release -p watershed-gpu --example audit -- model.xlsx \
    "Inputs!B4=1000:500000" "Inputs!B6=1:40:1" "Results!B9" --against model_v2.xlsx 500000

A cell with =low:high is an input and its range, with an optional step (1:40:1 is whole numbers); a cell alone is an answer.

What it reports

  1. Everywhere. Points spread over the inputs' ranges, and every corner of them. For each answer: its least and greatest, and where it is an error or negative, with the inputs those points have in common.
  2. One input at a time. Each input moved through its range from 300 starting points, the rest held. For each answer: whether it rises, falls, turns round or does not move, and where it jumps. Where a few lines go against the rest, it gives one of them.
  3. Against another version. The cells whose formula or typed value changed. Then both workbooks run for the same points: which answers differ, at how many points, by how much, and what the inputs of those points have in common.

A step that stands out on a line is only a suspect. For an input that does not move in steps, each suspect is closed in on by halving the step forty times; it is reported as a jump only if the answer still differs across it. That is what tells a jump from a steep slope.

It finds things to look at. Whether a jump or a turn is a mistake is for whoever knows the model.

On its own

With no workbook given it takes credit_loss.xlsx (#111) and credit_loss_changed.xlsx, a later version that shared/credit_loss.py now also writes, with two changes:

  • Meant: a loan's chance of default must be three times what was expected, not twice, to move to stage 2 (Model!B18).
  • A slip: in quarter 57 of the better path, the chance of default reads the expected path's unemployment (Schedule!R61).

It finds both cells. The provision differs at 4.9% of points, none of them in default. The loss over a loan's life differs at 27.4% of points, all with 57 quarters or more left, by at most 0.0025%. The loss over the next year is the same everywhere. That run asserts those findings, so it is a test as well.

The flaw it found in the credit loss workbook, and the fix

Run on the workbook as #111 had it, the audit showed some loans' provisions falling as they passed 90 days past due (111,238 to 106,722 for one). I had not planted that. A loan in default was given the loss on a sale at today's prices, where a loan's lifetime loss allowed for prices falling on each path.

The workbook now sells a property some quarters after a default (Model!B14, six), at that quarter's prices on each path. This applies in every quarter of the schedule and to a loan already in default. With it, the provision rises with days past due on all 300 lines the audit tries.

What this changes in credit_loss:

  • The workbook has 3,146 formulas, 3,124 of them between the loan and its provision (was 2,822 and 2,818). It now also uses INDEX.
  • LibreOffice's reference for 300 loans was made again: 17.4 ms a loan, and the furthest answer is 8×10⁻¹⁶ of LibreOffice's.
  • The 200,000-loan book sets aside £310.8m (was £320.0m) and runs in 5.4 s on the same 4 cores.

The audit still shows the lifetime loss falling a little as today's chance of default nears nine in ten. That is left for a reader to judge, and the README says so.

Also in this change

  • Workbook::cells() in watershed-xlsx: every cell that holds a value or a formula, with a test. The comparison of versions needs it.
  • CI's Examples job runs audit -- 20000.

Measured

On a 4-core cloud VM, one run of audit: 200,128 points in about 5.5 s, the 222,300 points of the lines in 6.3 s, the second workbook in 5.5 s; 17.5 s in all.

Checks

cargo fmt --check, clippy with and without --features cuda, cargo doc and watershed-xlsx's tests pass, and both examples' CI commands pass locally. Nothing here has run on a GPU; with --features cuda every run goes to the GPU.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v

Expressions, formulas and scenario plans have floor, on the CPU and in
the GPU kernel. It takes the last of a plan's 32 instruction codes.

watershed-xlsx builds the four rounding functions on it, for a number
that depends on a varied input and a fixed number of places. A number
within four parts in 10^16 of a half or a whole number is taken as it,
which is how 0.29 * 100 comes to 29 and 1.005 to 1.01 as they do in
Excel. The test workbook gains a Rounding sheet: sixteen formulas over
396 pairs of inputs, held to LibreOffice's values.

Nothing here has run on a GPU.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v
credit_loss reads a workbook that works out the expected credit loss on
one mortgage, on three paths of the economy, and runs its formulas for
every loan of a made-up book at once. It checks itself against the values
saved in the workbook, against LibreOffice recalculating the workbook for
each of 300 loans, and against the graph bit for bit. Then it works the
book out again for twenty slumps, worse and likelier.

The workbook and the reference are written by shared/credit_loss.py.

Nothing here has run on a GPU.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v
It read the reported edits once, as soon as the cell showed its old
value. With a WorkerTable the report comes after the cell repaints, so
the read could find one edit, not two. It now waits for the second, as
the file's other tests do.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v
audit runs a workbook for points spread over the whole of its inputs'
ranges and at every corner of them, and says where an answer is an error
or negative. It moves each input through its range from many starting
points and says whether each answer rises, falls or turns round, and
where it jumps, closing in on each suspected jump to confirm it. Given a
later version of the workbook, it lists the cells changed and runs both
for the same points, to show which answers moved and for which inputs.

On its own it takes the credit_loss workbook and a later version that
shared/credit_loss.py writes with one change that is meant and one slip,
and checks that it finds both and where the slip reaches.

Workbook::cells lists every cell that holds a value or a formula.

Nothing here has run on a GPU.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v
A loan in default was given the loss on a sale at today's prices, where
a loan's lifetime loss allowed for prices falling on each path. For some
loans the provision then fell as they passed 90 days past due, which the
audit example showed.

A property is now sold some quarters after a default (Model!B14, six),
at that quarter's prices on each path, in every quarter of the schedule
and for a loan already in default. The provision rises with days past
due on every line the audit tries.

Both workbooks and LibreOffice's reference are written again.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AdzBXf3FUMtMeaNSmdF32v
@matthewjones372 matthewjones372 changed the title An example: a workbook tried everywhere its inputs can go An example: a workbook tried everywhere its inputs can go; the credit loss workbook fixed where it found a flaw Nov 19, 2026
@matthewjones372
matthewjones372 merged commit cc1f335 into main Nov 19, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants