Skip to main content

Stateless Technical Analysis Library built with ♥︎ by Laakhay

Project description

Laakhay TA

Laakhay TA is a stateless technical analysis toolkit built on immutable data structures, explicit indicator metadata, and algebraic composition.

Highlights

  • Immutable primitives: Bar, OHLCV, Series, and Dataset keep timezone-aware timestamps and Decimal precision for reproducible analytics.
  • Registry-driven indicators: ta.indicator("sma", ...) exposes schemas, enforces parameters, and can be extended at runtime with @ta.register.
  • Algebraic composition: indicator handles, literals, and sources build expression DAGs that support dependency inspection and streaming updates.
  • Deterministic alignment: align_series and availability masks make lookback requirements explicit and guard against silent truncation.
  • I/O and streaming utilities: ta.from_csv/ta.to_csv bridge datasets, while Stream tracks expression readiness for live feeds.

Requirements

  • Python 3.12 or newer
  • uv is recommended for environment management

Installation

uv pip install laakhay-ta

Quick Start

from datetime import UTC, datetime
from decimal import Decimal

import laakhay.ta as ta
from laakhay.ta import dataset
from laakhay.ta.core import OHLCV, align_series

ohlcv = OHLCV(
    timestamps=(
        datetime(2024, 1, 1, tzinfo=UTC),
        datetime(2024, 1, 2, tzinfo=UTC),
        datetime(2024, 1, 3, tzinfo=UTC),
        datetime(2024, 1, 4, tzinfo=UTC),
    ),
    opens=(Decimal("100"), Decimal("101"), Decimal("103"), Decimal("104")),
    highs=(Decimal("105"),) * 4,
    lows=(Decimal("99"),) * 4,
    closes=(Decimal("101"), Decimal("102"), Decimal("104"), Decimal("105")),
    volumes=(Decimal("1000"), Decimal("1100"), Decimal("1150"), Decimal("1200")),
    is_closed=(True,) * 4,
    symbol="BTCUSDT",
    timeframe="1h",
)

market = dataset(ohlcv)

sma_fast_handle = ta.indicator("sma", period=2)
sma_slow_handle = ta.indicator("sma", period=3)

sma_fast = sma_fast_handle(market)
sma_slow = sma_slow_handle(market)

fast, slow = align_series(
    sma_fast,
    sma_slow,
    how="inner",
    fill="none",
    symbol="BTCUSDT",
    timeframe="1h",
)
spread = fast - slow

print(spread.values)            # Decimal results
print(spread.availability_mask) # lookback readiness

Expression composition is available for analysis and tooling:

signal = sma_fast_handle - sma_slow_handle
print(signal.describe())
requirements = signal.requirements()

Inspect indicator metadata or register custom logic:

from laakhay.ta import SeriesContext, register

schema = ta.describe_indicator("sma")
print(schema.params)

@register("mid_price")
def mid_price(ctx: SeriesContext):
    return (ctx.high + ctx.low) / 2

Streaming and I/O

from datetime import UTC, datetime, timedelta

from laakhay.ta import ta
from laakhay.ta.core.bar import Bar
from laakhay.ta.stream import Stream

stream = Stream()
stream.register("sma2", ta.indicator("sma", period=2)._to_expression())

base = datetime(2024, 1, 1, tzinfo=UTC)
stream.update_ohlcv("BTCUSDT", "1h", Bar.from_raw(base, 100, 100, 100, 100, 1, True))
update = stream.update_ohlcv(
    "BTCUSDT",
    "1h",
    Bar.from_raw(base + timedelta(hours=1), 110, 110, 110, 110, 1, True),
)

print(update.transitions[0].value)  # Decimal('105')

CSV helpers round-trip datasets:

ohlcv = ta.from_csv("btc_1h.csv", symbol="BTCUSDT", timeframe="1h")
ta.to_csv(ohlcv, "btc_out.csv")

Development

git clone https://github.com/laakhay/ta
cd ta
uv sync --extra dev
uv run ruff check laakhay/
PYTHONPATH=$PWD uv run pytest tests/ -v --tb=short

License

MIT License

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

laakhay_ta-0.1.3.tar.gz (74.3 kB view details)

Uploaded Source

Built Distribution

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

laakhay_ta-0.1.3-py3-none-any.whl (106.0 kB view details)

Uploaded Python 3

File details

Details for the file laakhay_ta-0.1.3.tar.gz.

File metadata

  • Download URL: laakhay_ta-0.1.3.tar.gz
  • Upload date:
  • Size: 74.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.4

File hashes

Hashes for laakhay_ta-0.1.3.tar.gz
Algorithm Hash digest
SHA256 1597ab6b2506f5202b8c42bb02da90aac6827c56bb4b8775bffeaae8b3e734fc
MD5 fa623a035a026ed0114b29cc806cc8c6
BLAKE2b-256 0edbb42a5761f22f7b971ae0d729d0d0ac27e2f6ed2b88c58f678de8d5e6513a

See more details on using hashes here.

File details

Details for the file laakhay_ta-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: laakhay_ta-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 106.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.4

File hashes

Hashes for laakhay_ta-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 54ac97c596b86cc3cc0e8c1b8b52a2ef5ece43c07fd5db73cf75e57ca048c10e
MD5 a27611405b2e97b1b6aadb09cf204b0e
BLAKE2b-256 2f465af06bd256b651c3789a5a38ec4f05906d5e30f59eceeb2d9a15b95e100d

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