Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling Default Rate by Vintage

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Rolling Default Rate by Vintage. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

dv01's loan performance analytics team needs to monitor default behavior for the January 2024 consumer-loan vintage. Write a PostgreSQL query that calculates the rolling three-month default rate for that vintage from January through May 2024.

Requirements

  1. Restrict the cohort to loans originated in January 2024.
  2. Count each loan only once, in the first month where defaulted is true. Treat NULL performance values as not defaulted.
  3. Include months with no defaults, and calculate the rolling three-month default rate as defaults in the current month and prior two months divided by the total size of the vintage.
  4. Return one row per month, ordered chronologically, with the month, monthly defaults, rolling defaults, and rate rounded to four decimal places.

Schema

loans
ColumnTypeDescription
loan_idPKINTUnique consumer loan identifier
origination_monthDATELoan origination month
loan_purposeVARCHAR(40)Purpose of the consumer loan
borrower_stateVARCHAR(2)Two-letter borrower state code
performance
ColumnTypeDescription
performance_idPKINTUnique monthly performance record
loan_idINTReferenced loan identifier
performance_monthDATEMonth of the performance observation
defaultedBOOLEANWhether the loan defaulted during the observation month
Tablesloansperformance
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results