DocsUtilityPartition Fn

Partition Fn

TransformUtility

Partition Fn divides the input series into consecutive, non-overlapping blocks of a fixed number of bars and applies a statistical function to each block. The result is a sparse series with one value per block, stamped at either the first or last bar of each block.

Algorithm

// For each non-overlapping block b:

blockStart=b × period
blockEnd=min(blockStart + period − 1, len − 1)
result[b]=fn(input[blockStart .. blockEnd])
timestamp[b]=anchor === 'first' ? ts[blockStart] : ts[blockEnd]
Partition Fn vs Rolling Fn: Rolling Fn moves one bar at a time (overlapping windows), giving a value at every bar. Partition Fn uses non-overlapping blocks, giving one value per period bars. Partition Fn is better for periodic summaries (e.g. weekly stats on daily data).

Parameters

NameTypeDefaultDescription
funcWinFuncType'max'Statistical function to apply to each block. See the full list below.
periodnumber20Number of bars per block. Must be ≥ 1. The last block may be smaller if the total bar count is not evenly divisible.
anchor'last' | 'first''last'Which bar's timestamp to stamp the result on. 'last' aligns with the end of each block; 'first' with the start.

Supported Functions

max / minHighest or lowest value in the block.
average / medianMean or median of the block.
sum / countTotal or count of non-null values.
std / varianceSample standard deviation or variance.
rangemax − min within the block.
q1 / q3 / iqrQuartiles and interquartile range.
mad / cv / rmsMean absolute deviation, coefficient of variation, root-mean-square.
slope / intercept / r_squaredLinear regression statistics over the block.
momentum / accelerationLast − first, and change in slope.
gain / lossTotal positive or total negative change in the block.
sharpe / sortinoRisk-adjusted return statistics.
skewness / kurtosisDistribution shape statistics.
argmax / argminIndex (within block) of max/min value.
max_drawdownPeak-to-trough drawdown within the block.
volatilityAnnualised volatility of the block.
entropy / autocorrShannon entropy and lag-1 autocorrelation.
rsiRelative Strength Index over the block.

Inputs & Outputs

PortTypeDescription
Input
input(number | null)[]Any numeric series with matching timestamps.
Outputs
values(number | null)[]One value per block (sparse). Null if the block contains no non-null inputs.
timestampsnumber[]One timestamp per block, placed at the anchor bar of each block.
funcWinFuncTypeActive function name (mirrored for display).

Use Cases

Weekly high/low on daily data

Set period = 5 and func = max on a daily close series. The result gives the highest close of each 5-bar week, stamped at the last bar of the week — a clean weekly high marker.

Periodic volatility regime

Use func = std and period = 20 to compute volatility for each non-overlapping 20-bar block. Compare consecutive blocks to detect whether volatility is expanding or contracting.