Skip to content

Latest commit

Β 

History

11 Commits

Folders and files

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

Repository files navigation

🏦 BaselCore β€” Risk Analytics Engine

A transparent, programmatic Basel III Risk & Capital Adequacy engine for a simulated $50B commercial bank β€” built with Python, visualized with Plotly Dash.


Python Pandas NumPy Plotly Dash Pytest OpenPyXL License: MIT

⚠️ Educational & Demonstration Use Only. This project does not constitute financial or regulatory advice and is not certified for actual BIS / Fed / ECB regulatory reporting.


πŸ“Œ Table of Contents


πŸ” Problem Statement

Financial institutions operating under Basel III face stringent, multi-dimensional regulatory requirements β€” covering credit risk, market risk, operational risk, capital adequacy, and liquidity buffers. The challenge:

  • Manual computation of Risk-Weighted Assets (RWA) is error-prone at scale.
  • Enterprise solutions (e.g., Bloomberg, Moody's) are expensive, black-boxed, and inaccessible for learning.
  • Stress testing across adverse macroeconomic scenarios requires rapid, reproducible pipeline reruns.
  • Regulatory thresholds (CET1 β‰₯ 7%, LCR β‰₯ 100%, NSFR β‰₯ 100%) must be continuously monitored with automated alerting.

There is no open, transparent, end-to-end Basel III engine that a quantitative analyst, risk student, or fintech professional can inspect, modify, and learn from.


πŸ’‘ Solution Overview

BaselCore is a fully programmatic, open-source Basel III risk analytics engine that:

  1. Generates a synthetic, reproducible $50B commercial bank balance sheet.
  2. Computes Credit, Market, and Operational RWA using Basel III standardized formulas.
  3. Calculates regulatory capital ratios (CET1, Tier 1, Total Capital) and liquidity metrics (LCR, NSFR).
  4. Stress-tests the balance sheet across 8 adverse macroeconomic scenarios.
  5. Alerts stakeholders with a multi-level (Green / Amber / Red / Critical) threshold monitoring system.
  6. Visualizes all outputs through an interactive Plotly Dash dashboard with heatmaps, gauges, and comparison charts.

πŸ—οΈ System Architecture

The engine follows a sequential pipeline architecture, where each module feeds cleanly into the next:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Data Generator  │────▢│  RWA Computation │────▢│  Capital Metrics β”‚
β”‚  (Balance Sheet) β”‚     β”‚  Credit / Market β”‚     β”‚  CET1 / Tier 1 / β”‚
β”‚  $50B Synthetic  β”‚     β”‚  / Operational   β”‚     β”‚  Total Capital   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                          β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β–Ό
β”‚  Liquidity       │◀────│  Stress Testing  │◀─── β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  LCR / NSFR      β”‚     β”‚  8 Scenarios     β”‚     β”‚  Alerts Engine   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                        β”‚                         β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β–Ό
                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β”‚   Plotly Dash Dashboard       β”‚
                  β”‚   Heatmaps Β· Gauges Β· Alerts  β”‚
                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow Summary:

  • A deterministic random seed ensures full reproducibility of the balance sheet.
  • RWA modules (credit, market, operational) are independent and composable.
  • The stress testing engine mutates the balance sheet and reruns the entire pipeline per scenario.
  • The dashboard and alert system consume final outputs from all modules.

🧰 Tech Stack

Layer Technology Purpose
Language Python Core engine
Data Processing Pandas NumPy Balance sheet simulation, RWA computation
Visualization Plotly Dash Interactive dashboard
UI Styling Dash Bootstrap Components (Darkly theme) Dashboard layout & theming
Testing Pytest Unit tests & coverage
Reporting OpenPyXL Excel report generation

✨ Features

πŸ“Š Risk-Weighted Asset (RWA) Engine

  • Credit RWA β€” Standardized Approach: maps (Exposure Class Γ— Rating) to Basel III risk weights (0%–150%). Covers Sovereign, Bank, Corporate, Retail, Residential Mortgage, Commercial Real Estate, and Past Due exposures.
  • Market RWA β€” Standardized Measurement Method: Interest Rate (General + Specific), Equity (8% general + 8% specific), FX (8% net open position), Commodity (15% net + 3% basis risk).
  • Operational RWA β€” New Standardized Approach: Business Indicator Component (BIC) with marginal scaling buckets (12% / 15% / 18%) and Internal Loss Multiplier (ILM = 1.0).

πŸ›οΈ Capital & Liquidity Metrics

  • CET1 Ratio β€” Common Equity minus regulatory deductions (Goodwill, Intangibles, DTA) / Total RWA. Minimum: 7.0% (4.5% + 2.5% conservation buffer).
  • Tier 1 & Total Capital Ratios β€” Full regulatory capital stack.
  • LCR β€” HQLA (post-haircut, with Level 2 ≀ 40% and Level 2B ≀ 15% limits) / Net Cash Outflows (30-day stress). Minimum: 100%.
  • NSFR β€” Available Stable Funding / Required Stable Funding. Minimum: 100%.

πŸŒͺ️ Stress Testing (8 Scenarios)

# Scenario Shock Applied
1 Interest Rate Surge +200 bps
2 Rate Cut βˆ’100 bps
3 Equity Crash βˆ’30% equity positions
4 Credit Deterioration 1-notch rating downgrade across portfolio
5 Liquidity Redemption 20% deposit run-off
6 FX Shock Β±20% currency moves
7 Combined Adverse All shocks simultaneously
8 Severe Recession GDP βˆ’5%, Unemployment +5%

Each scenario reruns the full pipeline and outputs a Pass/Fail per regulatory threshold (CET1, LCR, NSFR).

🚨 Multi-Level Alert System

Status Threshold Meaning
🟒 GREEN Above buffer requirement Fully compliant
🟑 AMBER Approaching minimum Monitor closely
πŸ”΄ RED Below minimum Breach β€” action required
🚨 CRITICAL Severe breach Immediate escalation

πŸ“ˆ Plotly Dash Dashboard

  • Capital Gauges (3) β€” CET1, Tier 1, Total Capital with colored threshold zones.
  • Liquidity Gauges (2) β€” LCR, NSFR.
  • RWA Breakdown β€” Stacked bar chart: Credit / Market / Operational.
  • Risk Heatmap β€” Exposure Class Γ— Credit Rating matrix showing RWA concentration.
  • Stress Test Comparison β€” Grouped bar chart: CET1 % vs LCR % across all 8 scenarios.
  • Alert Log Table β€” Live alert status for all monitored metrics.

πŸ“ Directory Structure

baselcore-risk-analytics/
β”œβ”€β”€ config/
β”‚   └── regulatory_config.py     # Basel III risk weights & regulatory parameters
β”œβ”€β”€ data/                        # Generated raw & processed balance sheet data
β”œβ”€β”€ dashboard/
β”‚   └── app.py                   # Plotly Dash interactive web application
β”œβ”€β”€ notebooks/                   # Jupyter notebooks for exploratory analysis
β”œβ”€β”€ outputs/
β”‚   └── reports/                 # Auto-generated Excel reports & visualizations
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ data_generator.py        # Synthetic $50B bank balance sheet generator
β”‚   β”œβ”€β”€ credit_rwa.py            # Credit risk RWA (Standardized Approach)
β”‚   β”œβ”€β”€ market_rwa.py            # Market risk RWA (SMM)
β”‚   β”œβ”€β”€ operational_rwa.py       # Operational risk RWA (NSA / BIC)
β”‚   β”œβ”€β”€ capital_metrics.py       # CET1 / Tier 1 / Total Capital calculations
β”‚   β”œβ”€β”€ liquidity_metrics.py     # LCR / NSFR calculations
β”‚   β”œβ”€β”€ stress_testing.py        # 8 adverse macroeconomic scenarios
β”‚   └── alerts.py                # Multi-level threshold alert system
β”œβ”€β”€ tests/                       # Pytest unit tests & coverage
β”œβ”€β”€ main.py                      # Pipeline orchestrator β€” run this first
└── requirements.txt             # Python dependencies

βš™οΈ Setup & Installation

Prerequisites

  • Python 3.10+
  • pip package manager
  • Git

1. Clone the Repository

git clone https://github.com/nilaysureka/BaselCore-Risk_Analytics_Engine.git
cd BaselCore-Risk_Analytics_Engine

2. Create & Activate a Virtual Environment

# Create
python -m venv venv

# Activate (macOS / Linux)
source venv/bin/activate

# Activate (Windows)
venv\Scripts\activate

3. Install Dependencies

pip install -r requirements.txt

πŸš€ Running the Project

Step 1 β€” Run the Analytics Pipeline

python main.py

This will:

  • Generate the synthetic $50B balance sheet.
  • Compute all RWA modules (credit, market, operational).
  • Calculate capital ratios and liquidity metrics.
  • Execute all 8 stress test scenarios.
  • Export results to outputs/reports/ as Excel files.

Step 2 β€” Launch the Interactive Dashboard

python dashboard/app.py

Open your browser and navigate to:

http://127.0.0.1:8050

πŸ–₯️ Dashboard Preview

The dashboard is organized as follows:

Section Component
Header Bank name Β· As-of date Β· Basel III compliance tag
Alert Banner Overall status: Healthy / Monitor / Action Required
Capital Panel Three gauges: CET1, Tier 1, Total Capital
Liquidity Panel Two gauges: LCR, NSFR
RWA Breakdown Stacked bar: Credit / Market / Operational
Risk Heatmap Exposure Class Γ— Rating RWA concentration matrix
Stress Test View Grouped bar: CET1 % vs LCR % across 8 scenarios
Data Tables Interactive stress test results + alert log

Theme: Darkly Bootstrap (Plotly Dash Bootstrap Components)


πŸ“ Methodology

Credit RWA β€” Standardized Approach

RWA = EAD Γ— Risk Weight

Risk weights assigned by (Exposure Class, External Rating) per Basel III Table β€” ranging from 0% (AAA Sovereign) to 150% (Past Due / Unrated CRE).

Market RWA β€” Standardized Measurement Method

IR Risk   = General (Duration Γ— Ξ”Yield) + Specific (Credit Spread Charge)
Equity    = 8% General + 8% Specific on gross position
FX        = 8% Γ— Net Open Position
Commodity = 15% Γ— Net Position + 3% Γ— Gross Position (basis risk)

Operational RWA β€” New Standardized Approach (NSA)

BIC   = ILDC Component + Services Component + Financial Component
Scaling: ≀€1B β†’ 12% | €1B–€30B β†’ 15% | >€30B β†’ 18%
Op RWA = BIC Γ— ILM (ILM = 1.0)

Capital Ratios

CET1        = Common Equity βˆ’ Goodwill βˆ’ Intangibles βˆ’ DTA
CET1 Ratio  = CET1 / Total RWA   [Minimum: 7.0%]
Tier 1 Ratio = Tier 1 Capital / Total RWA
Total Ratio  = Total Capital / Total RWA

Liquidity Ratios

LCR  = HQLA (post-haircut) / Net Cash Outflows (30-day stress)  [Minimum: 100%]
NSFR = Available Stable Funding / Required Stable Funding         [Minimum: 100%]

HQLA constraints: Level 2 ≀ 40% of total HQLA; Level 2B ≀ 15% of total HQLA.


πŸ§ͺ Testing

Run the full test suite with:

pytest tests/ -v --cov=src

Test Coverage

Test Area What's Validated
Data reproducibility Fixed seed generates identical balance sheets across runs
RWA boundary checks Risk weights bounded to 0%–150% for all exposure classes
Capital ordering CET1 < Tier 1 < Total Capital at all times
HQLA composition Level 2 ≀ 40%, Level 2B ≀ 15% limits enforced
Stress test logic Combined Adverse scenario produces the lowest CET1 ratio

πŸ”­ Scope & Limitations

In scope:

  • Standardized Approach for credit, market, and operational risk.
  • Full capital stack (CET1, AT1, Tier 2) and liquidity ratios (LCR, NSFR).
  • 8 predefined macroeconomic stress scenarios with automated pass/fail logic.
  • Interactive executive dashboard with alert system.

Out of scope:

  • Internal Ratings-Based (IRB) models for credit risk.
  • Real-time market data feeds (live API integration).
  • Certified regulatory submission to BIS / Federal Reserve / ECB.
  • Advanced market risk (FRTB / Internal Models Approach).

πŸ“„ Disclaimer

This project is for educational and demonstration purposes only. The simulated data, simplified methodologies, and outputs do not represent any real financial institution. This engine is not certified for actual regulatory reporting to the BIS, Federal Reserve, ECB, or any other regulatory body, and does not constitute financial or legal advice.


πŸ‘€ Author

Nilay Sureka

GitHub Portfolio


⭐ If you found this project useful, please consider starring the repo! ⭐

Made with 🐍 Python Β· πŸ“Š Plotly Dash Β· πŸ›οΈ Basel III

About

Basel III-compliant bank risk analytics engine with RWA computation, stress testing, and Plotly dashboard.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages