DeTime: time-series decomposition in Python
DeTime is an open-source Python toolkit for separating time series into trend, seasonal or oscillatory components, and residuals. I develop it as part of my research on temporal representation.
Use one Python or command-line interface to work with individual signals or aligned channels, compare decomposition methods, and inspect the resulting components and metadata.
Install DeTime
The project is called DeTime, sometimes written De-Time. Its PyPI distribution is detime-toolkit; the Python import is detime.
python -m pip install detime-toolkit
This small example uses singular spectrum analysis (SSA) on a synthetic series with a trend and a repeating cycle:
import numpy as np
from detime import DecompositionConfig, decompose
t = np.arange(120, dtype=float)
series = 0.03 * t + np.sin(2 * np.pi * t / 12)
result = decompose(
series,
DecompositionConfig(
method="SSA",
params={"window": 24, "rank": 6, "primary_period": 12},
),
)
print(result.trend.shape) # (120,)
print(result.season.shape)
print(result.residual.shape)
The installation guide covers optional dependencies. The quickstart also shows CLI usage and multichannel input.
Choose a decomposition method
The choice depends on the structure you expect in the data. A useful starting point is to compare a small number of methods on the same signal and inspect their residuals.
- One series with components to explore: start with SSA. Its window and rank control the subspace representation.
- A known seasonal period: consider STD, STDR for noisier cycles or outliers, or an STL baseline. Check that the period matches the sampling frequency.
- Aligned channels with shared structure: use MSSA to study them together. Unrelated channels may be better handled separately.
- A specialist comparison: consult the wrappers for VMD, EMD, wavelets and related methods. Dependencies and backend support differ across methods.
See the method selection guide for parameters and limitations, or the cross-package comparison for how DeTime fits alongside other tools.
Time-series decomposition for quant research
The quant tutorials explore features built from trends, oscillations and residuals. The examples cover trend following, mean reversion, pairs and portfolio workflows.
For historical trading experiments, a decomposition of the full price series can leak future information into earlier features. Recompute on each available training window, use the last feature row, delay execution and account for turnover costs.
- Quant research tutorial overview: choose a workflow and understand the shared feature pipeline.
- Walk-forward validation: check window boundaries, execution timing and cost assumptions.
- Executable quant tutorial notebooks: follow the individual examples and inspect their outputs.
These are research examples. A decomposition component or an attractive backtest alone does not establish predictive value.
Developing DeTime
My broader interest is how we represent and understand temporal data. DeTime provides a common software interface for studying decompositions and using their components in downstream experiments.
If you encounter a problem or have a reproducible example to contribute, use the GitHub issue tracker. Include the method, parameters and a small input that reproduces the behavior.