Skip to main content

bartons

Financial and technical-analysis expressions for polars, implemented in Rust as a native plugin (PyO3 + maturin).

Each indicator is a factory returning a pl.Expr, so it composes with the rest of polars — inside select, with_columns, over, lazy frames, and so on.

Install

Requires Python 3.11+ and polars>=1.28,<1.44. Wheels are cp311-abi3, so one wheel per platform covers every Python from 3.11 up.

pip install bartons

Usage

import polars as pl
from bartons.indicators import ATR, CCI, EMA, MACD, MAD, RSI
from bartons.samples import sample_prices

prices = sample_prices("daily")

prices.select("date", "close", ema=EMA(20), rsi=RSI(14), atr=ATR(14)).tail(3)
┌────────────┬────────────┬────────────┬───────────┬──────────┐
│ date       ┆ close      ┆ ema        ┆ rsi       ┆ atr      │
╞════════════╪════════════╪════════════╪═══════════╪══════════╡
│ 2024-08-07 ┆ 209.820007 ┆ 217.642081 ┆ 40.192313 ┆ 6.920431 │
│ 2024-08-08 ┆ 213.309998 ┆ 217.229501 ┆ 45.237928 ┆ 6.809686 │
│ 2024-08-09 ┆ 216.240005 ┆ 217.135264 ┆ 49.118920 ┆ 6.666851 │
└────────────┴────────────┴────────────┴───────────┴──────────┘

Single-source indicators default to pl.col("close") and also accept an explicit source, which makes them chain with pipe:

EMA(20)                          # close by default
EMA(pl.col("open"), 20)          # explicit source
pl.col("close").pipe(EMA, 5).pipe(RSI, 14)

TRANGE and ATR read high, low and close, each overridable by keyword.

Indicators

EMA(period) Exponential moving average
SMA(period) Simple moving average
RMA(period) Wilder's running moving average
WMA(period) Weighted moving average
RSI(period) Wilder's relative strength index
TRANGE() True range
ATR(period) Average true range
MACD(fast=12, slow=26, signal=9) MACD, signal and histogram expressions
MAD(period=20) Rolling mean absolute deviation
CCI(period=20) Commodity Channel Index

Multi-output native indicators return an ExprBundle, which Polars accepts as one argument and expands into ordinary columns:

prices.with_columns(MACD())
prices.with_columns(*MACD(), SMA(20))  # splat when mixing with other expressions

Eager API

The compiled kernels are also callable directly on a pl.Series, bypassing the expression layer:

from bartons import kernels

kernels.ema(prices["close"], period=20)

Parameters are keyword-only here. This path needs polars>=1.28; the expression API alone works further back.

Related Projects

  • Polars — the DataFrame library. Since every indicator here is a plain pl.Expr, its expression docs cover most of what you can do with them: windows, groups, lazy frames, and the rest.
  • PyO3 — Rust bindings for Python, and the polars plugin interface these kernels are written against. Worth reading if you want to write indicators of your own.
  • Maturin — builds and publishes Rust extensions as Python wheels. The tool to reach for if you take that route.

Download files

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

Source Distribution

bartons-0.1.0.tar.gz (583.2 kB view details)

Uploaded Source

Built Distribution

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

bartons-0.1.0-cp311-abi3-manylinux_2_34_aarch64.whl (6.5 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.34+ ARM64

File details

Details for the file bartons-0.1.0.tar.gz.

File metadata

  • Download URL: bartons-0.1.0.tar.gz
  • Upload date:
  • Size: 583.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.7

File hashes

Hashes for bartons-0.1.0.tar.gz
Algorithm Hash digest
SHA256 440de355698bc4631bb69f5d0846566e1bd62bd1ceada43fd8ff09f1b9594633
MD5 84eac9c60afb99badbf22ff8dea0d0ab
BLAKE2b-256 3b38d12ab394c51dc00ebc962f0e49ebd959dc3643dfe56e0d48cc2c2126f0aa

See more details on using hashes here.

File details

Details for the file bartons-0.1.0-cp311-abi3-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for bartons-0.1.0-cp311-abi3-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 49a5801c94556b8d08bb8f62d17189faab6b98a354ca009132b837ade1409ee3
MD5 678ca77208402ae50a5cb685f5c227a1
BLAKE2b-256 994f86e5dbde1e8e6866bbb885037a4ea99db3bba3ac5986c82509390d98df4f

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.7

6 files

0.1.6

6 files

0.1.5

6 files

0.1.4

6 files

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

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