Skip to main content

Transform-Invariant Segment Alignment (TISA) for financial time series

Project description

TISA

Transform-Invariant Segment Alignment for financial time series

TISA is a novel algorithm for aligning and comparing financial time series in a way that is invariant to non-linear transformations (like different volatility regimes or trends) and robust to noise. It combines segmentation with dynamic programming to find the optimal alignment between two series.

Theory

Standard measures like Euclidean distance or Dynamic Time Warping (DTW) often fail on financial data because they are sensitive to amplitude scaling and noise. TISA addresses this by:

  1. Segmentation: Breaking the time series into linear segments to reduce noise and dimensionality.
  2. Transform Invariance: Allowing each segment in the source series to be transformed (scaled and shifted) to match the target series.
  3. Dynamic Programming: Finding the globally optimal sequence of segments and transforms that minimizes the alignment cost.

For more details, see the documentation.

Install

Requires Python 3.9+.

# Create a virtual environment
python3 -m venv .venv
source .venv/bin/activate

# Install TISA
pip install -U pip
pip install -e .[dev]

Optional: create a .env file with your Polygon.io API key for data fetching:

POLYGON_API_KEY=YOUR_KEY_HERE

Quick Start

Python API

import numpy as np
from tisa.distance import TISADistance

# Generate synthetic data
x = np.cumsum(np.random.randn(252))
y = x * 1.5 + 10  # Scaled and shifted version

# Compute distance
dist = TISADistance().pairwise(x, y)
print(f"TISA Distance: {dist:.4f}")

# Get detailed alignment info
detail = TISADistance().detailed(x, y)
print(f"Best Transform: {detail['best_transform']}")

CLI

Fetch data (auto-uses Polygon if POLYGON_API_KEY is present, else yfinance):

tisa fetch --tickers SPY,QQQ --interval 1d --start 2022-01-01 --end 2025-01-01 --source auto

Compute distance / alignment from CSV files:

tisa distance --fileA data/SPY_1d.csv --fileB data/QQQ_1d.csv
tisa align --fileA data/SPY_1d.csv --fileB data/QQQ_1d.csv --out reports/align_SPY_QQQ.json

Benchmarks

TISA comes with a benchmarking suite to evaluate performance against other metrics.

# Run daily benchmark
tisa bench --config tisa/benchmarks/multi_daily.yaml --out reports/benchmark_daily

See tisa/benchmarks/README.md for more info.

Performance Benchmarks

Track TISA performance over time using pytest-benchmark:

# Run performance benchmarks
pytest tisa/tests/test_performance.py --benchmark-only

# Compare with previous runs
pytest tisa/tests/test_performance.py --benchmark-compare

# Save baseline
pytest tisa/tests/test_performance.py --benchmark-save=baseline

Contributing

We welcome contributions! Please see CONTRIBUTING.md for details.

License

MIT

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

tisa_finance-0.2.2.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

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

tisa_finance-0.2.2-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

File details

Details for the file tisa_finance-0.2.2.tar.gz.

File metadata

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

File hashes

Hashes for tisa_finance-0.2.2.tar.gz
Algorithm Hash digest
SHA256 d299718aa2b3368cab07e282e658fb2fd65f3bc0fd5cc91ded15094c4832e340
MD5 2f2480b376de6b8b5856ab8dd226d93d
BLAKE2b-256 8b8ed009b0e614608945f12269774b569d8bf70e1354b5865e66911d757d4cb9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tisa_finance-0.2.2.tar.gz:

Publisher: ci.yml on TheGameStopsNow/tisa-finance

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

File details

Details for the file tisa_finance-0.2.2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for tisa_finance-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 761277d8e3635e13aab4356b9bf103e96857dd26979f528b62a2ab461278541a
MD5 0b25530ff8df2663e8351448c747b022
BLAKE2b-256 beb90df06a19e87b44a692367772e5f5057e00a6d5c052226c4f36d78110c796

See more details on using hashes here.

Provenance

The following attestation bundles were made for tisa_finance-0.2.2-py3-none-any.whl:

Publisher: ci.yml on TheGameStopsNow/tisa-finance

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