bucketroll forecasts next year's charge-offs for an amortising instalment loan book from delinquency roll rates. It estimates count- and balance-weighted transition matrices between the buckets current, 1-29, 30-59, 60-89, 90-119 days past due, charged off and paid off, one matrix per calendar month, and rolls the as-of balances forward through them. Every forecast is checked to the cent: state balances plus cumulative charge-offs, payoffs and principal collected equal the opening book. That check guards the arithmetic, which any row-stochastic matrix passes; whether the estimates are right is tested by a one-step reconciliation of the forecast against the next month of the tape and by the backtests. The model is judged against the flat loss rate it replaces with rolling-origin backtests, and its own assumptions (seasonality, vintage drift, the Markov property) are tested separately. All data is synthetic, produced by a seeded generator in this repository.
A lender that finances home-improvement projects through contractors holds about 30,000 amortising loans and forecasts charge-offs for its budget and loss allowance with a flat rate: trailing-twelve-month charge-offs over average balance, applied to the projected book. That rate misses the tax-refund season when delinquent borrowers catch up, reacts a year late when loans booked under a broken scorecard cut-off start to roll, and treats a borrower behind for the first time the same as one who has been behind before. The flat rate also ignores that a book still growing is younger than its trailing average, so it runs low.
flowchart LR
A[Loan tape and loans<br/>CSV] --> B[validate<br/>delinquency logic]
B --> C[Transitions<br/>loan-month from/to state]
C --> D[Seasonal and pooled<br/>matrices, count and balance]
D --> E[Run-off forecast<br/>balances x matrices]
E --> F[Conservation check<br/>to the cent]
D --> G[Rolling-origin backtest<br/>vs flat loss rate]
C --> H[Vintage GLM<br/>observed vs expected]
C --> I[Markov check<br/>first-time vs repeat B1]
F --> J[report.md<br/>forecast.png]
G --> J
H --> J
I --> J
States are C (current), B1 (1-29 days past due), B2 (30-59), B3 (60-89), B4 (90-119), CO (charged off) and PO (paid off). A loan moves at most one bucket forward a month, only a B4 loan charges off, only a current loan pays off (the validator rejects any other payoff), and a cure goes back to C. In the generator a loan past its term pays off only if it is current; a delinquent one stays in its bucket until it cures or charges off, which the model treats like any other delinquent loan. --split-repeat splits B1 into first-time and repeat (previously 30+ days past due).
The data is synthetic. The generator (generate.py, parameters echoed to truth.json) uses a 2.2% average monthly current-to-B1 probability (1.2% to 4.0% by score band) times 1.25 in December and January and 0.80 in March and April; cure rates out of B1-B4 times 1.30 in March and April; B1 at 45% cure, 25% stay, 30% roll; prepayment 1.4% a month; charge-off on reaching 120 days past due. Two patterns are injected for the analysis to recover: loans booked 2025-01-06 to 2025-03-31 carry 1.7x the current-to-B1 rate (a scorecard cut-off error), and borrowers previously 30+ days past due roll from B1 to B2 at 1.8x the first-time rate with their cure rate unchanged. At full size the tape has about 667,000 rows.
python -m venv .venv && . .venv/bin/activate pip install -e ".[dev]" bucketroll generate --seed 31 --out data/ # about 20 seconds bucketroll validate bucketroll rolls --split-repeat bucketroll forecast --as-of 2026-09-30 --months 12 bucketroll backtest --origins 2024-07:2025-12 --horizon 6 bucketroll vintages bucketroll markov bucketroll report --out out/ # report.md and forecast.png pytest
Every analysis command reads --data data/ by default, refuses a tape that fails validate, and ignores anything after its as-of month.
From bucketroll generate --seed 31 --out data/ (31,350 loans, 2022-01 to 2026-09):
wrote 31,350 loans and 667,331 tape rows to data
bucketroll forecast --as-of 2026-09-30 --months 12. Dollars are balances; the last column is state balances plus cumulative charge-offs, payoffs and principal collected, minus the opening book:
run-off of the 2026-09 book, no new originations
month charge-offs principal payoffs ending balance gap
------- ----------- ---------- ---------- -------------- ------
2026-10 835,997 5,776,872 2,547,884 184,154,477 0.0000
2026-11 1,095,949 5,499,091 2,349,385 175,210,052 0.0000
2026-12 920,152 5,234,625 2,223,962 166,831,313 0.0000
2027-01 904,465 4,981,428 2,089,316 158,856,103 0.0000
2027-02 853,181 4,738,379 2,028,315 151,236,227 0.0000
2027-03 828,787 4,506,221 2,124,711 143,776,509 0.0000
2027-04 825,033 4,292,341 1,792,746 136,866,387 0.0000
2027-05 858,933 4,095,792 1,826,608 130,085,055 0.0000
2027-06 611,100 3,898,194 1,790,388 123,785,373 0.0000
2027-07 491,054 3,708,047 1,545,753 118,040,519 0.0000
2027-08 508,457 3,531,235 1,569,407 112,431,420 0.0000
2027-09 560,357 3,360,221 1,325,264 107,185,579 0.0000
total 9,293,466 53,622,446 23,213,740 0.0000
Origins must start at least 12 months into the tape and before its last month (an origin at the end has no later month to score), or the command exits 2 with a usage error.
bucketroll backtest (18 origins, 2024-07 to 2025-12, data truncated at each origin; WAPE is summed absolute error over summed actual charge-offs, bias is forecast minus actual over actual):
origins 2024-07 to 2025-12, data truncated at each origin
horizon seasonal WAPE pooled WAPE flat WAPE seasonal bias pooled bias flat bias
------- ------------- ----------- --------- ------------- ----------- ---------
1 mo 5.6% 5.4% 12.5% +0.3% +0.3% -1.5%
2 mo 7.2% 7.3% 14.5% +3.5% +3.0% -7.2%
3 mo 7.4% 7.9% 17.8% +3.0% +2.6% -13.0%
4 mo 8.7% 10.7% 22.3% -0.5% -0.5% -19.5%
5 mo 11.8% 14.1% 27.1% -2.6% -4.4% -25.3%
6 mo 14.2% 14.3% 29.7% -5.1% -6.7% -28.3%
The seasonal method wins at 4-5 months and is level with the pooled matrix at 6 months on the full-size book; both are about half the flat rate's error and the flat rate runs 28% low at 6 months. On the 20,000-loan book used by the tests the seasonal method is clearly ahead at 6 months (10.7% against 13.3% pooled and 25.9% flat).
bucketroll vintages (middle rows elided):
vintage exposure observed expected O/E p q (BH)
------- -------- -------- -------- ---- ------- -------
...
2024Q2 36,401 759 813.3 0.93 0.057 0.29
2024Q3 32,258 721 724.6 1.00 0.91 0.91
2024Q4 29,323 633 664.9 0.95 0.22 0.49
2025Q1 25,309 845 553.4 1.53 1.6e-30 3.1e-29
2025Q2 22,576 526 514.3 1.02 0.62 0.73
...
2026Q3 1,635 29 37.8 0.77 0.17 0.49
q < 0.05: 2025Q1
bucketroll markov:
group B1 loan-months rolled to B2 roll rate
---------- -------------- ------------ ---------
first-time 16,165 4,650 28.8%
repeat 689 341 49.5%
rate ratio repeat / first-time 1.72 (95% CI 1.59 to 1.86), p = 4.5e-41
seasonal backtest WAPE, origins 2024-07 to 2025-12, B1 unsplit vs split:
horizon WAPE B1 unsplit WAPE B1 split
------- --------------- -------------
1 mo 5.6% 5.6%
2 mo 7.2% 7.2%
3 mo 7.4% 7.4%
4 mo 8.7% 8.9%
5 mo 11.8% 11.8%
6 mo 14.2% 14.3%
Splitting B1 changes the backtest very little here: only about 4% of B1 loan-months are repeat, and the split cannot see which current loans are repeat.
- Run-off, not a going-concern forecast. The forecast has no new originations, so it answers "what will the book on hand charge off". The backtest scores it against charge-offs from loans open at the origin only, so the three methods are compared on the same population. New loans cannot charge off within five months of booking anyway.
- Balance-weighted by default, shrunk by calendar month. Dollar charge-offs depend on balances, so the matrices weight by the balance after the month's principal; count weighting (the
weightingparameter,--weighting countonrolls) conserves equally, since either way each row is normalised to sum to 1. A calendar-month row has only a few years of observations, so it is blended with the pooled row with weight n / (n + 150) on its own loan-months. Thin rows (B3, B4) lean on the pooled matrix, the current row barely moves.credibilityis a parameter. - Principal is collected before the transition. Each state has a principal rate (collected over opening balance, estimated on the window); the remainder is redistributed by the matrix row. Prepayment is the C-to-PO cell and maturity is a payoff of zero remaining balance, so it carries no weight.
- No look-ahead by construction. Estimation reads only transitions into the window ending at the origin and the opening book is the tape row at the origin. Tests compare a forecast from the full tape with one from the tape cut at the origin, and with future rows overwritten.
- Vintages from a grouped binomial GLM. C-to-B1 is modelled on calendar month, age band and score band over cells of loan-months, and each origination quarter is compared with the sum of its fitted probabilities. The p-value is exact Poisson, two-sided by doubling the smaller tail, with Benjamini-Hochberg across vintages. Expected counts treat the fitted probabilities as Poisson means, which is slightly conservative for probabilities of a few percent.
- The Markov check is a rate ratio, not a model. Repeat versus first-time B1-to-B2 uses a Wald interval on the log ratio and does not adjust for calendar month, so it is a crude screen;
--split-repeatis the remedy it motivates. Splitting only B1 is a deliberate approximation: current loans are not split, so the C-to-B1R share is a pooled average.
80 tests, offline, about 50 seconds. A 20,000-loan book is generated once per session for the statistical checks; the rest use hand-built tapes with counts worked out in the tests.
GITHUB_ACTIONS=true CI=true COLUMNS=80 pytest -q ruff check . && ruff format --check .
They cover the chain fixture (C = 950, D = 50 then C = 922.5, D = 67.5, CO = 10), hand-counted matrices, rows summing to 1 within 1e-12, forbidden cells exactly 0, validator messages that name loan and month, conservation within $0.01 for seasonal, pooled and split runs, a one-step forecast reconciled with the next tape month, the March/October cure ratio, the backtest ranking and no-look-ahead properties, the 2025Q1 vintage and the Markov ratio.
src/bucketroll/
generate.py seeded loan book and tape generator
validate.py delinquency-logic checks
book.py tape loading, transitions, truncation
rolls.py count/balance matrices, seasonal shrinkage, principal rates
forecast.py run-off chain and conservation check
backtest.py rolling-origin backtest, flat loss rate
vintages.py binomial GLM, Poisson p-values, Benjamini-Hochberg
markov.py first-time vs repeat B1 check
summaries.py table views; render.py formats them
report.py report.md and forecast.png
cli.py typer commands
tests/
MIT
