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.0.1.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.0.1-py3-none-any.whl (82.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for laakhay_ta-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a9afa86f495ba301a4256eae15eaaa2d58f823c7283279ae28c2205ff2faaa3f
MD5 67628c4f970be8cffefb66fcd172246c
BLAKE2b-256 88e342b8fc5bd4b4c4e386e7c6f697c0c7e0e67397e34e19738a1de87d9b630c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for laakhay_ta-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 62c7be254165a2f8416ad4a1cd6004e1512a8ce030bbe0463c37c3f637ee0695
MD5 18b1fa13750952f9f1f999ca3a8b7789
BLAKE2b-256 cb40d0a84a43c4674c5c3e3a2ed4ce60a897dcbf4196b5f2d55a0603a5b49fee

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