Skip to main content

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 series
  • s2 (np.ndarray): Second time series
  • window_size (int, optional): Size of the sliding window for spectral analysis
  • dtw_radius (int, optional): Radius for DTW computation
  • normalize (bool, optional): Whether to normalize the input series

Returns:

  • dict: Dictionary containing:
    • time_domain_correlation: Correlation in time domain
    • spectral_correlation: Correlation in frequency domain
    • dtw_path: DTW alignment path
    • spectral_components: Spectral components of the analysis

Visualization

plot_twsca_results(result, title=None)

Plot TWSCA analysis results.

Parameters:

  • result (dict): Results from compute_twsca
  • title (str, optional): Plot title

Examples

See the examples directory for detailed examples:

  1. Basic Usage: examples/basic_usage.py
  2. Market Analysis: examples/market_analysis.py
  3. Signal Processing: examples/signal_processing.py

Development

Setup

  1. Clone the repository:
git clone https://github.com/TheGameStopsNow/twsca.git
cd twsca
  1. Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install development dependencies:
pip install -e ".[dev]"

Running Tests

pytest

Building Documentation

cd docs
make html

Contributing

  1. Fork the repository
  2. Create your feature branch: git checkout -b feature/my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin feature/my-new-feature
  5. 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

twsca-0.1.1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

twsca-0.1.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

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

Hashes for twsca-0.1.1.tar.gz
Algorithm Hash digest
SHA256 41d4891d6e593db323393a18228fa66247a3a898db0f03d2c246d6ccf81b662d
MD5 3d5f4dfa1ba26c0b12648976462eb1f1
BLAKE2b-256 aee76f2f3986b4d3b9cc94db106a229da07399871d5b5b477b6f9d938e6db31c

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on TheGameStopsNow/twsca

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

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

Hashes for twsca-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 366b1519b8402bbc69cabfaf4a9232a7402e017bdfe3f501ecdb1579fbc522f8
MD5 5428b66740dca761f407658d7c2b1c85
BLAKE2b-256 f573b81df73aeaf0079ea0a2a3d05f3fb5b13c8e2d243e10164b64df25d34f1f

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on TheGameStopsNow/twsca

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