DocsMathStatisticsIQR (Interquartile Range)

IQR (Interquartile Range)

Windowed · default period 20Statistics

The Interquartile Range node computes Q3 − Q1 using linear interpolation within the rolling window. IQR is a robust spread measure that ignores the top and bottom 25% of values — making it insensitive to extreme outliers. It is the preferred spread measure when the distribution contains fat tails or outliers, which is common in financial data. Requires at least 4 non-null values.

Algorithm

  • Sort non-null window values ascending
  • Q1 = linear interpolation at the 25th percentile
  • Q3 = linear interpolation at the 75th percentile
  • IQR = Q3 − Q1
  • Requires ≥ 4 non-null values; returns null otherwise

Parameters

NameTypeDefaultDescription
periodnumber20Rolling window size. Minimum 4.

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

Outlier-Robust Volatility

Use IQR × 1.35 as a robust estimator of the standard deviation for fat-tailed return distributions where Stddev is inflated by occasional large moves.

Price Range Quality

Compare IQR of close prices to the full Range (Max − Min) to measure how much of the total price movement is in the central distribution vs. outlier spikes.

Regime Detection

Narrowing IQR indicates price compression; widening IQR indicates expanding volatility. Use as a Bollinger Band equivalent with outlier resilience.