A comprehensive, hands-on credit risk analytics project designed to bridge the gap between statistical credit modeling (Python) and executive business decision-making (Excel & Streamlit).
This repository contains a full credit risk workflow, including a rules-based underwriting scorecard, a statistical Probability of Default (PD) model, an Expected Loss (EL) framework, economic stress testing simulations, and an interactive decision-support web application.
Financial Credit Risk Analyst/
│
├── data/ # Database storage
│ ├── loan_applicants_raw.csv # Raw generated synthetic applicant data (175 rows)
│ ├── loan_applicants_with_pd.csv # Modeling outputs with Predicted PD values
│ └── loan_applicants_stressed.csv # Stress testing dataset (baseline vs. stressed PD/EL)
│
├── excel/ # Interactive spreadsheets
│ ├── loan_applicants.xlsx # Underwriting database with live calculated formulas
│ ├── loan_applicants_with_pd.xlsx # Underwriting database with appended PD column
│ └── loan_applicants_portfolio.xlsx # Executive Portfolio Dashboard with native Excel charts
│
├── python/ # Script source code
│ ├── generate_data.py # Data generation and Excel styling script (Phase 1)
│ ├── train_model.py # Logistic Regression classifier and ML evaluation (Phase 2)
│ ├── build_dashboard.py # Portfolio aggregations and dashboard compiler (Phase 3)
│ ├── stress_test.py # Macroeconomic income shock simulation script (Phase 4)
│ └── app.py # Streamlit interactive web application (Phase 6)
│
├── outputs/ # Models, figures, and committee memos
│ ├── roc_curve.png # Classifier diagnostic ROC curve
│ ├── stress_test_comparison.png # Stress test dual-bar chart comparison
│ ├── stress_test_summary.txt # Stressed expected loss report
│ ├── executive_memo.md # Formal risk memorandum for the Credit Committee
│ └── resume_framing.md # Resume bullet points and project descriptions for BA/PO roles
│
├── requirements.txt # Project dependencies
└── README.md # Main documentation page (this file)
- Python 3.11+
- Command-line shell (PowerShell or Bash)
Navigate to the project root directory and create a local virtual environment:
python -m venv .venv- Windows (PowerShell):
.\.venv\Scripts\Activate.ps1
- macOS/Linux:
source .venv/bin/activate
Install all required libraries using requirements.txt:
pip install -r requirements.txtYou can run the project phase-by-phase or execute the interactive dashboard directly.
Synthesizes the borrower database and styles the initial Excel sheet with live formulas:
python python/generate_data.pyCreates: data/loan_applicants_raw.csv and excel/loan_applicants.xlsx
Preprocesses features, trains a Logistic Regression classifier, evaluates model metrics, and plots the ROC curve:
python python/train_model.pyCreates: outputs/roc_curve.png, data/loan_applicants_with_pd.csv, and excel/loan_applicants_with_pd.xlsx
Sorts the database by risk, adds LGD/EAD/EL formulas, and compiles the Excel dashboard:
python python/build_dashboard.pyCreates: excel/loan_applicants_portfolio.xlsx
Simulates a 20% macroeconomic income shock and outputs downturn risk profiles:
python python/stress_test.pyCreates: outputs/stress_test_comparison.png, outputs/stress_test_summary.txt, and data/loan_applicants_stressed.csv
Launches the local Streamlit server for a hands-on, sandbox experience:
streamlit run python/app.pyOnce launched, open http://localhost:8501 in your web browser.
Here is the mathematical framework implemented in this project:
Incorporates existing obligations and the payment for the new requested loan:
Estimates interest expenses assuming a 5% rate on existing debt and 8% on the new loan:
- PD: Output from the Python Logistic Regression model.
- LGD: Set at a flat 45% (industry standard for senior credit, representing 55% recovery).
- EAD: Represented by the requested loan amount.
The Streamlit web app serves as an interactive underwriting cockpit:
- 📊 Portfolio Dashboard: Aggregates total exposure, expected losses, average PDs, and displays interactive Plotly charts.
- ⚡ Stress Testing Sandbox: Allows adjusting recessionary sliders (0% to 50% income shocks) and dynamically visualizes baseline vs. stressed losses.
- 🔍 Underwriter Sandbox: Search any applicant by ID and modify their values (FICO, income, loan size) to see their risk scores, scorecard points, grades, and statistical PDs update in real-time.