Skip to main content

Time Series Functions

Below functions are used for time series analysis.

seriesPeriodDetectFFT

Finds the period of the given time series data using FFT FFT - Fast Fourier transform

Syntax

seriesPeriodDetectFFT(series);

Arguments

  • series - An array of numeric values

Returned value

  • A real value equal to the period of time series
  • Returns NAN when number of data points are less than four.

Type: Float64.

Examples

Query:

SELECT seriesPeriodDetectFFT([1, 4, 6, 1, 4, 6, 1, 4, 6, 1, 4, 6, 1, 4, 6, 1, 4, 6, 1, 4, 6]) AS print_0;

Result:

┌───────────print_0──────┐
│ 3 │
└────────────────────────┘
SELECT seriesPeriodDetectFFT(arrayMap(x -> abs((x % 6) - 3), range(1000))) AS print_0;

Result:

┌─print_0─┐
│ 6 │
└─────────┘

seriesDecomposeSTL

Decomposes a time series using STL (Seasonal-Trend Decomposition Procedure Based on Loess) into a season, a trend and a residual component.

Syntax

seriesDecomposeSTL(series, period);

Arguments

  • series - An array of numeric values
  • period - A positive integer

The number of data points in series should be at least twice the value of period.

Returned value

  • An array of three arrays where the first array include seasonal components, the second array - trend, and the third array - residue component.

Type: Array.

Examples

Query:

SELECT seriesDecomposeSTL([10.1, 20.45, 40.34, 10.1, 20.45, 40.34, 10.1, 20.45, 40.34, 10.1, 20.45, 40.34, 10.1, 20.45, 40.34, 10.1, 20.45, 40.34, 10.1, 20.45, 40.34, 10.1, 20.45, 40.34], 3) AS print_0;

Result:

┌───────────print_0──────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ [[
-13.529999, -3.1799996, 16.71, -13.53, -3.1799996, 16.71, -13.53, -3.1799996,
16.71, -13.530001, -3.18, 16.710001, -13.530001, -3.1800003, 16.710001, -13.530001,
-3.1800003, 16.710001, -13.530001, -3.1799994, 16.71, -13.529999, -3.1799994, 16.709997
],
[
23.63, 23.63, 23.630003, 23.630001, 23.630001, 23.630001, 23.630001, 23.630001,
23.630001, 23.630001, 23.630001, 23.63, 23.630001, 23.630001, 23.63, 23.630001,
23.630001, 23.63, 23.630001, 23.630001, 23.630001, 23.630001, 23.630001, 23.630003
],
[
0, 0.0000019073486, -0.0000019073486, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.0000019073486, 0,
0
]] │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