Skip to main content

Maintenance PyPI license PyPI pyversions

Time-Lagged Detrended Cross Correlation Analysis

This package allows to implement Detrended Cross Correlation Analysis [1] and its Time-Lagged version. Implementations are based on [1] and [2].

The code allows to easily calculate the Detrended Cross-Correlation Coefficient, which is a variation of the more famous Pearson's correlation coefficient, meant for cases in which the time series is non stationary. Indeed, in many domains, stationarity of a time series is not guaranteed and running traditional correlation coefficients can give skewed or untrue results.

Usage

The package allows to calculate the detrended version with both no time lag, or with a given time lag.

from dcca import detrended_correlation
from numpy.random import rand

x: ndarray = rand(100)
y: ndarray = rand(100)

print(detrended_correlation(x=x, y=y, time_scale=3, time_lag=0))
-0.04848682827863634

The time_lag coefficient is meant to confront the time series when one is moved with respect to the other. At the moment, only the time series y can be moved using this. To run the full cross-correlation analysis, one may want to loop over different time lags:

from dcca import detrended_correlation
from numpy.random import rand

x: ndarray = rand(100)
y: ndarray = rand(100)
time_lags: list[int] = range(0, 10)
dccas = [detrended_correlation(x=x, y=y, time_scale=3, time_lag=0) for time_lag in time_lags]

In the example provided, the coefficient is always going to be the same, since the arrays are randomly sampled.

The time_scale coefficient specifies the box size of the local detrending. In short, the Detrended Cross-Correlation Coefficient, in order to account for non-stationarity in the two series, calculates the correlation over smaller parts of the series (boxes), whose size is indeed given by the aforementioned parameter. For more detail, please look at the referenced material.

The package also allows to calculate the standard Pearson's correlation coefficient, even with different time lags. While the method can be easily implemented, I though it might be useful to provide it for confronttions.

from dcca.cross_correlation import cross_correlation
from numpy.random import rand
x: ndarray = rand(100)
y: ndarray = rand(100)

print(cross_correlation(x=x, y=y, time_lag=0))

Installation

At the moment, the packe is only installable via pip. For following releases, I will try to port it into conda as well.

pip install dcca

References

[1] Podobnik, Boris, and H. Eugene Stanley. "Detrended cross-correlation analysis: a new method for analyzing two nonstationary time series." Physical review letters 100.8 (2008): 084102.

[2] Shen, Chenhua. "Analysis of detrended time-lagged cross-correlation between two nonstationary time series." Physics Letters A 379.7 (2015): 680-687.

Contacts

For any information, contact me, Leonardo Alchieri, at leonardo@alchieri.eu. This package was developed as part of my PhD at USI (Università della Svizzera italiana), Switzerland.

Metadata

Release files for dcca 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dcca 0.3.0
File Size Uploaded Provenance Actions
dcca-0.3.0.tar.gz 17.9 kB Without provenance Details for dcca-0.3.0.tar.gz

Release files / dcca-0.3.0.tar.gz

Download URL dcca-0.3.0.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
af2b2770d4459c95a59d46e6d3caf1f00ca08ba57554b484d7b1a449b931c659
BLAKE2b-256 checksum
How to use checksums
8d3b16010899a10e049af812b3881e586b10b86a6c1d9bbd76a0353d9700f715
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Security for dcca 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page