Skip to main content

Financial AI using Python, based on 'Advances in Financial Machine Learning' and 'Machine Learning for Asset Managers'.

Project description

RiskLabAI.py

PyPI version CI

A Python library for quantitative finance and financial machine learning, implementing core methods from Marcos López de Prado's Advances in Financial Machine Learning and Machine Learning for Asset Managers.

The library provides implementations for:

  • Financial data structures — tick, volume, dollar, imbalance, and run bars
  • Labeling — the triple-barrier method, meta-labeling, trend-scanning
  • Fractional differentiation — standard and fixed-width window (FFD)
  • Sample weights, denoising (Marčenko–Pastur), distance metrics
  • Cross-validation — Purged K-Fold, Combinatorial Purged CV (+ adaptive/bagged), walk-forward
  • Feature importance — MDI, MDA, SFI, and clustered variants
  • Portfolio optimization — HRP, NCO, hedging
  • Backtest statistics — PSR/DSR, PBO, strategy risk
  • Microstructure & entropy features, structural breaks, and a Deep-BSDE PDE solver

There is a companion Julia package, RiskLabAI.jl, which mirrors this API.

Installation

pip install RiskLabAI

The base install is lightweight. Heavier, optional capabilities are available as extras:

Extra Installs Enables
RiskLabAI[pde] torch the Deep-BSDE PDE solver (RiskLabAI.pde)
RiskLabAI[plot] matplotlib, seaborn, plotly plotting helpers
RiskLabAI[synth] quantecon synthetic-data utilities
RiskLabAI[all] all of the above everything
pip install "RiskLabAI[all]"

For development (editable install + tests), see INSTALLATION.md.

Quickstart

Sample dollar/volume/tick bars from raw ticks:

from RiskLabAI.data.structures.standard_bars import StandardBars
from RiskLabAI.utils.constants import CUMULATIVE_DOLLAR

# ticks: an iterable of (datetime, price, volume)
ticks = [
    ("2020-01-01 10:00:00", 100.0, 10),
    ("2020-01-01 10:00:01", 101.0, 5),
    ("2020-01-01 10:00:02", 100.0, 20),
]

bars = StandardBars(bar_type=CUMULATIVE_DOLLAR, threshold=3000)
bar_list = bars.construct_bars_from_data(ticks)
# each bar: [date_time, idx, open, high, low, close, volume,
#            buy_volume, sell_volume, ticks, dollar, threshold]

Discover and construct components by name through the extension registry:

import RiskLabAI.core as core

core.list_components()                       # {family: [available keys]}
cv = core.CROSS_VALIDATORS.create("purgedkfold", n_splits=5, times=event_times)

Logging

RiskLabAI logs under the "RiskLabAI" logger and is silent by default. To see progress and diagnostics, configure logging in your application:

import logging
logging.basicConfig(level=logging.INFO)

Extending the library

RiskLabAI is built to be extended with new models. The RiskLabAI.core layer provides a component registry and base interfaces so a new bar type, labeler, cross-validator, etc. can be registered and discovered without editing central code. See EXTENDING.md for a step-by-step guide with worked examples.

Contributing

Contributions are welcome. The project uses pytest for tests and black + ruff for formatting/linting (run before opening a PR):

pip install -e ".[all]" pytest black ruff
pytest -q --ignore=test/pde
black RiskLabAI test
ruff check RiskLabAI test

Please branch from main, keep changes focused, and update CHANGELOG.md.

License

See LICENSE.txt.

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

risklabai-2.0.0.tar.gz (140.0 kB view details)

Uploaded Source

Built Distribution

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

risklabai-2.0.0-py3-none-any.whl (181.6 kB view details)

Uploaded Python 3

File details

Details for the file risklabai-2.0.0.tar.gz.

File metadata

  • Download URL: risklabai-2.0.0.tar.gz
  • Upload date:
  • Size: 140.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for risklabai-2.0.0.tar.gz
Algorithm Hash digest
SHA256 7acebc1fc0c8b13300000ac2af6c4c2e297878edf93f17de2e0973a4faea1605
MD5 b4f41193de60c4611a6c4f01ef4784a5
BLAKE2b-256 3b2f18291e5de03af17a54c5dc703bdac7825bf7bade572ea5140ea7d77d10c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for risklabai-2.0.0.tar.gz:

Publisher: publish.yml on RiskLabAI/RiskLabAI.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file risklabai-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: risklabai-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 181.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for risklabai-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 49923ba105cbf0bb351219f36a55c61e147ed0615abe4984bd1bdaefca8af110
MD5 cef2e61232906c7d8f44e2146bb4a330
BLAKE2b-256 ee0b7fde7cd52b7d3fef7a96e30c2b569a08cd084391220960160084008b4310

See more details on using hashes here.

Provenance

The following attestation bundles were made for risklabai-2.0.0-py3-none-any.whl:

Publisher: publish.yml on RiskLabAI/RiskLabAI.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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