# Loan data conversion: which reconciliation catches the faults

When a lender moves its loans onto a new system, the conversion is often signed off once record counts and amount
totals match the old system's. This study converts 568,840 real public loan records from three sources into one loan table in SQL,
plants faults of the kinds conversions make, and measures which reconciliation check catches each one.

The SBA data dictionary spells paid in full PIF, but the 7(a) file writes P I F. A status map built from the
dictionary left 74,600 loans with no status and moved the 7(a) charge-off rate from 2.49% to 3.22%. Record counts and amount
totals still matched; a rule that every converted loan has a status caught it. Totals see only faults that change a
record count or a summed amount. In code they caught all 25 such faults and none of the other 21. They caught none
of the 13 faults in the rule document. On 40 faults drawn at random after the checks were frozen, that came to 17 of 40, a share
set by the fault mix. Totals, 19 rules on the target table and a code census together would catch 17 to 25 of 40. The
high end traces every rule failure on the first run; the low end accepts them all. Both ends are calculated, not measured.
An independent line-by-line rebuild, which catches every fault in code by construction, brings the high end to 36 of 40. The
faults came from the study's own list, and every cost and saving figure is assumed and was chosen after the results.
A second version, declared before it ran, counts a target rule only when its failures rise over the correct
conversion's: the rules then catch 20 of 40, and the quick checks stay at 25. A third version, also declared before it
ran, ties totals to the source system's own units (19 of 40), bounds the quick checks between 17 and 25 of 40, and sizes
a go-live test at one confidence level. A fourth version, also declared before it ran, gives the charge-off reversal
line at the low end (4 of 15 missed), the draws that test needs, and totals by fault kind.

Pages: [the summary](index.html), [the follow-up](fresh.html), [all results](results.html),
[linking lenders](lenders.html), [method and checks](method.html).

## Data

All public federal data. The raw files are not copied here; [data/sources.json](data/sources.json) lists each one with
its URL, licence and sha256.

- SBA 7(a) loans, fiscal year 2020 to September 2026 (403,644 records), and SBA 504 loans, fiscal year 2010 to
  September 2026 (119,599 records), with the SBA data dictionary.
- HMDA mortgage records for Montana in 2017 (45,597 records) and the 2017 reporter panel.
- The FDIC list of insured institutions, active and inactive.

## Files

- [rules/conversion-rules.json](rules/conversion-rules.json): the rule document. The SQL reads its code maps and units.
- [protocol-r1.json](protocol-r1.json) and [predictions-r1.json](predictions-r1.json): the chosen faults, the checks,
  the fresh-fault generator, the lender match and the predictions, written before any fault ran.
- [amendments-r1.json](amendments-r1.json): the one labelled change, a rounding rule, made before any fault ran.
- [assumptions.json](assumptions.json): the money and effort figures, chosen after the results.
- [CHANGES-r2.md](CHANGES-r2.md): the second version's declaration, written before its code.
  [tools/change2.py](tools/change2.py) scores it from the stored results into
  [results/change2-r2.json](results/change2-r2.json).
- [CHANGES-r3.md](CHANGES-r3.md): the third version's declaration, written before its code.
  [tools/change3.py](tools/change3.py) scores it into [results/change3-r3.json](results/change3-r3.json); its totals
  part reads the raw tables in the work database that the prepare step builds.
- [CHANGES-r4.md](CHANGES-r4.md): the fourth version's declaration, written before its code.
  [tools/change4.py](tools/change4.py) scores it from the stored results into
  [results/change4-r4.json](results/change4-r4.json).
- [sql/convert.sql](sql/convert.sql): the conversion. [tools/reference.py](tools/reference.py): the independent rebuild
  in plain Python.
- [tools/checks.py](tools/checks.py): every check. [tools/fresh_faults.py](tools/fresh_faults.py): the generator.
- [tools/run_study.py](tools/run_study.py), [tools/summarize.py](tools/summarize.py),
  [tools/lenders.py](tools/lenders.py): the runs. [results/](results/summary-r1.json): their output.
- [site/render.py](site/render.py): builds the pages; every number comes from results/ or assumptions.json.
- [tests/test_study.py](tests/test_study.py): unit tests and a replay of the stored runs.

## Rebuild

Python 3.12 with duckdb 2.0, and pytest for the tests. From this folder, with a work folder
outside it:

```
python3 -B tools/get_data.py <raw dir>
python3 -B tools/run_study.py prepare <raw dir> <work dir>
python3 -B tools/run_study.py main <raw dir> <work dir>
python3 -B tools/run_study.py fresh <raw dir> <work dir>
python3 -B tools/lenders.py <work dir>
python3 -I -B tools/summarize.py
python3 -I -B tools/change2.py
python3 -B tools/change3.py <work dir>
python3 -I -B tools/change4.py
python3 -I -B site/render.py
python3 -B -m pytest -q tests
```

The tests that replay the runs need the raw files: set `LDC_RAW` to the raw folder and `LDC_REPLAY` to an empty work
folder. Without them, those tests are skipped and the rest run.

The design system files under vendor/ are copied unedited from release 2.3.0 by
[tools/vendor_kit.py](tools/vendor_kit.py); [vendor/viz-design-system-adoption.json](vendor/viz-design-system-adoption.json)
pins each file's sha256.

Some files are packed in loan-data-conversion-data-1.zip; unzip it here to restore the full export, which the manifest lists file by file.
