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 |