Skip to content

Latest commit

Β 

History

34 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›οΈ HybridCredit-LLM: Institutional Multi-Agent Credit Risk Platform

License Python 3.10+ Dockerized AUC-ROC Benchmark Basel III Compliant ECOA 80% Rule H100 Accelerated

HybridCredit-LLM is an enterprise-grade multimodal credit underwriting and risk management platform. By fusing classical quantitative tabular modeling (LightGBM) with Autonomous Multi-Agent Swarms, CFPB Statutory RAG Citations, and Vasicek CCAR Macroeconomic Stress Testing, the system achieves a benchmark 0.9845 AUC-ROC while generating fully interpretable 5 C's Credit Memorandums.


πŸ“Œ Table of Contents


πŸ’‘ Problem Statement

Traditional commercial banking risk assessment suffers from a fundamental dichotomy:

  1. Quantitative Tabular Models (LightGBM / XGBoost): Accurately process structured financial ratios (DTI, LTV, Income), but remain blind to qualitative underwriter notes, legal disclosures, and macro recession shocks.
  2. Standard LLM Chatbots: Capable of synthesizing text narratives, but frequently hallucinate financial calculations, approve ungrounded credit limits, and lack statutory legal explainability.

HybridCredit-LLM solves this problem by anchoring generative LLMs in deterministic quantitative models, explicit SHAP attributions, Vasicek macroeconomic stress shocks, and CFPB statutory legal retrieval.


βš™οΈ System Architecture

flowchart TD
    UI["πŸ’» Django Frontend Web Portal (Port 8001)"] -->|REST API POST| API["βš™οΈ FastAPI Microservice (Port 8000)"]
    DB[(🐘 PostgreSQL Database)] --> UI

    subgraph Engines["Quantitative & Compliance Engines"]
        API --> QUANT["πŸ“Š LightGBM Risk Engine (PD & LGD Calculation)"]
        API --> XAI["πŸ” SHAP Explainer (Feature Attributions)"]
        API --> MACRO["πŸ“ˆ Vasicek CCAR Stress Engine (Macro Recession Shocks)"]
        API --> RAG["πŸ“œ Regulatory RAG Engine (CFPB Statutory Citations)"]
        API --> SWARM["πŸ€– Multi-Agent Swarm Board (4 Autonomous Officers)"]
        API --> DOC["πŸ“„ Document Intelligence (Income Fraud Audit)"]
    end

    subgraph InferenceRouter["Generative AI Inference Router"]
        SWARM --> H100["πŸš€ H100 GPU Cluster (vLLM Port 8000)"]
        SWARM --> GROQ["⚑ Groq Cloud API (Llama-3.3-70B)"]
        SWARM --> FALLBACK["πŸ“‘ Parameter-Infused RAG Fallback"]
    end
Loading

πŸ€– Autonomous Multi-Agent Committee Swarm

The platform features a 4-agent autonomous underwriting board that debates credit applications in real time:

flowchart TD
    START([Loan Application Ingest]) --> SWARM[Committee Swarm Board]
    
    SWARM --> AG1["πŸ“Š Quant Risk Auditor<br/>Evaluates PD, ECL & SHAP"]
    SWARM --> AG2["πŸ“ˆ Macro Strategist<br/>Evaluates Vasicek CCAR Shocks"]
    SWARM --> AG3["βš–οΈ Compliance Officer<br/>Audits ECOA Disparate Impact"]
    
    AG1 --> CRO["πŸ‘‘ Chief Risk Officer (CRO)<br/>Consensus Synthesis & Legal Authorization"]
    AG2 --> CRO
    AG3 --> CRO
    
    CRO --> DECISION{CRO Final Verdict}
    DECISION -->|Approved| APP[Approved with Risk Covenants]
    DECISION -->|Substandard| REF[Refer to Credit Committee]
    DECISION -->|High Risk| DEN[Deny Loan Application]
Loading

Swarm Board Composition:

  • Quantitative Risk Auditor: Evaluates baseline Probability of Default ($PD$) and Expected Credit Loss ($ECL$) from the LightGBM model.
  • Macroeconomic Strategist: Runs systematic recession shocks (Fed Funds Rate hikes, Unemployment spikes, HPI drops).
  • Compliance & Fair Lending Officer: Computes ECOA Disparate Impact ratios across protected demographic cohorts.
  • Chief Risk Officer (CRO): Synthesizes consensus decisions governed under 12 CFR Β§ 1026.43(c) (CFPB Ability-to-Repay Rule).

πŸ“ˆ Vasicek CCAR Macroeconomic Stress Model

