A cohomological approach to financial risk scoring using persistent homology and sheaf theory
Project description
Cohomological Risk Scoring
Author: Idriss Bado
A sophisticated Python package for financial risk assessment using cohomological methods, persistent homology, and sheaf theory. This framework provides a mathematically rigorous approach to identifying systemic risks and anomalies in financial transaction networks.
Overview
This package implements the Persistence of Cohomological Risk (PCR) scoring methodology, which uses algebraic topology to detect structural inconsistencies in financial networks. Unlike traditional graph-based methods, this approach captures higher-order relationships and cyclic dependencies that often indicate fraudulent behavior or systemic risk.
Key Features
- Sheaf-Theoretic Framework: Model financial data as sheaves over simplicial complexes
- Persistent Cohomology: Compute topological features across multiple scales
- Risk Scoring: Assign cohomological risk scores to entities based on structural inconsistencies
- Risk Class Identification: Automatically identify Cohomological Risk Classes (CRCs)
- Visualization Tools: Generate persistence diagrams and risk score distributions
- Network Analysis: Build and analyze financial transaction networks
Mathematical Foundation
The package is built on three key mathematical concepts:
-
Simplicial Complexes: Financial networks are modeled as simplicial complexes where vertices represent entities, edges represent transactions, and higher-dimensional simplices capture multi-party relationships.
-
Sheaf Theory: Data is organized as a sheaf, with stalks at each simplex and restriction maps encoding consistency conditions.
-
Persistent Cohomology: Cohomological features are tracked across a filtration, revealing persistent structural anomalies that indicate risk.
Installation
From PyPI (when published)
pip install cohomological-risk-scoring
From Source
git clone https://github.com/idrissbado/cohomological-risk-scoring.git
cd cohomological-risk-scoring
pip install -e .
Development Installation
pip install -e ".[dev]"
Quick Start
import networkx as nx
from cohomological_risk_scoring import PCRScorer
from cohomological_risk_scoring.utils import create_example_network
# Create or load your financial network
G, vertex_features, edge_features = create_example_network(n_vertices=30)
# Initialize the scorer
scorer = PCRScorer(max_dim=2, filtration_param='weight')
# Fit the model
scorer.fit(G, vertex_features, edge_features)
# Compute risk scores
scores = scorer.compute_all_scores()
# Identify high-risk entities
high_risk = {v: s for v, s in scores.items() if s > 0.7}
print(f"High-risk entities: {high_risk}")
# Get risk classes
risk_classes = scorer.get_risk_classes(threshold=0.1)
# Visualize results
scorer.visualize_persistence(save_path='persistence_diagram.png')
# Generate detailed report
print(scorer.generate_report())
Core Components
FinancialSheaf
The FinancialSheaf class implements the mathematical foundation:
- Complex Construction: Build simplicial complexes from financial graphs
- Sheaf Data: Define vertex and edge stalks with restriction maps
- Cohomology Computation: Calculate coboundary matrices and cohomology groups
- Persistent Cohomology: Track cohomological features across filtrations
PCRScorer
The PCRScorer class provides the main interface:
- Fit: Build the sheaf model from financial data
- Score Computation: Calculate PCR scores for all entities
- Risk Classification: Identify Cohomological Risk Classes
- Visualization: Generate persistence diagrams and score distributions
- Reporting: Create comprehensive analysis reports
Use Cases
- Anti-Money Laundering (AML): Detect circular transaction patterns
- Fraud Detection: Identify inconsistent financial behavior
- Credit Risk: Assess systemic risk in lending networks
- Market Manipulation: Detect coordinated trading schemes
- Regulatory Compliance: Monitor for suspicious activity patterns
Requirements
- Python >= 3.8
- NumPy >= 1.20.0
- SciPy >= 1.7.0
- NetworkX >= 2.6.0
- GUDHI >= 3.5.0
- Persim >= 0.3.0
- Matplotlib >= 3.4.0
Documentation
Full documentation is available at https://cohomological-risk-scoring.readthedocs.io
Examples
See the examples/ directory for detailed usage examples:
basic_usage.py: Introduction to the packageadvanced_analysis.py: Custom restriction functions and advanced featuresreal_world_data.py: Working with real financial datasets
Testing
Run the test suite:
pytest tests/
With coverage:
pytest --cov=cohomological_risk_scoring tests/
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Citation
If you use this package in your research, please cite:
@software{bado2025cohomological,
author = {Bado, Idriss},
title = {Cohomological Risk Scoring: A Topological Approach to Financial Risk Assessment},
year = {2025},
url = {https://github.com/idrissbado/cohomological-risk-scoring}
}
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Idriss Bado
- GitHub: @idrissbado
- Email: idrissbadoolivier@gmail.com
Acknowledgments
- The GUDHI library team for persistent homology tools
- The NetworkX community for graph analysis capabilities
- Researchers in topological data analysis and financial mathematics
Roadmap
- Support for directed graphs
- GPU acceleration for large-scale networks
- Integration with popular fraud detection frameworks
- Real-time monitoring capabilities
- Interactive web-based visualization
- Extended documentation with tutorials
- Benchmark datasets for evaluation
References
- Carlsson, G. (2009). "Topology and data." Bulletin of the American Mathematical Society, 46(2), 255-308.
- Ghrist, R. (2014). "Elementary Applied Topology." Createspace.
- Hansen, J., & Ghrist, R. (2019). "Toward a spectral theory of cellular sheaves." Journal of Applied and Computational Topology, 3(4), 315-358.
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 cohomological_risk_scoring-0.1.0.tar.gz.
File metadata
- Download URL: cohomological_risk_scoring-0.1.0.tar.gz
- Upload date:
- Size: 21.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfdf7de5ebab0434e9ce7c815ebec6c49657e64fdc9a53a0c142714b26e919fe
|
|
| MD5 |
e1db1332316ba3e1277da27b97bd6c56
|
|
| BLAKE2b-256 |
e15d1251325a096bac8dde09a3609d593856bf12960bf787a5d58d0c7f2e1784
|
File details
Details for the file cohomological_risk_scoring-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cohomological_risk_scoring-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9daaad87763a41b86cd21c4a48655ca348fa0478da098a4a0a8864323b97724
|
|
| MD5 |
c88bb772e16ae118f099447b89b44ca9
|
|
| BLAKE2b-256 |
9f97e76049d1b4a2e994870f68e63c650981f8bc805392c1a770f3eb40b09fb4
|