Building a Delinquency Roll Rate Matrix From Monthly Snapshots

Last updated: November 29, 2026

Quick Overview

Given monthly loan snapshots with a delinquency status and balance, write pandas code that builds the month-over-month roll rate matrix (probability of moving from each status to each next status), by count or balance weighted, using only consecutive months.

Upstart
Data Manipulation (SQL/Python)
Data Scientist
Upstart
November 29, 2026
Data Scientist
Take-home Project
Data Manipulation (SQL/Python)
Hard

0

0

0 solved


Given monthly loan snapshots with a delinquency status and balance, write pandas code that builds the month-over-month roll rate matrix (probability of moving from each status to each next status), by count or balance weighted, using only consecutive months.

Roll rates drive loss forecasting and loan pricing at Upstart, and capital markets partners ask for them when buying loan pools. A take-home or onsite pandas exercise checks careful handling of gaps, duplicates and terminal states, not just a groupby.

What the Interviewer Expects
  • Pairs each snapshot with the same loan's next month using a shift within loan groups
  • Excludes pairs with gaps in reporting
  • Treats charged-off and paid-off as absorbing states
  • Supports balance weighting
  • Normalizes rows safely and returns a stable state order
  • Validates that rows sum to 1
Key Topics to Cover
pandas
groupby shift
transition matrix
loss forecasting
data quality
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you project losses 12 months out with this matrix?
  • Why might the transition matrix not be stationary across vintages?
  • How would you handle a loan whose status is restated later?
  • How would you compute this on a billion rows?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

Columns: loan_id, as_of_month, status in {Current, DPD1_29, DPD30_59, DPD60_89, DPD90_PLUS, ChargedOff, PaidOff}, and balance. A loan should have one row per month, but feeds can contain dupli...

Approach

Deduplicate on (loan, month), convert months to an integer index, sort, then use groupby(...).shift(-1) to attach the next status and next month. Keep only pairs exactly one month apart and starting...


Submit Your Answer
Markdown supported