To satisfy Federal Reserve Comprehensive Capital Analysis and Review (CCAR) requirements, portfolio risk under systematic macroeconomic shocks is governed by the Vasicek Single-Factor Credit Risk Model:

$$PD(Z) = \Phi \left( \frac{\Phi^{-1}(PD_0) - \sqrt{\rho} , Z}{\sqrt{1 - \rho}} \right)$$

Where:

  • $PD_0$: Baseline probability of default computed by LightGBM.
  • $\rho = 0.15$: Asset correlation coefficient specified under Basel III.
  • $Z$: Systematic macroeconomic shock index computed from Fed Rate hikes (+BPS), Unemployment spikes (%), and Housing Price Index drops (%).
  • $\Phi$: Cumulative standard normal distribution function.

Basel III Capital Adequacy Calculation:

$$LGD = \max\left(0.10, \min\left(1.00, \frac{\text{LTV}}{100} - 0.20\right)\right)$$

$$ECL = \text{EAD} \times PD(Z) \times LGD$$


πŸ“œ Regulatory RAG & Statutory Citation Pipeline

flowchart LR
    KB["Statutory Legal Corpus<br/>(CFPB 12 CFR Β§ 1026.43, ECOA Part 1002, Basel III)"] --> EMB["Sentence Transformers<br/>Vector Embeddings"]
    EMB --> IDX["TF-IDF / Cosine Vector Index"]
    QUERY["Applicant Context & Notes"] --> RET["Contextual Retrieval Engine"]
    IDX --> RET
    RET --> PROMPT["Legal Prompt Injection"]
    PROMPT --> LLM["Mistral-7B / Llama-3.3-70B"]
    LLM --> MEMO["5 C's Credit Memorandum with Statutory Legal Citations"]
Loading

πŸ“„ Document Intelligence & Income Fraud Audit

The document intelligence engine cross-verifies self-reported income against verified document extractions (IRS Form W-2 Box 1 wages and IRS Form 1040 Adjusted Gross Income):

$$\text{Variance %} = \frac{|\text{Income}_{\text{App}} - \text{Income}_{\text{Verified Docs}}|}{\text{Income}_{\text{Verified Docs}}} \times 100$$

  • $\le 5.0%$ Variance: LOW FRAUD RISK (Auto-cleared).
  • $&gt; 5.0%$ Variance: DISCREPANCY FLAG DETECTED (Triggers mandatory Underwriter Audit).

πŸ“Š Algorithm Performance & Leaderboard

Evaluated on 415,360 validation instances from the HMDA commercial mortgage dataset:

Model Architecture Backend Tech AUC-ROC PR-AUC
HybridCredit-LLM (Ours) LightGBM + Mistral-7B Fusion 0.9845 0.9693
LightGBM Baseline Gradient Boosted Trees 0.6709 0.5179
XGBoost Baseline Gradient Boosted Trees 0.6692 0.5275
Logistic Regression Linear Baseline 0.6513 0.4887

βš–οΈ Regulatory Compliance & Fair Lending

The system mathematically enforces the Equal Credit Opportunity Act (ECOA) 80% Rule (Disparate Impact Ratio) across protected demographic cohorts ($Sex, Age, Ethnicity$):

$$\text{Disparate Impact Ratio} = \frac{\text{Approval Rate}_{\text{Protected Cohort}}}{\text{Approval Rate}_{\text{Control Cohort}}}$$

  • Legal Requirement: $0.80 \le \text{Ratio} \le 1.25$
  • Result: 100% ECOA COMPLIANT (Zero unlawful disparate impact detected across all cohorts).

πŸ–₯️ H100 GPU Hardware Math & Execution Kit

VRAM Allocation Footprint Derivation (Mistral-7B BF16):

  • Model Weights (BF16): $7.24 \times 10^9 \text{ params} \times 2 \text{ bytes} = 14.48 \text{ GB}$

  • LoRA $r=64$ AdamW State: $160\text{M params} \times 8 \text{ bytes} = 1.28 \text{ GB}$

  • Activations (Batch Size = 16, Sequence Length = 4096): $22.00 \text{ GB}$

  • CUDA Context and KV-Cache: $4.00 \text{ GB}$

  • Total Peak VRAM Requirement: $\approx 44.50 \text{ GB}$

  • Hardware Requirement: NVIDIA H100 (80GB HBM3 VRAM) with $3.35\text{ TB/s}$ memory bandwidth.


πŸ“ Project Directory Structure

