Volatility
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
| Name | Type | Default | Description |
|---|---|---|---|
| period | number | 20 | Rolling window size (produces period−1 returns). |
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
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.