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.1.tar.gz (140.2 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.1-py3-none-any.whl (181.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: risklabai-2.0.1.tar.gz
  • Upload date:
  • Size: 140.2 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.1.tar.gz
Algorithm Hash digest
SHA256 4e2876fafd55cb7886b3b4589720d532ed3b511783be288c7da871708c73dbab
MD5 4e9f1a2442de321f8bdd2e4086a39afc
BLAKE2b-256 eb7f28000a26c3d02b9eb5e86d55242d78c21d2fa21440cac5f0efdbd5a4b0c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for risklabai-2.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: risklabai-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 181.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7662f15c630314c9432513408517b9ce6507119d855c93d58b730bcf5e29d67a
MD5 5eb111de88ff142bae896486a6400599
BLAKE2b-256 b08a9a3aa3e8df1a04cc008bd91b1493d80a357db3bbee143e419bca4c2f6836

See more details on using hashes here.

Provenance

The following attestation bundles were made for risklabai-2.0.1-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