Your question is Rolling Default Rate Query. 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.
American Credit Acceptance wants to monitor recent credit performance by loan origination cohort. Write a PostgreSQL query that calculates the rolling 30-day default rate for each cohort and reporting date.
A loan enters a default event on the first date where its status is DEFAULT. The rolling window includes the reporting date and the preceding 29 calendar days.
origination_date.0 for cohorts with no defaults in the window, round the rate to four decimal places, and order by cohort month and reporting date.| Column | Type | Description |
|---|---|---|
| loan_idPK | BIGINT | Unique loan identifier |
| origination_date | DATE | Date the loan was originated |
| product_code | VARCHAR(20) | American Credit Acceptance loan product code |
| Column | Type | Description |
|---|---|---|
| status_idPK | BIGINT | Unique status observation |
| loan_id | BIGINT | Loan associated with the status |
| status_date | DATE | Date of the status observation |
| status_code | VARCHAR(20) | Observed loan status |