The EWMA (Exponentially Weighted Moving Average) volatility estimator produces a real-time, per-second volatility estimate from streaming price ticks. It is the core input to the Black-Scholes probability model.
The EWMA estimator updates variance incrementally with each new tick:σt2=λ⋅σt−12+(1−λ)⋅Δtrt2Where:
λ = decay factor ∈ (0, 1) (default: 0.94)
r_t = log return between consecutive ticks
Δt = time delta between ticks (in seconds)
r_t² / Δt = normalized squared return (variance per second)
Decay Factor λ = 0.94: This gives approximately 94% weight to the previous variance and 6% weight to the new observation. Higher λ → smoother, slower adaptation. Lower λ → more reactive, noisier.
Crucial detail: we divide r² by Δt to express variance in per-second units:variance per second=Δtr2This ensures σ is directly compatible with the Black-Scholes formula, which expects time in seconds.
getVolatility() { if (!this._initialized) { return 0 } return Math.sqrt(this._variance)}getTickCount() { return this._tickCount}getMeanSigma() { if (this._sigmaHistory.length === 0) return 0 const sum = this._sigmaHistory.reduce((a, b) => a + b, 0) return sum / this._sigmaHistory.length}
getMeanSigma(): Used by the anomalous regime detector. If current volatility exceeds 3× the mean of the last 100 values, the engine abstains from predicting.
Time Delta Guard: Extremely small or zero Δt would cause r²/Δt to explode. The 1ms floor prevents division-by-near-zero while still being negligible for typical tick intervals (100ms - 1s).
Simple moving average (SMA) gives equal weight to all observations in the window:σSMA2=N1i=1∑Nri2EWMA gives exponentially decaying weight to older observations:σEWMA2=(1−λ)i=0∑∞λirt−i2Benefits:
Memory efficiency: O(1) state (no tick buffer required)
Recency bias: Recent volatility matters more than ancient history
The “effective” lookback period for λ = 0.94:Neff=1−λ2−1=0.062−1≈32 ticksThis means the estimator “forgets” 95% of a tick’s influence after ~32 subsequent ticks.
The Black-Scholes formula expects time remaining in seconds and volatility in matching units:d2=σTln(S/K)+(r−2σ2)TIf T is in seconds, σ must be per-second volatility.
If you prefer annualized volatility (common in finance):σannual=σper-second×31536000Where 31,536,000 = seconds per year.For hourly volatility:σhourly=σper-second×3600
Unit Consistency: The engine uses per-second units throughout. If you modify the time scale, you must adjust both the volatility estimator and the Black-Scholes inputs.
The decay factor controls the trade-off between stability and responsiveness:
λ
Effective Window
Behavior
0.90
~19 ticks
Very reactive, noisy
0.94
~32 ticks
Default — balanced
0.97
~65 ticks
Smooth, slow adaptation
0.99
~199 ticks
Very stable, insensitive to shocks
Empirical Tuning: λ = 0.94 was selected through backtesting on Polymarket tick data. For markets with different microstructure (e.g., high-frequency vs. low-frequency ticks), you may need to re-calibrate.
When to reset: Only reset volatility on market close or context switch. The engine’s resetMomentum() method preserves volatility state across interval boundaries, allowing the EWMA to accumulate long-term regime information.
GARCH (Generalized Autoregressive Conditional Heteroskedasticity) is a more sophisticated volatility model:σt2=ω+αrt−12+βσt−12EWMA is a special case of GARCH(1,1) with:
ω = 0 (no long-term mean reversion)
α = 1 - λ
β = λ
GARCH offers mean-reversion to a long-run variance level, but requires more complex parameter estimation. EWMA is simpler and suffices for short-lived prediction markets.
The λ = 0.94 default comes from J.P. Morgan’s RiskMetrics™ methodology (1996), which popularized EWMA for daily returns. For intraday tick data, the optimal λ may differ.
An alternative to EWMA is realized volatility (sum of squared returns over a fixed window):σRV2=i=1∑Nri2This is unbiased but requires storing all returns in the window (O(N) memory vs. O(1) for EWMA).
J.P. Morgan (1996). RiskMetrics™ Technical Document (4th ed.).
Tsay, R. S. (2010). Analysis of Financial Time Series (3rd ed.). Wiley.
Engle, R. F. (1982). “Autoregressive Conditional Heteroscedasticity with Estimates of the Variance of United Kingdom Inflation.” Econometrica, 50(4), 987-1007.