Skip to main content

RiskLabAI

PyPI version CI

RiskLabAI is a Python library for quantitative finance, financial machine learning, and causal factor analysis. It provides research-oriented implementations of methods associated with Marcos López de Prado's Advances in Financial Machine Learning, Machine Learning for Asset Managers, and Causal Factor Investing.

RiskLabAI 3.0.0 preserves the previously published Python library and adds a clean causal-factor-analysis namespace. The companion RiskLabAI.jl package independently implements the same 57 causal concepts. This parity statement applies to the causal API, not to every Python module.

What is included

  • Causal factor analysis - constrained minimum-variance allocation, factor-mirage diagnostics, graphical identification, treatment-effect formulas, specification experiments, and evidence records for the seven-stage causal-factor protocol
  • Financial data structures - tick, volume, dollar, imbalance, run, and time bars
  • Labeling and sample weights - triple-barrier, meta-labeling, trend-scanning, uniqueness, and time-decay methods
  • Fractional differentiation and denoising - fixed-width fractional differentiation, Marcenko-Pastur denoising, and targeted shrinkage
  • Validation and feature importance - purged and combinatorial cross-validation, walk-forward validation, MDI, MDA, SFI, and clustered variants
  • Portfolio and backtest analytics - HRP, NCO, hedging, PSR/DSR, PBO, and strategy-risk tools
  • Market features - microstructure, entropy, structural-break, and technical-indicator utilities
  • Optional capabilities - plotting, optimization, simulation, symbolic analysis, changepoint detection, acceleration, synthetic-control tools, and a Deep-BSDE PDE solver

Compatibility

RiskLabAI 3.0.0 supports CPython 3.12, 3.13, and 3.14 with NumPy >=2.2,<3. The complete tested policy and feature-specific limitations are in docs/compatibility.md.

Installation

Install the base package from PyPI:

python -m pip install RiskLabAI

Optional dependency groups can be installed individually or together:

Extra Enables
speed Numba acceleration
pde Deep-BSDE PDE solver using PyTorch
synth synthetic-control utilities using QuantEcon
hpo hyperparameter tuning using Optuna
plot Matplotlib, Seaborn, and Plotly helpers
symbolic symbolic analysis using SymPy
profile memory profiling
simulation simulation progress support
changepoints changepoint detection on Python 3.12-3.13
test the supported pytest test runner

For example:

python -m pip install "RiskLabAI[plot,speed]"

There is intentionally no all extra. See INSTALLATION.md for environment setup, all tested optional groups, and development instructions.

Causal-factor quick start

import numpy as np

from RiskLabAI.causal_factor_analysis import (
    CausalDAG,
    average_treatment_effect,
    check_backdoor_adjustment_set,
    minimum_variance_factor_weights,
)

covariance = np.diag([1.0, 2.0, 4.0])
factor_exposures = np.array([[1.0, 0.0], [0.0, 1.0], [1.0, 1.0]])
target_exposures = np.array([0.0, 1.0])

weights = minimum_variance_factor_weights(
    covariance,
    factor_exposures,
    target_exposures,
)
np.testing.assert_allclose(weights, [-2.0 / 7.0, 5.0 / 7.0, 2.0 / 7.0])

effect = average_treatment_effect(3.5, 1.25)
assert effect == 2.25

dag = CausalDAG(
    nodes=("T", "U", "Y"),
    directed_edges=(("U", "T"), ("U", "Y"), ("T", "Y")),
    observed_nodes=("T", "U", "Y"),
)
assert check_backdoor_adjustment_set(dag, "T", "Y", ("U",)).admissible

The complete deterministic example is examples/causal_factor_analysis_quickstart.py. The causal API and its limits are documented in docs/causal_factor_analysis.md.

Financial-data quick start

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

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)

Extending the library

The RiskLabAI.core registries provide discovery and construction points for bars, cross-validators, feature-importance models, labelers, bet sizers, and portfolio optimizers. For example:

import pandas as pd

from RiskLabAI.core import CROSS_VALIDATORS, list_components

catalogue = list_components()
start_times = pd.to_datetime(["2024-01-02", "2024-01-03", "2024-01-04"])
event_times = pd.Series(
    pd.to_datetime(["2024-01-03", "2024-01-04", "2024-01-05"]),
    index=start_times,
)
cross_validator = CROSS_VALIDATORS.create(
    "purgedkfold",
    n_splits=5,
    times=event_times,
)

See EXTENDING.md for the extension interfaces and examples.

Development

python -m pip install -e ".[test]" "black==26.5.1" "ruff==0.15.17"
python -m pytest -q
black --check src/RiskLabAI/causal_factor_analysis test/causal_factor_analysis
ruff check src/RiskLabAI/causal_factor_analysis test/causal_factor_analysis

Please branch from main, keep changes focused, and include tests for behavior changes.

Scope

RiskLabAI is research software, not investment advice. Graph routines evaluate criteria on a caller-supplied directed acyclic graph; they do not discover or certify that graph. Protocol records validate declared evidence structures; they do not prove that empirical assumptions are true.

License

RiskLabAI is distributed under the BSD 3-Clause License.

Download files

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

Source Distribution

risklabai-3.0.0.tar.gz (359.9 kB view details)

Uploaded Source

Built Distribution

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

risklabai-3.0.0-py3-none-any.whl (280.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: risklabai-3.0.0.tar.gz
  • Upload date:
  • Size: 359.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for risklabai-3.0.0.tar.gz
Algorithm Hash digest
SHA256 3b20864396313f457f68a09eb11d27b7fd4f7b03c69079b473a57c9038529bd3
MD5 7a99f4b867bd82062976b1b9a95314a9
BLAKE2b-256 935e3252be42f84a092cbbcf4eccc75553eb06713320943db66d9245f887dc21

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: risklabai-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 280.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for risklabai-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0109bb6f761a39f218bc301f832ede256c70c9d40490da46a675dd1aba3caa57
MD5 4e9a102a874c747470f78d994c89953e
BLAKE2b-256 c2201e9107d639fe135caf304b24dabb480fb67b3ce5f726a2301e0c869a056a

See more details on using hashes here.

Provenance

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

Release history Release notifications | RSS feed

3.1.0

2 files

This release

3.0.0 This release

2 files

2.0.1

2 files

2.0.0

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.0.93

2 files

0.0.92

2 files

0.0.91

2 files

0.0.89

2 files

0.0.88

2 files

0.0.87

2 files

0.0.85

2 files

0.0.84

2 files

0.0.82

2 files

0.0.81

2 files

0.0.80

2 files

0.0.79

2 files

0.0.78

2 files

0.0.77

2 files

0.0.74

2 files

0.0.73

2 files

0.0.71

2 files

0.0.70

2 files

0.0.69

2 files

0.0.68

2 files

0.0.66

2 files

0.0.65

2 files

0.0.64

2 files

0.0.63

2 files

0.0.62

2 files

0.0.61

2 files

0.0.60

2 files

0.0.59

2 files

0.0.58

2 files

0.0.57

2 files

0.0.56

2 files

0.0.55

2 files

0.0.54

2 files

0.0.53

2 files

0.0.52

2 files

0.0.51

2 files

0.0.50

2 files

0.0.49

2 files

0.0.48

2 files

0.0.46

2 files

0.0.45

2 files

0.0.19

2 files

0.0.18

2 files

0.0.17

2 files

0.0.16

2 files

0.0.15

2 files

0.0.14

2 files

0.0.13

2 files

0.0.12

2 files

0.0.11

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.4

2 files

0.0.1

2 files

0.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page