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.2.tar.gz (58.0 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.2-py3-none-any.whl (82.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for laakhay_ta-0.1.2.tar.gz
Algorithm Hash digest
SHA256 374b96e887bf446aed975d684812931a3eb369ffb439211ee25de013aacc769a
MD5 4c46426ede8866856a4954070b55b993
BLAKE2b-256 9c42cbe3335225de849d62af25a78760510a90cd8eb4d319a2581c068bac5374

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for laakhay_ta-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8ea53414d402f293485f5a94c829821b6e16f5f080724c4a5eb781945f84f889
MD5 8bdeb30ce26c8144356fa68567cd0a21
BLAKE2b-256 28ee6dbf99af1e4673775492ab179572179422f23409669e05dc12c0f3b37d50

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