Variance
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
| Name | Type | Default | Description |
|---|---|---|---|
| period | number | 20 | Rolling window size. |
Inputs & Outputs
| Port | Type | Description |
|---|---|---|
| Inputs | ||
| input | number[] | Source numeric array |
| Outputs | ||
| values | number | null | Computed value at each bar; null before the warmup period completes |
| timestamps | number[] | Bar timestamps (UNIX ms), aligned 1-to-1 with values |
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.