Financial AI using Python, based on 'Advances in Financial Machine Learning' and 'Machine Learning for Asset Managers'.
Project description
RiskLabAI.py
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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e2876fafd55cb7886b3b4589720d532ed3b511783be288c7da871708c73dbab
|
|
| MD5 |
4e9f1a2442de321f8bdd2e4086a39afc
|
|
| BLAKE2b-256 |
eb7f28000a26c3d02b9eb5e86d55242d78c21d2fa21440cac5f0efdbd5a4b0c8
|
Provenance
The following attestation bundles were made for risklabai-2.0.1.tar.gz:
Publisher:
publish.yml on RiskLabAI/RiskLabAI.py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
risklabai-2.0.1.tar.gz -
Subject digest:
4e2876fafd55cb7886b3b4589720d532ed3b511783be288c7da871708c73dbab - Sigstore transparency entry: 1885168852
- Sigstore integration time:
-
Permalink:
RiskLabAI/RiskLabAI.py@9c4fc68b8d6dde3886acc554e991675e7360ad6f -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/RiskLabAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9c4fc68b8d6dde3886acc554e991675e7360ad6f -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7662f15c630314c9432513408517b9ce6507119d855c93d58b730bcf5e29d67a
|
|
| MD5 |
5eb111de88ff142bae896486a6400599
|
|
| BLAKE2b-256 |
b08a9a3aa3e8df1a04cc008bd91b1493d80a357db3bbee143e419bca4c2f6836
|
Provenance
The following attestation bundles were made for risklabai-2.0.1-py3-none-any.whl:
Publisher:
publish.yml on RiskLabAI/RiskLabAI.py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
risklabai-2.0.1-py3-none-any.whl -
Subject digest:
7662f15c630314c9432513408517b9ce6507119d855c93d58b730bcf5e29d67a - Sigstore transparency entry: 1885168957
- Sigstore integration time:
-
Permalink:
RiskLabAI/RiskLabAI.py@9c4fc68b8d6dde3886acc554e991675e7360ad6f -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/RiskLabAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9c4fc68b8d6dde3886acc554e991675e7360ad6f -
Trigger Event:
release
-
Statement type: