Skip to main content

Finance decision intelligence tools for cost-sensitive credit and fraud risk modelling.

Project description

FinCausal

FinCausal is a finance-focused Python library for decision-risk analysis, cost-sensitive classification, and model-governance workflows in credit risk, fraud detection, AML alerting, and operational risk review.

It helps analysts move from a narrow model-performance question:

“Does this model have good accuracy?”

To a decision-governance question:

“Which decision threshold reduces expected financial loss while respecting customer-impact and operational constraints?”

Version 0.4.1 focus

Version 0.4.1 adds the missing governance modules around the core cost-sensitive classifier:

  • constrained threshold optimisation
  • calibration checks
  • fairness/customer-impact checks
  • model monitoring and drift diagnostics
  • explanation utilities
  • report export to Markdown and HTML
  • train/validation/test backtesting helper
  • rolling-period backtesting helper
  • benchmark CSV loader
  • edge-case test coverage
  • safe dependency ranges for NumPy/Pandas/scikit-learn

Installation

Recommended clean environment:

conda create -n fincausal-env python=3.11 -y
conda activate fincausal-env
pip install dist/fincausal-0.4.1-py3-none-any.whl

From PyPI after publishing:

pip install fincausal

Quick start

from fincausal import (
    CostMatrix,
    CostSensitiveClassifier,
    make_credit_risk_data,
    train_validation_test_split,
)

X, y = make_credit_risk_data(n_samples=5000, random_state=42)
X_train, X_val, X_test, y_train, y_val, y_test = train_validation_test_split(X, y)

costs = CostMatrix(false_positive=100, false_negative=5000, currency="GBP")
model = CostSensitiveClassifier(cost_matrix=costs)
model.fit(X_train, y_train)

result = model.optimize_threshold(
    X_val,
    y_val,
    max_flagged_rate=0.45,
    min_precision=0.35,
)

print(result["best_threshold"])
print(model.loss_report(X_test, y_test))

Calibration checks

calibration = model.calibration_report(X_test, y_test, n_bins=10)
print(calibration["brier_score"])
print(calibration["expected_calibration_error"])
print(calibration["table"])

Fairness/customer-impact checks

import pandas as pd

segments = pd.qcut(X_test["income"], q=3, labels=["low", "middle", "high"])
fairness = model.fairness_report(X_test, y_test, segments, threshold=model.best_threshold_)
print(fairness)

This is a customer-impact/model-governance check. It is not a legal protected-class fairness certification.

Model monitoring and drift

score_drift = model.score_drift_report(X_train, X_test)
print(score_drift)

Feature PSI:

from fincausal import feature_drift_report

print(feature_drift_report(X_train, X_test))

Explanation utilities

importance = model.feature_importance_report(X_test, y_test, n_repeats=5)
print(importance)

Reports

report = model.decision_report(X_test, y_test)
report.save_markdown("fincausal_report.md")
report.save_html("fincausal_report.html")

Backtesting

from fincausal import threshold_validation_backtest

backtest = threshold_validation_backtest(
    X_train,
    y_train,
    X_val,
    y_val,
    X_test,
    y_test,
    cost_matrix=costs,
    max_flagged_rate=0.45,
    min_precision=0.35,
)

print(backtest["optimized_test_report"])

Benchmark data

Built-in synthetic benchmark:

from fincausal import make_credit_risk_data
X, y = make_credit_risk_data(n_samples=5000, random_state=42)

External CSV loader:

from fincausal import load_credit_risk_csv
X, y = load_credit_risk_csv("credit_data.csv", target_col="default_risk")

Testing

pytest

Current local status:

27 passed

Dependency policy

The package uses safe dependency ranges to avoid forcing unstable major-version upgrades:

numpy>=1.23,<2.0
pandas>=1.5,<3.0
scikit-learn>=1.2,<1.8
scipy>=1.9,<1.16

Limitations

FinCausal is an early-stage alpha library. It is not a production-grade bank model-risk platform and does not replace independent validation, regulatory review, security review, or legal fairness assessment.

All results depend on model quality, sample design, selected business constraints, and supplied cost assumptions.

Roadmap

  • public benchmark notebooks
  • documentation website
  • GitHub Actions CI/CD
  • versioned PyPI release workflow
  • richer PDF/HTML report templates
  • SHAP integration as optional extra
  • monitoring dashboard examples

License

MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fincausal-0.4.1.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fincausal-0.4.1-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file fincausal-0.4.1.tar.gz.

File metadata

  • Download URL: fincausal-0.4.1.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for fincausal-0.4.1.tar.gz
Algorithm Hash digest
SHA256 40e6316adfe6a59d86a281c8b7863e6835102c8c3ea2e631631376992e1a7d68
MD5 3b0ba8bde3a6200dfc7d1b9244e99ac5
BLAKE2b-256 78df1e9dca657565418e1a944a2e022e37359197ffb7a4384b25aaa3af20d83d

See more details on using hashes here.

File details

Details for the file fincausal-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: fincausal-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for fincausal-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fd6f761ba11311044759333a925fbe554fa80d9ffcd8769b054c604739aa1f42
MD5 de1a9698bef820060be92858468b44d6
BLAKE2b-256 d211d6225288d6679fa504e493f6879ece420a428258f259385427f694f531a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page