Metadata-Version: 2.4
Name: RiskLabAI
Version: 2.0.1
Summary: Financial AI using Python, based on 'Advances in Financial Machine Learning' and 'Machine Learning for Asset Managers'.
Author-email: RiskLab <arian@risklab.ai>
License: BSD 3-Clause License
        
        Copyright (c) 2022, RiskLab AI (risklab.ai)
        All rights reserved.
        
        RiskLabAI includes codes and algorithms from Marcos López de Prado's books 
        "Advances in Financial Machine Learning" and 
        "Machine Learning for Asset Managers".
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Project-URL: Homepage, https://github.com/RiskLabAI/RiskLabAI.py
Project-URL: Bug Tracker, https://github.com/RiskLabAI/RiskLabAI.py/issues
Project-URL: Changelog, https://github.com/RiskLabAI/RiskLabAI.py/blob/main/CHANGELOG.md
Keywords: finance,machine learning,quantitative finance,fintech,de prado,backtesting
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: BSD License
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Topic :: Office/Business :: Financial
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy<3,>=1.22
Requires-Dist: pandas>=1.5
Requires-Dist: scipy>=1.8
Requires-Dist: scikit-learn>=1.1
Requires-Dist: statsmodels>=0.13
Requires-Dist: numba>=0.57
Requires-Dist: joblib>=1.1
Requires-Dist: ta>=0.10
Requires-Dist: tqdm>=4.60
Requires-Dist: sympy>=1.10
Provides-Extra: pde
Requires-Dist: torch; extra == "pde"
Provides-Extra: synth
Requires-Dist: quantecon; extra == "synth"
Provides-Extra: plot
Requires-Dist: matplotlib; extra == "plot"
Requires-Dist: seaborn; extra == "plot"
Requires-Dist: plotly; extra == "plot"
Provides-Extra: dev
Requires-Dist: yfinance; extra == "dev"
Requires-Dist: memory_profiler; extra == "dev"
Requires-Dist: jupyterlab; extra == "dev"
Requires-Dist: stable-baselines3; extra == "dev"
Requires-Dist: gymnasium; extra == "dev"
Requires-Dist: torchvision; extra == "dev"
Requires-Dist: torchaudio; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: black==26.5.1; extra == "dev"
Requires-Dist: ruff==0.15.17; extra == "dev"
Provides-Extra: all
Requires-Dist: RiskLabAI[pde]; extra == "all"
Requires-Dist: RiskLabAI[synth]; extra == "all"
Requires-Dist: RiskLabAI[plot]; extra == "all"
Dynamic: license-file

# RiskLabAI.py

[![PyPI version](https://badge.fury.io/py/RiskLabAI.svg)](https://badge.fury.io/py/RiskLabAI)
[![CI](https://github.com/RiskLabAI/RiskLabAI.py/actions/workflows/ci.yml/badge.svg)](https://github.com/RiskLabAI/RiskLabAI.py/actions/workflows/ci.yml)

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](https://github.com/RiskLabAI/RiskLabAI.jl), which mirrors this
API.

## Installation

```bash
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 |

```bash
pip install "RiskLabAI[all]"
```

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

## Quickstart

Sample dollar/volume/tick bars from raw ticks:

```python
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:

```python
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:

```python
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`](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):

```bash
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`](LICENSE.txt).
