Volatility

Windowed · default period 20Statistics

The Volatility node computes the population standard deviation of period-over-period returns within the rolling window. Returns are computed as r[i] = (v[i] − v[i−1]) / |v[i−1]|. This is historical (realized) volatility — the standard input for volatility-targeting position sizing, ATR-alternative estimation, and regime classification between low-volatility compression and high-volatility expansion phases.

Algorithm

  • Compute returns: r[i] = (vals[i] − vals[i−1]) / |vals[i−1]| for non-zero vals[i−1]
  • Discard pairs where vals[i−1] === 0
  • volatility = population_std(returns)
  • Returns null with fewer than 2 valid return values

Parameters

NameTypeDefaultDescription
periodnumber20Rolling window size (produces period−1 returns).

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

Volatility Targeting

Compute target position size as (target_vol × equity) / (Volatility × √bars_per_year × price) to maintain constant realized volatility exposure across different market regimes.

Regime Classification

Low volatility (below 20th percentile of its own history) → compression regime, favor range-bound strategies. High volatility → expansion regime, favor breakout and momentum strategies.

Stop Distance Scaling

Set stop distance as a fixed multiple of Volatility × price rather than using ATR, ensuring stops are scaled to the actual return-based volatility of the asset.