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:
- Segmentation: Breaking the time series into linear segments to reduce noise and dimensionality.
- Transform Invariance: Allowing each segment in the source series to be transformed (scaled and shifted) to match the target series.
- 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d299718aa2b3368cab07e282e658fb2fd65f3bc0fd5cc91ded15094c4832e340
|
|
| MD5 |
2f2480b376de6b8b5856ab8dd226d93d
|
|
| BLAKE2b-256 |
8b8ed009b0e614608945f12269774b569d8bf70e1354b5865e66911d757d4cb9
|
Provenance
The following attestation bundles were made for tisa_finance-0.2.2.tar.gz:
Publisher:
ci.yml on TheGameStopsNow/tisa-finance
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tisa_finance-0.2.2.tar.gz -
Subject digest:
d299718aa2b3368cab07e282e658fb2fd65f3bc0fd5cc91ded15094c4832e340 - Sigstore transparency entry: 724897850
- Sigstore integration time:
-
Permalink:
TheGameStopsNow/tisa-finance@41399a1073c8e5b41ce9b7e827881c14c5d0aca2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TheGameStopsNow
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@41399a1073c8e5b41ce9b7e827881c14c5d0aca2 -
Trigger Event:
workflow_dispatch
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
761277d8e3635e13aab4356b9bf103e96857dd26979f528b62a2ab461278541a
|
|
| MD5 |
0b25530ff8df2663e8351448c747b022
|
|
| BLAKE2b-256 |
beb90df06a19e87b44a692367772e5f5057e00a6d5c052226c4f36d78110c796
|
Provenance
The following attestation bundles were made for tisa_finance-0.2.2-py3-none-any.whl:
Publisher:
ci.yml on TheGameStopsNow/tisa-finance
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tisa_finance-0.2.2-py3-none-any.whl -
Subject digest:
761277d8e3635e13aab4356b9bf103e96857dd26979f528b62a2ab461278541a - Sigstore transparency entry: 724897851
- Sigstore integration time:
-
Permalink:
TheGameStopsNow/tisa-finance@41399a1073c8e5b41ce9b7e827881c14c5d0aca2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TheGameStopsNow
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@41399a1073c8e5b41ce9b7e827881c14c5d0aca2 -
Trigger Event:
workflow_dispatch
-
Statement type: