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 the latest stable release from PyPI:

pip install twsca

Alternatively, install directly from GitHub for the latest development version:

pip install git+https://github.com/TheGameStopsNow/twsca.git

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.2.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.2-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file twsca-0.1.2.tar.gz.

File metadata

  • Download URL: twsca-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 48da0c5926ca7a1892c79a3b455eb4c3fbd15943aa590f8342df3300d7cfc555
MD5 a7f3ba226f4eef18f0e09fa47369bde8
BLAKE2b-256 d022ca82d40b82d94563c5ede7a9f8e45bf94f425970a3ac727be44f826667ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for twsca-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: twsca-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c354737178dd438bd2ca6ad9ea0cfcaaecadcb73e1bbb2aa9134fbcf51581e47
MD5 e3a0124d63faceada403c14872950661
BLAKE2b-256 dc3b22c31ef25a75f356bcb10e74c047e19df011b4a414d1afe04946d06ed2ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for twsca-0.1.2-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