series_seasonal()

Calculates the seasonal component of a series, according to the detected or given seasonal period.

Syntax

series_seasonal(series [, period ])

Learn more about syntax conventions.

Parameters

Name Type Required Description
series dynamic ✔️ An array of numeric values.
period int The number of bins for each seasonal period. This value can be any positive integer. By default, the value is set to -1, which automatically detects the period using the series_periods_detect() with a threshold of 0.7. If seasonality is not detected, the function returns zeros. If a different value is set, it ignores seasonality and returns a series of zeros.

Returns

A dynamic array of the same length as the series input that contains the calculated seasonal component of the series. The seasonal component is calculated as the median of all the values that correspond to the location of the bin, across the periods.

Examples

Auto detect the period

In the following example, the series' period is automatically detected. The first series' period is detected to be six bins and the second five bins. The third series' period is too short to be detected and returns a series of zeroes. See the next example on how to force the period.

print s=dynamic([2, 5, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1])
| union (print s=dynamic([8, 12, 14, 12, 10, 10, 12, 14, 12, 10, 10, 12, 14, 12, 10, 10, 12, 14, 12, 10]))
| union (print s=dynamic([1, 3, 5, 2, 4, 6, 1, 3, 5, 2, 4, 6]))
| extend s_seasonal = series_seasonal(s)

Output

s s_seasonal
[2,5,3,4,3,2,1,2,3,4,3,2,1,2,3,4,3,2,1,2,3,4,3,2,1] [1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0,3.0,2.0,1.0]
[8,12,14,12,10,10,12,14,12,10,10,12,14,12,10,10,12,14,12,10] [10.0,12.0,14.0,12.0,10.0,10.0,12.0,14.0,12.0,10.0,10.0,12.0,14.0,12.0,10.0,10.0,12.0,14.0,12.0,10.0]
[1,3,5,2,4,6,1,3,5,2,4,6] [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]

Force a period

In this example, the series' period is too short to be detected by series_periods_detect(), so we explicitly force the period to get the seasonal pattern.

print s=dynamic([1, 3, 5, 1, 3, 5, 2, 4, 6]) 
| union (print s=dynamic([1, 3, 5, 2, 4, 6, 1, 3, 5, 2, 4, 6]))
| extend s_seasonal = series_seasonal(s, 3)

Output

s s_seasonal
[1,3,5,1,3,5,2,4,6] [1.0,3.0,5.0,1.0,3.0,5.0,1.0,3.0,5.0]
[1,3,5,2,4,6,1,3,5,2,4,6] [1.5,3.5,5.5,1.5,3.5,5.5,1.5,3.5,5.5,1.5,3.5,5.5]