algo-risk-credit
建立信用評分模型,預測借款人的違約機率
中文翻譯
---
name: "algo-risk-credit"
description: "建立信用評分模型,從借款人特徵預測違約機率。當使用者需要評估信用度、建立信用評分卡、或評估放款風險時使用,即使他們說的是「預測違約風險」、「信用評分」或「貸款核准模型」也一樣。"
metadata:
category: "WP-40 風險演算法"
tags: ["risk", "credit-scoring", "default-prediction", "lending"]
---
# 信用評分模型(Credit Scoring Model)
## 概述
信用評分模型用羅吉斯迴歸或梯度提升,從借款人特徵預測違約機率(PD)。輸出:分數(300-850 範圍)或 PD(0-1)。用於貸款核准、定價和投資組合風險管理。
## 何時使用
**觸發條件:**
- 要建立貸款/信用核准決策用的評分卡
- 要預測違約機率,做依風險的定價
- 要評估現有信用模型的區辨能力
**何時不要用:**
- 企業破產預測(用 Altman Z-Score)
- 市場風險衡量(用 VaR)
## 演算法
```
鐵律:信用模型必須「既能區辨」又「經過校準」
區辨力(AUC):能正確排出好借款人和壞借款人的順序。
校準:預測的 PD 和實際違約率吻合。
AUC=0.85 的模型,如果預測 PD 是實際違約率的 2 倍,
就會造成系統性的定價過高/過低。兩個特性「都」要有。
```
### 階段 1:輸入驗證
蒐集:借款人特徵(收入、負債比、信用歷史長度、逾期次數、使用率)、結果變數(12-24 個月內違約)。處理:缺失值、類別不平衡(違約率通常 2-5%)。
**關卡:** 違約事件足夠(300 筆以上)、特徵在做決策的當下就拿得到。
### 階段 2:核心演算法
1. 特徵工程:羅吉斯迴歸用 WOE(Weight of Evidence)分箱,GBDT 則直接編碼
2. 訓練模型:羅吉斯迴歸(可解釋、法規偏好)或 GBDT(準確度較高)
3. 校準:在 holdout 上做 Platt scaling,確保各十分位的預測 PD 和實際違約率吻合
4. 轉成分數:Score = offset + factor × log(odds),縮放到 300-850 範圍
### 階段 3:驗證
評估:AUC(>0.70 可接受、>0.80 良好)、KS 統計量、Gini 係數。用群體穩定度指標(PSI)監控漂移。
**關卡:** AUC > 0.70、校準可接受、對受保護屬性沒有歧視性偏差。
### 階段 4:輸出
回傳分數、PD 和主要風險驅動因素。
## 輸出格式
```json
{
"score": 680,
"pd": 0.035,
"risk_grade": "B",
"top_risk_factors": [{"factor": "high_utilization", "impact": -45}, {"factor": "short_history", "impact": -30}],
"metadata": {"model": "logistic_regression", "auc": 0.78, "vintage": "2024-Q3"}
}
```
## 範例
### 輸入輸出範例
**輸入:** 借款人:收入=$60K、DTI=35%、5 年信用歷史、0 次逾期、60% 使用率
**預期:** 分數約 680、PD 約 3.5%、等級 B(高使用率帶來一些風險)
### 邊界情況
| 輸入 | 預期 | 原因 |
|-------|----------|-----|
| 沒有信用歷史(薄檔案) | 不確定性高,預設採保守做法 | 評分的資料不足 |
| 所有特徵都一樣 | 不論結果,分數都相同 | 模型無法區分,需要更多特徵 |
| 經濟大幅變動 | PSI > 0.25,模型需要重新校準 | 群體已偏離訓練時的分布 |
## 常見陷阱
- **拒絕推論(reject inference)**:訓練資料只包含被核准的申請人。被拒絕的申請人的結果未知,造成選擇偏誤。要用拒絕推論的技巧。
- **公平放款**:模型不能依受保護的屬性(種族、性別、年齡)歧視。就算是代理變數(郵遞區號 ≈ 種族)也可能造成差別影響。要用公平性指標測試。
- **Through-the-door vs on-the-books**:TTD 樣本包含所有申請人;OTB 只有被核准的。模型的目的決定該用哪個樣本。
- **Vintage 分析**:違約率隨經濟狀況而異。2019 年訓練的模型,在衰退期可能預測不準。要依 vintage 追蹤模型表現。
- **法規要求**:金融監理機關(Basel、OCC、FDIC)對模型驗證、文件和公平放款測試有具體要求。
## 參考資料
- WOE 分箱的方法,見 `references/woe-binning.md`
- 拒絕推論的技巧,見 `references/reject-inference.md`英文原文
---
name: "algo-risk-credit"
description: "Build credit scoring models to predict default probability from borrower characteristics. Use this skill when the user needs to assess creditworthiness, build a credit scorecard, or evaluate lending risk — even if they say 'predict default risk', 'credit scoring', or 'loan approval model'."
metadata:
category: "WP-40 風險演算法"
tags: ["risk", "credit-scoring", "default-prediction", "lending"]
---
# Credit Scoring Model
## Overview
Credit scoring models predict the probability of default (PD) from borrower characteristics using logistic regression or gradient boosting. Output: a score (300-850 range) or PD (0-1). Used for loan approval, pricing, and portfolio risk management.
## When to Use
**Trigger conditions:**
- Building a scorecard for loan/credit approval decisions
- Predicting default probability for risk-based pricing
- Evaluating existing credit models for discriminatory power
**When NOT to use:**
- For corporate bankruptcy prediction (use Altman Z-Score)
- For market risk measurement (use VaR)
## Algorithm
```
IRON LAW: A Credit Model Must Discriminate AND Be Calibrated
Discrimination (AUC): correctly ranking good vs bad borrowers.
Calibration: predicted PD matches actual default rates.
A model with AUC=0.85 but predicted PD 2x actual default rate will
cause systematic over/under-pricing. Need BOTH properties.
```
### Phase 1: Input Validation
Collect: borrower features (income, debt ratio, credit history length, delinquency count, utilization), outcome variable (default within 12-24 months). Handle: missing values, class imbalance (typically 2-5% default rate).
**Gate:** Sufficient defaults (300+ events), features available at decision time.
### Phase 2: Core Algorithm
1. Feature engineering: WOE (Weight of Evidence) binning for logistic regression, or direct encoding for GBDT
2. Train model: logistic regression (interpretable, regulatory-preferred) or GBDT (higher accuracy)
3. Calibrate: Platt scaling on holdout, ensure predicted PD matches actual default rate by decile
4. Convert to score: Score = offset + factor × log(odds), scaled to 300-850 range
### Phase 3: Verification
Evaluate: AUC (>0.70 acceptable, >0.80 good), KS statistic, Gini coefficient. Population stability index (PSI) for monitoring drift.
**Gate:** AUC > 0.70, calibration acceptable, no discriminatory bias in protected attributes.
### Phase 4: Output
Return score, PD, and key risk drivers.
## Output Format
```json
{
"score": 680,
"pd": 0.035,
"risk_grade": "B",
"top_risk_factors": [{"factor": "high_utilization", "impact": -45}, {"factor": "short_history", "impact": -30}],
"metadata": {"model": "logistic_regression", "auc": 0.78, "vintage": "2024-Q3"}
}
```
## Examples
### Sample I/O
**Input:** Borrower: income=$60K, DTI=35%, 5yr credit history, 0 delinquencies, 60% utilization
**Expected:** Score ~680, PD ~3.5%, Grade B (some risk from high utilization)
### Edge Cases
| Input | Expected | Why |
|-------|----------|-----|
| No credit history (thin file) | High uncertainty, default to conservative | Insufficient data for scoring |
| All features identical | Same score regardless of outcome | Model can't differentiate — need more features |
| Major economy shift | PSI > 0.25, model needs recalibration | Population has shifted from training distribution |
## Gotchas
- **Reject inference**: Training data only includes approved applicants. Rejected applicants' outcomes are unknown, creating selection bias. Use reject inference techniques.
- **Fair lending**: Models must not discriminate by protected attributes (race, gender, age). Even proxy variables (zip code ≈ race) can create disparate impact. Test with fairness metrics.
- **Through-the-door vs on-the-books**: TTD samples include all applicants; OTB only approved ones. Model purpose determines which sample to use.
- **Vintage analysis**: Default rates vary by economic conditions. A 2019-trained model may not predict well in a recession. Track model performance by vintage.
- **Regulatory requirements**: Financial regulators (Basel, OCC, FDIC) have specific requirements for model validation, documentation, and fair lending testing.
## References
- For WOE binning methodology, see `references/woe-binning.md`
- For reject inference techniques, see `references/reject-inference.md`