Metadata-Version: 2.4
Name: rwa-calc
Version: 0.1.31
Summary: Basel 3.1 Credit Risk RWA Calculator compliant with PRA PS9/24
Project-URL: Homepage, https://github.com/OpenAfterHours/rwa_calculator
Project-URL: Documentation, https://OpenAfterHours.github.io/rwa_calculator/
Project-URL: Repository, https://github.com/OpenAfterHours/rwa_calculator.git
Project-URL: Issues, https://github.com/OpenAfterHours/rwa_calculator/issues
Project-URL: Changelog, https://github.com/OpenAfterHours/rwa_calculator/blob/master/docs/appendix/changelog.md
Author: OpenAfterHours
Maintainer: OpenAfterHours
License: Apache-2.0
License-File: LICENSE
Keywords: banking,basel,capital,credit-risk,polars,pra,regulatory,risk-management,rwa
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Office/Business :: Financial
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Typing :: Typed
Requires-Python: >=3.13
Requires-Dist: duckdb>=0.9.0
Requires-Dist: fastexcel>=0.19.0
Requires-Dist: polars-normal-stats>=0.2.0
Requires-Dist: polars>=1.0.0
Requires-Dist: pyarrow>=14.0.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: pyyaml>=6.0.0
Requires-Dist: xlsxwriter>=3.1.0
Provides-Extra: all
Requires-Dist: marimo>=0.5.0; extra == 'all'
Requires-Dist: mkdocs-material>=9.5.0; extra == 'all'
Requires-Dist: mkdocs-mermaid2-plugin>=1.1.0; extra == 'all'
Requires-Dist: mkdocs>=1.5.0; extra == 'all'
Requires-Dist: mkdocstrings[python]>=0.24.0; extra == 'all'
Requires-Dist: mypy>=1.8.0; extra == 'all'
Requires-Dist: numpy>=1.26.0; extra == 'all'
Requires-Dist: pytest-benchmark>=4.0.0; extra == 'all'
Requires-Dist: pytest-cov>=4.0.0; extra == 'all'
Requires-Dist: pytest>=8.0.0; extra == 'all'
Requires-Dist: ruff>=0.3.0; extra == 'all'
Requires-Dist: uvicorn>=0.27.0; extra == 'all'
Provides-Extra: dev
Requires-Dist: mkdocs-material>=9.5.0; extra == 'dev'
Requires-Dist: mkdocs-mermaid2-plugin>=1.1.0; extra == 'dev'
Requires-Dist: mkdocs>=1.5.0; extra == 'dev'
Requires-Dist: mkdocstrings[python]>=0.24.0; extra == 'dev'
Requires-Dist: mypy>=1.8.0; extra == 'dev'
Requires-Dist: numpy>=1.26.0; extra == 'dev'
Requires-Dist: pytest-benchmark>=4.0.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: ruff>=0.3.0; extra == 'dev'
Provides-Extra: ui
Requires-Dist: marimo>=0.5.0; extra == 'ui'
Requires-Dist: uvicorn>=0.27.0; extra == 'ui'
Description-Content-Type: text/markdown

*This package is still in development and is not production ready*

# UK Credit Risk RWA Calculator

[![Documentation](https://img.shields.io/badge/docs-GitHub%20Pages-blue)](https://OpenAfterHours.github.io/rwa_calculator/)

A high-performance Risk-Weighted Assets (RWA) calculator for UK credit risk, supporting both current regulations and future Basel 3.1 implementation. Built with Python using Polars for vectorized performance.

**Documentation:** [https://OpenAfterHours.github.io/rwa_calculator/](https://OpenAfterHours.github.io/rwa_calculator/)

## Installation

```bash
# Install from PyPI
pip install rwa-calc

# Or with uv
uv add rwa-calc

# With UI support (web-based calculator interface)
pip install rwa-calc[ui]
```

### Optional Dependencies

| Extra | Description |
|-------|-------------|
| `ui` | Interactive web UI via Marimo |
| `dev` | Development tools (pytest, mypy, mkdocs) |
| `all` | All optional dependencies |

## Quick Start

**Quickest Start** — one call does everything:

```python
from rwa_calc.api import quick_calculate

response = quick_calculate("/path/to/data")
print(f"Total RWA: {response.summary.total_rwa:,.0f}")
```

**More Control** — choose framework, IRB approach, and reporting date:

```python
from datetime import date
from rwa_calc.api import create_service, CalculationRequest

service = create_service()
response = service.calculate(
    CalculationRequest(
        data_path="/path/to/data",
        framework="CRR",
        reporting_date=date(2026, 12, 31),
        irb_approach="full_irb",
    )
)

if response.success:
    print(f"Total RWA: {response.summary.total_rwa:,.0f}")
    df = response.collect_results()
```

**Interactive UI** — web-based calculator interface:

```bash
pip install rwa-calc[ui]
rwa-calc-ui
# Open http://localhost:8000 in your browser
```

## 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 PS9/24 | **Active Development** |

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

## 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
- **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, Institution, Corporate, Corporate SME, Retail Mortgage, Retail QRRE, Retail Other, Specialised Lending, Equity

## Documentation

Comprehensive documentation is available at **[OpenAfterHours.github.io/rwa_calculator](https://OpenAfterHours.github.io/rwa_calculator/)**

| Section | Description |
|---------|-------------|
| [Getting Started](https://OpenAfterHours.github.io/rwa_calculator/getting-started/) | Installation and first calculation |
| [User Guide](https://OpenAfterHours.github.io/rwa_calculator/user-guide/) | Regulatory frameworks, methodology, exposure classes |
| [Architecture](https://OpenAfterHours.github.io/rwa_calculator/architecture/) | System design and pipeline |
| [Data Model](https://OpenAfterHours.github.io/rwa_calculator/data-model/) | Input schemas and validation |
| [API Reference](https://OpenAfterHours.github.io/rwa_calculator/api/) | Complete technical documentation |
| [Development](https://OpenAfterHours.github.io/rwa_calculator/development/) | Testing, benchmarks, contributing |
| [Plans](https://OpenAfterHours.github.io/rwa_calculator/plans/) | Development roadmap and status |

## Running Tests

```bash
# 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:** ~1,915 tests (1,485 unit + 275 acceptance + 123 contract + ~30 benchmark)

## License

[Apache-2.0 license](LICENSE)

## References

### Current Regulations (CRR / Basel 3.0)
- [PRA Rulebook - CRR Firms](https://www.prarulebook.co.uk/pra-rules/crr-firms)
- [UK CRR - Regulation (EU) No 575/2013 as onshored](https://www.legislation.gov.uk/eur/2013/575/contents)

### Basel 3.1 Implementation (January 2027)
- [PRA PS9/24 - Implementation of the Basel 3.1 standards](https://www.bankofengland.co.uk/prudential-regulation/publication/2024/september/implementation-of-the-basel-3-1-standards-near-final-policy-statement-part-2)
- [PRA CP16/22 - Implementation of Basel 3.1 Standards](https://www.bankofengland.co.uk/prudential-regulation/publication/2022/november/implementation-of-the-basel-3-1-standards)
- [Basel Committee - CRE: Calculation of RWA for credit risk](https://www.bis.org/basel_framework/chapter/CRE/20.htm)