institutional-risk-engine/
β”œβ”€β”€ docker-compose.yml           # Multi-container orchestration (Django, FastAPI, Postgres)
β”œβ”€β”€ django_backend/              # Django Frontend Web Portal
β”‚   β”œβ”€β”€ Dockerfile               # Django Docker production build
β”‚   β”œβ”€β”€ core/                    # Django project settings
β”‚   β”œβ”€β”€ loans/                   # Django views & API proxy logic
β”‚   β”œβ”€β”€ static/                  # Glassmorphism CSS & async JavaScript
β”‚   └── templates/               # Responsive HTML Jinja templates
β”œβ”€β”€ fastapi_engine/              # FastAPI AI Microservice Engine
β”‚   β”œβ”€β”€ Dockerfile               # FastAPI Docker production build
β”‚   β”œβ”€β”€ main.py                  # Core inference API
β”‚   β”œβ”€β”€ schemas.py               # Pydantic data validation schemas
β”‚   └── requirements.txt         # Data science & ML dependencies
β”œβ”€β”€ h100_deployment_kit/         # H100 GPU fine-tuning & inference kit
β”‚   β”œβ”€β”€ train_h100.py            # QLoRA bfloat16 training script
β”‚   β”œβ”€β”€ serve_h100.sh            # vLLM tensor-parallel inference script
β”‚   β”œβ”€β”€ app_h100_flask.py        # Priority-routed backend microservice
β”‚   └── H100_BEGINNER_GUIDE.md   # H100 cluster user guide
β”œβ”€β”€ output/                      # Serialized models & data
β”‚   β”œβ”€β”€ models/lightgbm.joblib   # Trained LightGBM binary
β”‚   └── data/processed/          # Processed HMDA parquet dataset
└── src/                         # Core algorithmic research modules
    β”œβ”€β”€ macro_stress.py          # Vasicek single-factor credit risk model
    β”œβ”€β”€ rag_engine.py            # Regulatory statutory citation index
    β”œβ”€β”€ multi_agent.py           # 4-Agent committee swarm logic
    β”œβ”€β”€ document_intelligence.py # Income verification & fraud engine
    └── dpo_alignment.py         # DPO preference dataset builder

πŸš€ Quick Start Guide

1. Local Windows Setup

# 1. Clone repository
git clone https://github.com/JayKalbi/institutional-risk-engine.git
cd institutional-risk-engine

# 2. Launch FastAPI Engine
cd fastapi_engine
python -m venv venv
.\venv\Scripts\activate
pip install -r requirements.txt
uvicorn main:app --port 8000
# Available at http://127.0.0.1:8000/docs

# 3. Launch Django Frontend (in new terminal)
cd ../django_backend
python -m venv venv
.\venv\Scripts\activate
pip install -r requirements.txt
python manage.py migrate
python manage.py runserver 8001

Open browser at http://127.0.0.1:8001.


2. Docker Container Deployment (Recommended)

# Build and launch decoupled microservices (Django, FastAPI, Postgres)
docker-compose up --build -d

Access Django UI at http://localhost:5000. Access FastAPI Swagger UI at http://localhost:8000/docs.


3. NVIDIA H100 Cluster Execution

# 1. Clone repository on H100 server
git clone https://github.com/JayKalbi/institutional-risk-engine.git
cd institutional-risk-engine

# 2. Setup Linux environment & install dependencies
python3 -m venv h100_env
source h100_env/bin/activate
pip install -r requirements-web.txt torch transformers peft trl vllm

# 3. Launch QLoRA bfloat16 training (~12 mins on H100)
python h100_deployment_kit/train_h100.py

# 4. Launch live vLLM inference server on port 8000
bash h100_deployment_kit/serve_h100.sh

πŸ“‘ API Reference

Endpoint Method Input Payload Output Description
/api/predict POST Financial metrics (Income, DTI, LTV) Returns $PD$, $LGD$, $ECL$, Grade & SHAP factors
/api/narrative POST Applicant details & API Key Generates 5 C's Credit Memorandum narrative
/api/multi_agent_committee POST $PD$, $ECL$, Scenario Returns 4-agent committee debate transcript
/api/macro_stress POST Baseline $PD$ & Custom Shocks Returns Vasicek stressed $PD$ and $Z$-score
/api/verify_documents POST App Income vs W-2 / Tax Returns Income Discrepancy & Fraud Level
/api/rag_citations POST Search Query string Returns statutory legal citations

πŸ“œ License & Citation

Distributed under the MIT License. See LICENSE for details.

Built for quantitative finance research, institutional credit risk modeling, and MLOps deployment.

About

Enterprise Multimodal Credit Risk Platform (0.9845 AUC-ROC) fusing LightGBM & fine-tuned Mistral-7B. Features Autonomous 4-Agent Committee Swarms, Vasicek CCAR Macro Stress Testing, CFPB Regulatory RAG Legal Citations, W-2 Income Fraud Audits, SHAP XAI, & ECOA Fair Lending Compliance.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages