Variance

Windowed · default period 20Statistics

The Variance node computes population variance over the rolling window: the mean of squared deviations from the mean. Variance is the foundation for standard deviation (apply Sqrt), Bollinger Bands, and all covariance-based measures. Using population variance (divides by n, not n−1) is consistent with the other nodes in the library.

Algorithm

  • μ = mean(non-null vals)
  • variance = Σ (v − μ)² / n
  • Returns null with fewer than 2 non-null values

Parameters

NameTypeDefaultDescription
periodnumber20Rolling window size.

Inputs & Outputs

PortTypeDescription
Inputs
inputnumber[]Source numeric array
Outputs
valuesnumber | nullComputed value at each bar; null before the warmup period completes
timestampsnumber[]Bar timestamps (UNIX ms), aligned 1-to-1 with values
Live mode: In live streaming mode the node updates only the last bar in-place rather than recalculating the full array, keeping CPU usage minimal during real-time data feeds.

Use Cases

Standard Deviation

Pipe Variance output into Sqrt to produce a rolling standard deviation series — the Bollinger Band width component. Use Average(input) ± multiplier × Sqrt(Variance(input)) for full Bollinger Bands.

Volatility Scaling

Divide a signal by Sqrt(Variance) to normalize it to unit variance — producing a Z-score-like series that adapts to changing volatility regimes.

Volatility Comparison

Compare rolling variance across different lookback periods (5, 20, 60 bars) to detect volatility term structure and distinguish short-term spikes from sustained regime shifts.