Skip to main content

LLM-oriented narration and compression for time series data

Project description

narrata

narrata turns OHLCV price series into compact, deterministic text summaries optimized for LLM context.

Installation

pip install narrata

Install optional backends:

pip install "narrata[all]"

Requires Python 3.11+ and pandas 2.0+.

Quickstart

narrate(...) takes a pandas OHLCV DataFrame with a datetime index.

In this example, df is an AAPL simulated OHLCV DataFrame that already exists in your pipeline.

Ticker is optional. Preferred pattern: pass ticker="AAPL" directly to narrate(...).

from narrata import narrate

# Assume `df` already exists and contains:
# - DatetimeIndex
# - Open, High, Low, Close, Volume columns
# Example source: AAPL simulated OHLCV data.
print(narrate(df, ticker="AAPL"))

Example output:

AAPL (120 pts, daily): ▁▁▂▂▂▃▃▄▄▄▄▅▆▆▆▆▇▇██
Date range: 2025-01-01 to 2025-04-30
Range: [$139.99, $175.68]  Mean: $157.35  Std: $10.33
Start: $140.00  End: $175.19  Change: +25.14%
Regime: Uptrend since 2025-01-02 (low volatility)
RSI(14): 65.1 (neutral-bullish)  MACD: bullish crossover 1 day ago
BB: near upper band
Volume: 0.98x 20-day avg (average)
Volatility: 23rd percentile (low)
SAX(16): aaabbccdeeffgggh
Patterns: Ascending triangle forming since 2025-03-02
Candlestick: Doji on 2025-04-29
Support: $145.13 (13 touches), $139.99 (6 touches)  Resistance: $175.68 (3 touches)

Fallback vs extras (same input)

Using the same deterministic 252-point dataset:

Fallback-only (pip install narrata):

AAPL (252 pts, business-daily): ▁▂▁▂▂▃▃▃▄▄▄▅▆▆▆▆▇▇▇█
Date range: 2024-01-02 to 2024-12-18
Range: [$140.61, $201.32]  Mean: $170.44  Std: $17.52
Start: $141.05  End: $201.32  Change: +42.73%
Regime: Uptrend since 2024-12-10 (low volatility)
RSI(14): 72.9 (overbought)  MACD: bullish crossover 7 days ago
BB: above upper band
SMA 50/200: golden cross
Volume: 0.95x 20-day avg (average)
Volatility: 1st percentile (extremely low)
SAX(16): aaabbcdeefggghhh
Patterns: Ascending triangle forming since 2024-09-26
Candlestick: Bullish Engulfing on 2024-12-17
Support: $193.16 (27 touches), $156.63 (26 touches)  Resistance: $201.32 (4 touches)

With extras (pip install "narrata[all]"):

AAPL (252 pts, business-daily): ▁▂▁▂▂▃▃▃▄▄▄▅▆▆▆▆▇▇▇█
Date range: 2024-01-02 to 2024-12-18
Range: [$140.61, $201.32]  Mean: $170.44  Std: $17.52
Start: $141.05  End: $201.32  Change: +42.73%
Regime: Uptrend since 2024-10-02 (low volatility)
RSI(14): 72.9 (overbought)  MACD: bullish crossover 7 days ago
BB: above upper band
SMA 50/200: golden cross
Volume: 0.95x 20-day avg (average)
Volatility: 1st percentile (extremely low)
SAX(16): aaabbbcddefggghh
Patterns: Ascending triangle forming since 2024-09-26
Candlestick: Doji on 2024-12-11
Support: $193.16 (27 touches), $156.63 (26 touches)  Resistance: $201.32 (4 touches)

Digit Splitting for LLM Robustness

digit_tokenize(...) can help when your downstream model is sensitive to dense numeric strings.

Use it when you have many prices, percentages, or long decimals in prompt context.

from narrata import digit_tokenize

print(digit_tokenize("Price 171.24, move +3.2%"))
# <digits-split>
# Price 1 7 1 . 2 4 , move + 3 . 2 %

Features

  • Input validation for OHLCV DataFrames
  • Summary analysis with date range context
  • Regime classification (Uptrend / Downtrend / Ranging)
  • RSI and MACD interpretation
  • Bollinger Band and moving average crossover descriptions
  • Volatility and volume context
  • SAX symbolic encoding
  • ASTRIDE adaptive symbolic encoding (with ruptures)
  • Pattern and candlestick detection
  • Support/resistance extraction
  • Sparkline generation
  • Output formatting (plain, markdown_kv, toon)

FAQ

Is narrata redundant if I already use OpenBB, yfinance, or another data SDK?

No. narrata is complementary. It sits on top of your data access layer and converts OHLCV data into concise, LLM-ready narrative text.

Does narrata call an LLM or provide LLM endpoints?

No. narrata is a pure Python library with deterministic, programmatic analysis and narration. It does not call LLM APIs.

Citation

If you use narrata in research or public projects, cite this package using CITATION.cff.

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

narrata-0.1.1.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

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

narrata-0.1.1-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

File details

Details for the file narrata-0.1.1.tar.gz.

File metadata

  • Download URL: narrata-0.1.1.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for narrata-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3b5e91a0f2ae6613a387ed202bf3560f5edd96f1b2dbe259a306da43da137c84
MD5 50d32ddd00ba664d67e909856c99b98d
BLAKE2b-256 e54fe5b4e48f848e4a6cde5a8e06f71b6f988d6186d66fa6a7fc939bcc928bd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for narrata-0.1.1.tar.gz:

Publisher: release.yml on marcinmiklitz/narrata

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file narrata-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: narrata-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 30.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for narrata-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 836e22eb0500ac2539bddaf6a88513c8af82269285f67ea1d364e860906fe905
MD5 fdb11b1aab76735eeafdf30888372f83
BLAKE2b-256 dcb59f7122a3b1d9deea98b438fe2b3bcc12856920158a087fca25bd6c7e9208

See more details on using hashes here.

Provenance

The following attestation bundles were made for narrata-0.1.1-py3-none-any.whl:

Publisher: release.yml on marcinmiklitz/narrata

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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