Mortgage Lending in New York, 2022 to 2025

US HMDA New York 2022 to 2025, SQL Data Analytics

PostgreSQL: an analytics project on 1,755,419 real mortgage applications from US Home Mortgage Disclosure Act (HMDA) data, asking who gets access to mortgage credit in New York, on what terms, and whether the answer differs by applicant group once income, product, neighbourhood and lender are held constant. The whole database runs in your browser, with nothing to install.

Tools & Skills

  • PostgreSQL star schema design (partitioned fact table, dimensions, bridge tables)
  • Joins, Subqueries, Window functions, CTEs & shift-share decomposition
  • Data profiling, quarantine rules & executable quality assertions
  • Query performance tuning & index analysis
  • DuckDB WebAssembly playground with an automated PostgreSQL parity test

Approach

Raw regulatory files from the CFPB and the Philadelphia Fed were landed as untouched text, profiled, then modelled into fifteen tables: a year-partitioned fact table, eight dimensions, four bridges, a quarantine table and a code reference. Because the regulator strips every loan identifier, surrogate keys are derived from an MD5 hash of each source row, so the model rebuilds identically on any machine.

Nothing is deleted. Impossible values are quarantined with the rule they broke, and eight assertions gate every build. The data dictionary is generated from the PostgreSQL catalogue itself, so the documentation cannot drift from the database. The work is written up in eleven phases, each one showing at least one thing that went wrong.

Key Findings

  • Debt-to-income is a cliff, not a slope. From 20 to 49 percent the denial rate is flat near 13. At 50 to 60 it is 40.86, and above 60 it is 90.42. Below 20 percent it rises again to 24.49, because that end of the distribution is small second-lien business rather than cautious borrowers.
  • Which lender you ask is worth fifteen times. On one identical product, denial across the 72 largest lenders runs from 1.14 to 31.57 percent. The lowest denies 1.14 percent on applicants who are more leveraged and earn substantially less than those of a lender denying 17.76 percent.
  • Borrowing against a home you own is a different market. 407,382 applications deny at only 7.44 percent but withdraw at 47.59 and close incomplete at 19.27. More applications are lost to abandonment than to refusal.
  • A quarter of the register never reaches a credit decision. A shift-share analysis showed 76% of the rise in denials came from products denying more, the opposite of my own prediction.
  • Collateral is the only denial reason independent of income. It moves three quarters of a point across the income bands while debt-to-income falls from 23.44 to 2.41, so in the highest income band collateral becomes the largest single reason a lender gives.

Data Quality Finding

Profiling found 80,167 rows carrying a code the regulator documents nowhere, and showed that counting HMDA race codes naively overstates multi-race applicants sixfold (106,971 against a true 18,051). Every published row is accounted for: 1,754,846 modelled plus 573 quarantined equals the 1,755,419 published. The parity test then caught something subtler: NUMERIC is arbitrary precision in PostgreSQL and three decimal places in DuckDB, so one rounding step ran twice in one engine and four published figures were wrong in the second decimal. All forty-two queries now agree cell for cell. As HMDA holds no credit score, findings are presented as differences in outcomes, never as proof of cause.

Outcome

A reproducible, fully documented database where every claim is executable. All forty-two published queries open in the browser playground already loaded and run against the real 1.75 million rows, so anyone can check a figure in seconds or write their own SQL queries against the model.