Basel 3.1 Credit Risk RWA Calculator compliant with PRA PS1/26
Project description
[!IMPORTANT] This package is still in active development and is not production ready - release 1.0.0 will confirm when ready for current CRR and 2.0.0 for Basel 3.1
UK Credit Risk (CR) & Counterparty Credit Risk (CCR) RWA Calculator
A high-performance Risk-Weighted Assets (RWA) calculator for UK CR & CCR, supporting both current regulations and future Basel 3.1 implementation. Built with Python using Polars for vectorized performance.
Documentation: https://OpenAfterHours.club/rwa_calculator/
Installation
Install with uv (recommended)
uv add rwa-calc
Or with pip
pip install rwa-calc
The web UI and REST API ship with the base package — no extra required.
Optional Dependencies
| Extra | Description |
|---|---|
ui |
Legacy alias — UI deps are now included in the base install |
dev |
Development tools (pytest, ruff, ty, zensical) |
all |
All optional dependencies |
Quick Start
from datetime import date
from rwa_calc.api import CreditRiskCalc
response = CreditRiskCalc(
data_path="/path/to/data",
framework="CRR",
reporting_date=date(2026, 12, 31),
permission_mode="irb",
).calculate()
if response.success:
print(f"Total RWA: {response.summary.total_rwa:,.0f}")
df = response.collect_results()
IRB Mode — set permission_mode="irb" and provide a model_permissions input table
to route exposures to FIRB, AIRB, or slotting based on per-model approvals. Exposures
without a matching model permission fall back to SA. See the
Data Model docs
for the model permissions schema.
Interactive UI — server-rendered web interface (calculator, results, CRR vs Basel 3.1 comparison, and legacy-engine reconciliation) plus a REST API and an editable Marimo workbench:
uv add rwa-calc
rwa-ui
# Open http://localhost:8000 in your browser (REST API + OpenAPI at /docs)
Regulatory Scope
This calculator supports two regulatory regimes:
| Regime | Effective Period | UK Implementation | Status |
|---|---|---|---|
| CRR (Basel 3.0) | Until 31 December 2026 | UK CRR (EU 575/2013 as onshored) | Active |
| Basel 3.1 | From 1 January 2027 | PRA PS1/26 | Implemented |
A configuration toggle allows switching between calculation modes for:
- Current regulatory reporting under UK CRR
- Impact analysis and parallel running ahead of Basel 3.1 go-live
- Seamless transition when Basel 3.1 becomes effective
Migrating from an Existing Calculator
The hardest part of adopting a new credit-risk engine is not installing it — it is signing off that the new numbers are correct on your own book. Parallel-run reconciliation operationalises that discipline: run this calculator and your existing/legacy calculator on the same portfolio, then reconcile the two outputs component by component (exposure class, approach, CCF, EAD, PD, LGD, risk weight, RWA, …).
Every exposure is bucketed as an exact match, a within-tolerance difference, a break, or missing on one side — with our engine's reason and input drivers attached so each break can be traced to either a data / mapping issue or an engine difference.
from datetime import date
from rwa_calc.api import CreditRiskCalc
calc = CreditRiskCalc(
data_path="/path/to/data",
framework="CRR",
reporting_date=date(2026, 12, 31),
permission_mode="standardised",
)
# Map your legacy output columns onto our components in a small TOML file
response = calc.reconcile("reconciliation.toml")
print(response.collect_totals_tie_out()) # does it tie out?
print(response.collect_summary_by_component()) # which components agree
breaks = response.collect_breaks_detail() # the break worklist, largest first
response.to_excel("reconciliation.xlsx") # full report, one sheet per view
You can also run it without writing Python from the Reconciliation page in the web UI
(rwa-ui, then open http://localhost:8000/reconciliation) or over HTTP via
POST /api/reconcile. This is distinct from Framework Comparison (CRR vs Basel 3.1 on the
same engine) — here the other side is your external, legacy output.
Details: See the Parallel-Run Reconciliation guide.
Key Features
- Dual-Framework Support: Single codebase for CRR and Basel 3.1 with UK-specific deviations
- High Performance: Polars LazyFrames for vectorized calculations (50-100x improvement over row iteration)
- Complete Coverage: Standardised (SA), IRB (F-IRB & A-IRB), and Slotting approaches
- Credit Risk Mitigation: Collateral, guarantees, and provisions with RWA-optimized allocation
- Complex Hierarchies: Multi-level counterparty and facility hierarchy support
- Audit Trail: Full calculation transparency for regulatory review
- Framework Comparison: Side-by-side CRR vs Basel 3.1 impact analysis
- Parallel-Run Reconciliation: Tie this calculator out against your existing/legacy engine component-by-component (EAD, RWA, risk weight, PD, LGD, …) to sign off a migration with confidence
- COREP Output: Export results to COREP regulatory templates
- Multiple Export Formats: Parquet, CSV, Excel, and COREP
Supported Approaches
| Approach | Description |
|---|---|
| Standardised (SA) | Risk weights based on external ratings and exposure characteristics |
| Foundation IRB (F-IRB) | Bank-estimated PD, supervisory LGD |
| Advanced IRB (A-IRB) | Bank-estimated PD, LGD, and EAD |
| Slotting | Category-based approach for specialised lending |
Supported Exposure Classes
Sovereign / Central Bank, Institution, Corporate, Corporate SME, PSE, MDB, RGLA, Retail Mortgage, Retail QRRE, Retail Other, Specialised Lending, Equity, Covered Bond, Residential Mortgage, Commercial Mortgage (Basel 3.1 RE split), High Risk, Defaulted, Other
Documentation
Comprehensive documentation is available at OpenAfterHours.club/rwa_calculator
| Section | Description |
|---|---|
| Getting Started | Installation and first calculation |
| User Guide | Regulatory frameworks, methodology, exposure classes |
| Reconciliation | Parallel-run tie-out against a legacy calculator for migration |
| Architecture | System design and pipeline |
| Data Model | Input schemas and validation |
| API Reference | Complete technical documentation |
| Development | Testing, benchmarks, contributing |
| Plans | Development roadmap and status |
Running Tests
Test fixtures are parquet files generated from Python builders and are not checked into the repo (they are gitignored). Generate them once before running the test suite for the first time, and again whenever a fixture builder under tests/fixtures/ changes:
# Generate all test fixtures (parquet output, 8 groups)
uv run python tests/fixtures/generate_all.py
# Run all tests
uv run pytest -v
# Run with coverage
uv run pytest --cov=src/rwa_calc
# Run benchmarks (10K + 100K, excludes 1M/10M)
uv run pytest tests/benchmarks/ -m "benchmark and not slow" -k "not 1m" -o "addopts=" --benchmark-only -v
Test Results: ~5,500 tests (~4,675 unit + ~500 acceptance + ~165 contract + ~145 integration + ~30 benchmark)
License
References
Current Regulations (CRR / Basel 3.0)
Basel 3.1 Implementation (January 2027)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rwa_calc-0.3.2.tar.gz.
File metadata
- Download URL: rwa_calc-0.3.2.tar.gz
- Upload date:
- Size: 4.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b816d23aca61e5a676eddc55abc036b67a7ca5a17a5719265646e2cb698edf18
|
|
| MD5 |
455f24c8ca33be7142d25803fb2e65c3
|
|
| BLAKE2b-256 |
91ec1a26b6e7d5c53062c5f85323ee8e73ee92dfca2006d3de1237ae6af64cde
|
Provenance
The following attestation bundles were made for rwa_calc-0.3.2.tar.gz:
Publisher:
publish.yml on OpenAfterHours/rwa_calculator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rwa_calc-0.3.2.tar.gz -
Subject digest:
b816d23aca61e5a676eddc55abc036b67a7ca5a17a5719265646e2cb698edf18 - Sigstore transparency entry: 1896345389
- Sigstore integration time:
-
Permalink:
OpenAfterHours/rwa_calculator@5f3164c1669eb38d426e44110765d980090d3363 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/OpenAfterHours
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5f3164c1669eb38d426e44110765d980090d3363 -
Trigger Event:
release
-
Statement type:
File details
Details for the file rwa_calc-0.3.2-py3-none-any.whl.
File metadata
- Download URL: rwa_calc-0.3.2-py3-none-any.whl
- Upload date:
- Size: 884.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e1819b74f4a3e4477cdb26b62557ff2219736a8888aeb7b8db1eb077c674c74
|
|
| MD5 |
5801ef4c95167eb54703bb6f1b2a2987
|
|
| BLAKE2b-256 |
bad041aa379b52fe9d9e991ceda751d911c0cf733d5f22b365d9128074b1a8be
|
Provenance
The following attestation bundles were made for rwa_calc-0.3.2-py3-none-any.whl:
Publisher:
publish.yml on OpenAfterHours/rwa_calculator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rwa_calc-0.3.2-py3-none-any.whl -
Subject digest:
9e1819b74f4a3e4477cdb26b62557ff2219736a8888aeb7b8db1eb077c674c74 - Sigstore transparency entry: 1896345540
- Sigstore integration time:
-
Permalink:
OpenAfterHours/rwa_calculator@5f3164c1669eb38d426e44110765d980090d3363 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/OpenAfterHours
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5f3164c1669eb38d426e44110765d980090d3363 -
Trigger Event:
release
-
Statement type: