Skip to main content

Blazingly Fast Polars Quant Tool

Project description

polars-quant

polars-quant 🧮📊

A compact, code-first toolkit of technical indicators and simple backtesting utilities implemented in Rust and exposed to Python via PyO3. Designed for research and small-scale backtests using Polars DataFrames.

Key points

  • License: MIT (see LICENSE).
  • No GPU/CUDA features are included — CPU-only Rust + Polars implementation.
  • The Python API signatures are authoritative in python/polars_quant/polars_quant.pyi.

Install (Windows PowerShell)

python -m venv .venv; .\.venv\Scripts\Activate.ps1
pip install polars polars-quant

From source (dev)

git clone https://github.com/Firstastor/polars-quant.git
cd polars-quant
pip install -e .
# If building native extensions you will need Rust toolchain
# rustup and MSVC build tools on Windows

Quick examples (detailed) ⚡

  1. Compute a 3-period moving average on a price series
import polars as pl
import polars_quant as plqt

df = pl.DataFrame({'close': [100.0, 101.0, 102.0, 103.0, 104.0]})

# `ma` returns a list of Series (one per numeric column).
ma_list = plqt.ma(df, 3)
print(type(ma_list), len(ma_list))
# To attach results back to a DataFrame:
res_df = df.with_columns(ma_list)
print(res_df)
  1. MACD example (single series)
df = pl.DataFrame({'close': [100.0, 101.0, 102.5, 101.0, 103.0, 104.0]})
macd_series = plqt.macd(df, fast=12, slow=26, signal=9)
# macd returns [dif, dea, macd] series
res = df.with_columns(macd_series)
print(res)
  1. ADX (expects OHLC columns: lowercase high, low, close)
df = pl.DataFrame({
	'high': [10.0, 10.5, 11.0],
	'low': [9.5, 9.8, 10.2],
	'close': [10.0, 10.4, 10.8]
})
adx_df = plqt.adx(df, timeperiod=14)  # returns a DataFrame with `adx` column added
print(adx_df)

Backtesting (small example) 🧾

import polars as pl
from polars_quant import Backtrade

# sample price data for one symbol
data = pl.DataFrame({
	'Date': ['2023-01-01','2023-01-02','2023-01-03','2023-01-04'],
	'AAPL': [100.0, 102.0, 101.0, 105.0]
})

# entry/exit signals must match the data shape (boolean)
entries = pl.DataFrame({
	'Date': data['Date'],
	'AAPL': [True, False, False, True]
})
exits = pl.DataFrame({
	'Date': data['Date'],
	'AAPL': [False, True, True, False]
})

bt = Backtrade.run(data, entries, exits, init_cash=100000.0, fee=0.001)
bt.summary()

Docs

  • API reference: docs/api.md (short, code-driven)
  • Examples: docs/start/usage.md
  • Exact Python signatures: python/polars_quant/polars_quant.pyi

If you want a full parity table (function → pyi signature → Rust output columns), tell me and I'll generate it from the codebase.

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

polars_quant-0.3.0.tar.gz (63.9 kB view details)

Uploaded Source

Built Distribution

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

polars_quant-0.3.0-cp39-abi3-win_amd64.whl (10.4 MB view details)

Uploaded CPython 3.9+Windows x86-64

File details

Details for the file polars_quant-0.3.0.tar.gz.

File metadata

  • Download URL: polars_quant-0.3.0.tar.gz
  • Upload date:
  • Size: 63.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.9.4

File hashes

Hashes for polars_quant-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e848f9d544ff66f594e8e11d600c3c3a223c8349020ed3bdbe7f57bc60b86975
MD5 856650845005f7b686fb281129aa93c9
BLAKE2b-256 354b6812dd465e2729e70fec319a7d462ced838f4a85cc9d693def34437c291a

See more details on using hashes here.

File details

Details for the file polars_quant-0.3.0-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for polars_quant-0.3.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c475fab789351d891cbcc50e73f53a684b80fb208a96b114f9be7e1670b22471
MD5 48ce08b88ea56c1f2308974be361989c
BLAKE2b-256 cc81034fe617580addd452c2a90103a28cf0829ecb77fba19e9625eb78a46fc9

See more details on using hashes here.

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