Skip to main content

quant-ml-toolkit

PyPI version Python versions License: MIT

A small Python toolkit for building quantitative machine-learning pipelines — from raw OHLCV price data through to a trained, explainable model.

The pieces are designed to chain together, but each is usable on its own:

raw OHLCV
   -> technical features        (TechnicalFeatureCalculator)
   -> cleaning & scaling        (FeaturePreprocessor)
   -> feature selection         (FeatureSelector)
   -> train / val / test split  (SampleSplit)
   -> model training + SHAP     (RandomForestModelTrainer)

Installation

pip install quant-ml-toolkit

The base install is lightweight. Two features need optional extras:

pip install "quant-ml-toolkit[talib]"   # technical features (needs the TA-Lib C library, see below)
pip install "quant-ml-toolkit[shap]"    # SHAP explanations
pip install "quant-ml-toolkit[all]"     # everything

TechnicalFeatureCalculator depends on TA-Lib, whose Python wrapper requires the underlying TA-Lib C library to be installed separately (e.g. brew install ta-lib, conda install -c conda-forge ta-lib, or your platform's package manager).

Requires Python 3.10–3.13.

Quick start

The examples assume price data pulled from Yahoo Finance via yfinance.

Note on yfinance columns. Recent versions of yfinance return a MultiIndex column layout by default (e.g. ('Close', 'AAPL')). TechnicalFeatureCalculator matches columns by the suffixes Open/High/Low/Close/Volume, so pass multi_level_index=False to get the flat columns it expects:

import yfinance as yf

ohlcv = yf.download(
    "AAPL", start="2018-01-01", end="2023-12-31",
    multi_level_index=False,   # -> flat Open/High/Low/Close/Volume columns
)

1. Compute technical features

from quant_ml_toolkit import TechnicalFeatureCalculator

calc = TechnicalFeatureCalculator(ohlcv)
features = calc.get_feature_df(
    technical_indicators_close=True,   # Return, ROC, RSI, volatility, Bollinger bands, ...
    technical_indicators_ohlc=True,    # ATR, CCI, Stochastic, ADX, Aroon, Williams %R, ...
    level_measures=True,               # SMA/EMA (10/20/50/200)
    volume_change=True,                # volume % change
    lag_close=True, lag_return=True,   # lagged close / return columns
)

You can also pass a single close-price Series instead of a DataFrame; in that case only the close-based indicators are computed.

2. Build a target and split

import numpy as np
from quant_ml_toolkit import SampleSplit

# example target: sign of next-day return (a simple up/down classification)
features["target"] = np.sign(ohlcv["Close"].pct_change().shift(-1))
data = features.dropna()

feature_cols = [c for c in data.columns if c != "target"]

# chronological split (shuffle=False by default — important for time series)
X_train, y_train, X_test, y_test = SampleSplit.TrainTestXYSplit(
    data, feature_variables=feature_cols, target_variables=["target"],
    train_size=80, test_size=20,
)

3. Preprocess (fit on train, apply to test)

from quant_ml_toolkit import FeaturePreprocessor

pp = FeaturePreprocessor(X_train, test_features_df=X_test)
pp.handle_missing_values()
pp.handle_infinity_values()
pp.handle_outlier_values_boundary_method(z_threshold=3)
pp.normalize(standardize=True)
X_train, X_test = pp.load_data()

All statistics (fill values, outlier bounds, the scaler) are fitted on the training set only and then applied to the test set, so there is no look-ahead leakage.

4. Select features

from quant_ml_toolkit import FeatureSelector

fs = FeatureSelector(X_train, X_test, y_train.squeeze(), model_type="Classification")
fs.remove_constant_features()
fs.remove_correlated_features(corr_thld=0.9)
fs.select_feature_by_mutual_information(select_k=20)
X_train, X_test = fs.X_train, fs.X_test

5. Train, tune and explain

from quant_ml_toolkit import RandomForestModelTrainer

trainer = RandomForestModelTrainer(
    X_train, X_test, y_train.squeeze(), y_test.squeeze(),
    model_type="classification",
)

# randomized hyperparameter search over a sensible default grid
trainer.fit(random_search=True, scoring="accuracy", n_iter=25, cv=3)

predictions = trainer.predict()

# feature importance via SHAP (requires the [shap] extra)
trainer.compute_shap_values()
importance = trainer.get_shap_values_df()      # mean |SHAP| per feature, sorted
trainer.shap_summary_plot(title="Feature importance").show()

Modules

Module Key API What it does
data to_period_timestamp, rolling_window, monthly_return_from_daily_close Date parsing, walk-forward in/out-of-sample windows, daily→monthly returns
features TechnicalFeatureCalculator Technical-indicator feature engineering (TA-Lib)
preprocessing FeaturePreprocessor, get_dummy_and_numerical_variables Leakage-safe missing/inf/outlier handling and scaling
selection FeatureSelector Constant/correlation/mutual-information/RFE/ROC-AUC selection
splitting SampleSplit Percentage-based train/val/test and X/y splits
modelling RandomForestModelTrainer Random-forest training, randomized search, SHAP

License

MIT

Metadata

Release files for quant-ml-toolkit 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quant-ml-toolkit 0.2.0
File Size Uploaded Provenance Actions
quant_ml_toolkit-0.2.0.tar.gz 23.7 kB With provenance Details for quant_ml_toolkit-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for quant-ml-toolkit 0.2.0
File Interpreter ABI Platform Actions
quant_ml_toolkit-0.2.0-py3-none-any.whl Python 3 none any Details for quant_ml_toolkit-0.2.0-py3-none-any.whl

Total release size: 45.1 kB

Release files / quant_ml_toolkit-0.2.0.tar.gz

Download URL quant_ml_toolkit-0.2.0.tar.gz
Size 23.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b3ad31e4bc2b72391599aeed6e9a7ecb38835eea5e7f99e513207eeb5f979df2
BLAKE2b-256 checksum
How to use checksums
c2b42d22d467a176a5d3c2212a38da71baaac3ab1082e09c430e2db826bd6670
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.

Transparency log

Release files / quant_ml_toolkit-0.2.0-py3-none-any.whl

Download URL quant_ml_toolkit-0.2.0-py3-none-any.whl
Size 21.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31e5101b59af651bf4f6f5f1bc1ee09aaea82b5ec8c8c3708e8ff81ea11ecba2
BLAKE2b-256 checksum
How to use checksums
3cc8fb126360da0601d37346613698d3219c14f637ad1aa9788e584a47f450f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.

Transparency log

Security for quant-ml-toolkit 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for quant_ml_toolkit-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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