Time-Warped Spectral Correlation Analysis for Financial Market Data
Project description
Time-Warped Spectral Correlation Analysis (TWSCA)
TWSCA is a Python package for analyzing correlations between time series that may be misaligned in time or have different speeds. It combines dynamic time warping (DTW) with spectral analysis to identify hidden relationships.
Features
- Dynamic Time Warping (DTW) for time series alignment
- Spectral analysis for frequency domain correlation
- Support for multiple time series comparison
- Visualization tools for correlation analysis
- Comprehensive test suite
- Type hints for better IDE support
Installation
# Install from GitHub
pip install git+https://github.com/TheGameStopsNow/twsca.git
# Or install with development dependencies
pip install -e "git+https://github.com/TheGameStopsNow/twsca.git#egg=twsca[dev]"
Quick Start
from twsca import compute_twsca
import numpy as np
# Example with sine waves
t = np.linspace(0, 10, 100)
s1 = np.sin(t)
s2 = np.sin(t + 1) # Phase-shifted version
# Compute TWSCA
result = compute_twsca(s1, s2)
print(f"Time-domain correlation: {result['time_domain_correlation']}")
print(f"Spectral correlation: {result['spectral_correlation']}")
API Reference
Core Functions
compute_twsca(s1, s2, **kwargs)
Compute Time-Warped Spectral Correlation Analysis between two time series.
Parameters:
s1(np.ndarray): First time seriess2(np.ndarray): Second time serieswindow_size(int, optional): Size of the sliding window for spectral analysisdtw_radius(int, optional): Radius for DTW computationnormalize(bool, optional): Whether to normalize the input series
Returns:
dict: Dictionary containing:time_domain_correlation: Correlation in time domainspectral_correlation: Correlation in frequency domaindtw_path: DTW alignment pathspectral_components: Spectral components of the analysis
Visualization
plot_twsca_results(result, title=None)
Plot TWSCA analysis results.
Parameters:
result(dict): Results fromcompute_twscatitle(str, optional): Plot title
Examples
See the examples directory for detailed examples:
- Basic Usage:
examples/basic_usage.py - Market Analysis:
examples/market_analysis.py - Signal Processing:
examples/signal_processing.py
Development
Setup
- Clone the repository:
git clone https://github.com/TheGameStopsNow/twsca.git
cd twsca
- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Install development dependencies:
pip install -e ".[dev]"
Running Tests
pytest
Building Documentation
cd docs
make html
Contributing
- Fork the repository
- Create your feature branch:
git checkout -b feature/my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin feature/my-new-feature - Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Citation
If you use TWSCA in your research, please cite:
@software{twsca2024,
author = {Dennis Nedry},
title = {TWSCA: Time-Warped Spectral Correlation Analysis},
year = {2024},
publisher = {GitHub},
url = {https://github.com/TheGameStopsNow/twsca}
}
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
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 twsca-0.1.1.tar.gz.
File metadata
- Download URL: twsca-0.1.1.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41d4891d6e593db323393a18228fa66247a3a898db0f03d2c246d6ccf81b662d
|
|
| MD5 |
3d5f4dfa1ba26c0b12648976462eb1f1
|
|
| BLAKE2b-256 |
aee76f2f3986b4d3b9cc94db106a229da07399871d5b5b477b6f9d938e6db31c
|
Provenance
The following attestation bundles were made for twsca-0.1.1.tar.gz:
Publisher:
publish.yml on TheGameStopsNow/twsca
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
twsca-0.1.1.tar.gz -
Subject digest:
41d4891d6e593db323393a18228fa66247a3a898db0f03d2c246d6ccf81b662d - Sigstore transparency entry: 196900197
- Sigstore integration time:
-
Permalink:
TheGameStopsNow/twsca@5574bddd09ebd4f7f9cfa3882d304e3fb89b6447 -
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:
publish.yml@5574bddd09ebd4f7f9cfa3882d304e3fb89b6447 -
Trigger Event:
push
-
Statement type:
File details
Details for the file twsca-0.1.1-py3-none-any.whl.
File metadata
- Download URL: twsca-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
366b1519b8402bbc69cabfaf4a9232a7402e017bdfe3f501ecdb1579fbc522f8
|
|
| MD5 |
5428b66740dca761f407658d7c2b1c85
|
|
| BLAKE2b-256 |
f573b81df73aeaf0079ea0a2a3d05f3fb5b13c8e2d243e10164b64df25d34f1f
|
Provenance
The following attestation bundles were made for twsca-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on TheGameStopsNow/twsca
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
twsca-0.1.1-py3-none-any.whl -
Subject digest:
366b1519b8402bbc69cabfaf4a9232a7402e017bdfe3f501ecdb1579fbc522f8 - Sigstore transparency entry: 196900203
- Sigstore integration time:
-
Permalink:
TheGameStopsNow/twsca@5574bddd09ebd4f7f9cfa3882d304e3fb89b6447 -
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:
publish.yml@5574bddd09ebd4f7f9cfa3882d304e3fb89b6447 -
Trigger Event:
push
-
Statement type: