Supporting project P1 · Credit risk analytics · Public data (Freddie Mac SFLLD, 2014 vintage sample)
Which mortgages default — and by how much?
A full statistical workflow on 50,000 real US mortgages (3.39 million monthly records): audited ingestion, risk-factor analysis, and a logistic model validated out-of-cohort — executed under licence terms that never let a raw row leave its owner.
What is real and what isn't — on this page
Real
- Every number: computed from the authentic Freddie Mac 2014-vintage sample files (50,000 loans), fetched under free research registration.
- Every chart: rendered from aggregate tables that passed two independent verification passes (sums, joins, and a from-scratch re-parse of the origination file).
- The model, its coefficients, confidence intervals and validation metrics: computed by
R/02_model.R— output reproduced in full below. - The six documented build bugs and data traps (trailing pipes, NA codes, unmatched reference files…), in
AI_GOT_IT_WRONG.md.
Not on this page (by design and by licence)
- No loan-level rows anywhere online — licence prohibits re-posting raw or derived records; the aggregate layer is the only data here.
- No claim that US mortgage conclusions apply to Nigerian lending — only the method transfers.
- No production-readiness claim: this is a statistical study of one vintage, not a deployable scorecard.
- No AI hype: code was AI-assisted, and every failure it caused was caught by checks — documented, count and all.
00 The two-minute version
Headline: on 50,000 real 2014-vintage US mortgages, a logistic model fitted only on earlier originations predicts later ones at almost exactly the right rates — out-of-cohort calibration slope 1.02 (ideal 1.00) on 33,691 unseen loans; FICO is the dominant divider, 17.0% vs 1.5% default across the extreme bands.
- Business question
- Which origination factors move mortgage default risk — and does a model trained on earlier loans still price later ones correctly?
- Data
- 50,000 real loans (Freddie Mac SFLLD 2014 sample), 3,394,276 monthly records; licence-safe aggregates only, every table verified twice. REAL
- Method
- Audit-first base-R ingestion → locked default definition (ever 90+ days delinquent) → grouped-binomial logistic model → out-of-cohort (origination-time) validation (train 16,275 loans; test 33,691). REAL
- Result
- Clean monotone FICO ladder (adjusted odds 6.9× between extreme bands, 95% CI 4.5–10.5); LTV effect appears only ≥90%; undisclosed DTI defaulting at 8.6% — worse than every disclosed band; riskiest 20% of cells capture 47% of unseen defaults. REAL
- Recommendation
- For a book like this: price sub-700 FICO materially higher, and treat missing DTI as a red-flag feature, not noise. Magnitudes are US-specific — the discipline transfers, the numbers don't.
- Limitations
- One vintage; banded aggregates (licence constraint); ~19% of loans observed <24 months; cell-level AUC ≈0.69 understates loan-level maximum.
- Next steps
- Second vintage · survival/competing-risks framing · approval-cutoff and stability extension (now in the repository:
R/03_cutoff_stability.R).
01The Problem
If you lend money on homes, three numbers decide whether a loan is safe: the borrower's credit score, how leveraged the property is (loan-to-value), and why the loan exists. This project quantifies that intuition on real data and stress-tests whether a model built on older originations still explains newer ones.
The framing statistic of the study: only 3.872% of these 50,000 prime-era mortgages ever reached 90+ days delinquent in 12+ years of observation — so the interesting questions are discrimination (can we rank risk?), calibration (are rates predicted accurately?), and stability over time — not raw accuracy. "96% of my model's predictions were correct" would mean nothing here; predicting "nobody defaults" scores 96.1%.
02The Data
One vintage-year random sample: 50,000 loans originated in 2014, each tracked monthly from acquisition to March 2026 or termination (3,394,276 rows). Pipe-delimited text, no header rows — schema comes from the official file layout.
| Dataset / document | Publisher | URL | Verified | Licence | Content | Used for | Status | Limits |
|---|---|---|---|---|---|---|---|---|
| SFLLD vintage sample — origination file | Freddie Mac | freddiemac.com/research/datasets/sf-loanlevel-dataset → Clarity Data Download | 2026-10-21 | Free research registration; redistribution prohibited | 50,000 rows × 31 fields | Risk factors (FICO, DTI, LTV, purpose…) | REAL — never published | Sample ≠ population; one vintage |
| SFLLD vintage sample — performance file | Freddie Mac | same as above | 2026-10-21 | same | 3,394,276 rows × 35 fields, periods 201401–202603 | Outcome construction (delinquency, termination) | REAL — never published | Censoring (81.6% prepay early) |
| File layout, headers, general user guide (July 2026) | Freddie Mac | freddiemac.com/fmac-resources/research/ (public) | 2026-10-21 (downloaded) | Public documentation | 31 + 35 field schemas; code definitions | Schema, data dictionary, automated checks | REAL | July-2026 layout ≠ older releases |
| Free Terms & Conditions (SFLLD) | Freddie Mac | capitalmarkets.freddiemac.com/crt/docs/pdfs/fre_terms_conditions_sflld.pdf | 2026-10-21 | Terms document | 2 pages | Defines the aggregates-only architecture | REAL | — |
| Release-47 public reference sample | Freddie Mac (public) | freddiemac.com/fmac-resources/research/docs/release-47-sample-files.zip | 2026-10-21 | Public | 1,000 + 1,011 rows | Pipeline smoke test only | REAL (format examples — 0 shared loan IDs, verified) | Not a matched dataset; never analysed |
| Verified aggregate layer (16 files) | This project | data/aggregates/ (repository) | 2026-10-21/24 | Derived non-recreatable aggregates — publishable per terms | Band tables, cell tables, tallies + verification log | Modelling input; all charts on this page | REAL, twice-reconciled | Small cells (n<10) suppressed: 34 loans, 1 default excluded & disclosed |
03The Process
How an "I can't upload the file" problem became a better, licence-proof design — the pipeline moves to the data, and every returned number is treated as untrusted until independently re-verified.
- Schema first, code second. Field maps were built from the official July-2026 file layout — 31 origination + 35 performance fields — before writing parsers. The import script (
01_import_checks.R) measures row width by pipe-count (a trailing|made strsplit under-count in tests), aborts loudly on unknown layouts, and refuses to run on unverified input. - Automated audit battery. Field-width distribution, row/loan counts, duplicate-ID scan, range checks against the data dictionary (FICO 300–850; DTI ≤65; LTV 6–105 for this era), missingness per key field, and the one that mattered most early: the loan-ID join check (Freddie's public "reference sample" turned out to contain zero shared IDs between its two files — format examples, not mini-data; the real vintage sample joined 50,000/50,000).
- Missing-value codes cleaned before analysis.
999/9999disclosures recoded to NA with explicit "Not Available" categories kept — because EDA later proved undisclosed-DTI loans default at 8.6% vs 4.0% max visible band. Deleting them would have deleted signal. - Locked outcome definition before modelling. Default ≡ ever delinquency status ≥ 03 (90+ days) — a definition that subsumes REO acquisitions (82 loans) and adverse terminations (171 loans: short-sale/charge-off/third-party/REO disposition), verified by set arithmetic.
- Aggregates-only relay + independent verification. Aggregate tables were computed data-owner-side; on return, every table was re-summed (all equal 50,000 / 1,936), join counts re-checked, and band counts reconciled against a from-scratch re-parse of the origination file before being accepted into
data/aggregates/. - AI-assisted, QA-first. Code was built with AI assistance and six real bugs/traps were caught and logged before any output shipped — published as
AI_GOT_IT_WRONG.mdin the repository because the debugging record is part of the competence on display.
04What the data showed
Each chart below comes with the "so what" it forced into the modelling decision.
05The Model
A grouped-binomial logistic regression — the classical GLM where each row is a band-combination cell with defaults vs non-defaults. It is exactly what the licence allows to travel, and R fits it natively with proper weights, standard errors and confidence intervals.
cbind(defaults, n − defaults) ~ fico_band + ltv_band + purpose · fitted on the H1 cells only (loans first-paid Jan–Jun 2014: 16,275 loans, 642 defaults) · references = safest cells (FICO ≥780, LTV <60, purchase) · overdispersion φ = 1.28 → native binomial SEs retained (quasi-binomial fallback pre-wired).| Term | Odds ratio | 95% CI | p-value | Reading |
|---|---|---|---|---|
| FICO <620 (vs ≥780) | 6.88 | 4.49 – 10.55 | <0.001 | ≈7× the default odds of the cleanest-score cell |
| FICO 620–659 | 5.83 | 4.18 – 8.12 | <0.001 | gradient holds band by band |
| FICO 660–699 | 4.45 | 3.36 – 5.90 | <0.001 | — |
| FICO 700–739 | 3.04 | 2.30 – 4.00 | <0.001 | — |
| FICO 740–779 | 1.65 | 1.23 – 2.20 | <0.001 | still measurably riskier than ≥780 |
| LTV 60–89 (vs <60) | 1.03 – 1.25 | cross 1.0 | not significant | stated honestly — flat region |
| LTV 90–94 | 1.48 | 1.03 – 2.13 | 0.033 | risk surface lifts at ~90% |
| LTV 95–105 | 1.94 | 1.43 – 2.64 | <0.001 | — |
| LTV 106+ | 2.65 | 1.87 – 3.76 | <0.001 | the flagged outlier cells are really riskier — after adjusting for FICO & purpose |
| Purpose: cash-out refi (vs purchase) | 1.39 | 1.05 – 1.83 | 0.022 | — |
| Purpose: no-cash-out refi | 1.87 | 1.52 – 2.29 | <0.001 | the counterintuitive EDA finding survives adjustment |
Baseline (intercept): a FICO≥780 · LTV<60 · purchase loan carries a fitted lifetime-default probability of ≈0.9%. Full machine-readable coefficient set: model_outputs/coefficients_or.csv.
06Does it hold out-of-cohort?
Train quarters (Jan–Jun 2014) were never seen by the test: the model was scored on H2 — 33,691 loans originated later (Jul 2014 → 2015 spillover).
| Metric (H2 holdout) | Value | Honest label |
|---|---|---|
| Test base rate | 3.838% (1,293 / 33,691) | exact — computed |
| Calibration intercept (in-the-large) | 0.086 | exact (offset GLM) · 0 = perfect |
| Calibration slope | 1.016 | exact (offset GLM) · 1 = perfect |
| AUC / Gini | ≈0.69 / ≈0.39 | cell-level approximation — within-cell risk assumed homogeneous; a loan-level score would sit a little higher |
| Brier (cell-weighted) vs base-rate null | 0.00024 vs 0.00121 → skill 0.80 | cell-level: loan-level Brier is higher by the within-cell variance — not comparable to loan-level benchmarks |
| Top-20% predicted-risk cells | capture 47.1% of all test defaults | exact — computed |
| Excluded cells | 34 loans, 1 default | suppressed (n<10) upstream — disclosed, never hidden |
07Limits — said before you ask
- Right-censoring & competing risks. 81.6% of loans prepaid early; "ever-default by Mar-2026" is a lifetime outcome. A production build needs a survival/competing-risk model — named here because this page doesn't pretend otherwise.
- Banded resolution. The licence caps us at aggregates, so FICO entered as 6 bands, not a continuous score — discrimination is understated by design; the tradeoff was legal necessity and is priced into the wording.
- One vintage, one split. H1→H2 is a true origination-time test but a single macro regime. A second vintage (e.g. 2016/2017) re-uses this exact pipeline unchanged; queued, not faked.
- Scope discipline: US agency mortgages generalize as method, never as effect sizes, to Nigeria or anywhere else. Nothing here is a lending recommendation.
- AI assistance disclosed: code was AI-assisted; all six build-breaking bugs it introduced are logged with fixes in
AI_GOT_IT_WRONG.md. Verification, definitions, and interpretations are mine.
08Why this matters to a hiring team
- Comfortable with real-world ugliness: no-header pipes, NA codes, drifting layouts, unmatched reference files — handled with checks, never vibes.
- Governance literacy that is rare at entry level: the licence shaped the architecture itself. If your organisation's data can't leave the building, this page is the proof-of-pattern.
- Statistical judgement over tool flash: imbalance recognised → calibration-first evaluation → honest approximations with labels, rather than a borrowed "94% accuracy".
- End-to-end finish: ingest checks, EDA with "so what"s, model with CIs, out-of-cohort (origination-time) validation, model card, exec brief, chart pack, and a debugging paper trail.
09Tools used
- R (base, zero-dependency): chunked pipe importer, audit battery, rollup, grouped-binomial GLM, calibration machinery —
R/01_import_checks.R,R/02_model.R(seeded, commented for explanation). - Python: report parsing into the verified aggregate CSVs; matplotlib chart rendering.
- Statistics: grouped logistic regression, overdispersion testing, offset-GLM calibration intercept/slope, Mann–Whitney cell-approximation AUC.
- Practice: small-cell suppression (n<10), reproducible-file discipline, licence-aware data handling, AI-assistance disclosure with a bug ledger.
Named paths (R/…, AI_GOT_IT_WRONG.md, SOLUTIONS_LOG.md) are relative to this project's repo folder — browse the files on GitHub ↗ (verified live 2026-10-25).