- Yang-Zhang Volatility is a sophisticated volatility estimator that combines overnight (close-to-open) returns with Rogers-Satchell intraday volatil...
Yang-Zhang Volatility is a sophisticated volatility estimator that combines overnight (close-to-open) returns with Rogers-Satchell intraday volatility to capture the full spectrum of price dynamics. Unlike simple close-to-close volatility that misses overnight gaps, or purely intraday measures that ignore opening moves, Yang-Zhang provides a theoretically unbiased estimate that remains consistent whether markets gap or drift.
## Historical Context
Introduced by Dennis Yang and Qiang Zhang in their 2000 paper "Drift-Independent Volatility Estimation Based on High, Low, Open, and Close Prices," this estimator addressed a fundamental gap in volatility measurement. Traditional close-to-close volatility understates true volatility when significant price movements occur outside trading hours. The Parkinson (1980) and Garman-Klass (1980) estimators used high-low information but assumed continuous trading with no overnight gaps.
2.**Open-to-close volatility** ($\sigma_c^2$): Captures standard intraday drift
3.**Rogers-Satchell volatility** ($\sigma_{RS}^2$): Captures intraday high-low range accounting for drift
The key innovation was deriving optimal weights that minimize variance while remaining independent of price drift. The resulting estimator is approximately 8× more efficient than close-to-close for capturing true volatility.
## Architecture & Physics
### 1. Log Return Components
For each bar, compute four log returns relative to the previous close and current open:
1.**First bar handling**: On the very first bar, there's no previous close. The implementation uses the current open as the "previous close" for this bar only, meaning $r_o = 0$ for bar 0.
2.**Warmup period**: YZV needs approximately `Period` bars before producing stable estimates. The bias-corrected RMA helps, but early values during warmup may still be less reliable.
3.**Negative variance guard**: Due to floating-point precision, the Rogers-Satchell component can theoretically go slightly negative in edge cases. The implementation guards against this by clamping variance to zero before taking the square root.
4.**Scale interpretation**: YZV output is in the same units as the log-return standard deviation (essentially a percentage in decimal form). A value of 0.02 means ~2% daily volatility.
5.**Parameter sensitivity**: The optimal $k$ weight depends on period. Don't reuse $k$ values calculated for different periods—the formula must be recomputed.
6.**Gap vs no-gap markets**: For instruments that trade 24/7 (crypto, forex), the overnight component may be less meaningful. Consider using only the Rogers-Satchell component for such markets.
## Trading Applications
### Volatility Forecasting
Yang-Zhang provides more accurate current volatility estimates, improving forecasts:
| **Parkinson** | Parkinson ignores gaps; YZV handles them |
| **Garman-Klass** | GK handles overnight but not as optimally weighted |
| **Rogers-Satchell** | RS is a component of YZV; doesn't handle gaps |
| **ATR** | ATR is absolute price-based; YZV is log-return based |
| **Historical Volatility** | YZV is a better HV estimator |
## Implementation Notes
### State Management
The indicator maintains a compact state record:
-`RawRma`: Running RMA value (before bias correction)
-`ECompensator`: Bias compensator $(1-\alpha)^n$
-`PrevClose`: Previous bar's close for overnight return
-`LastValidYzv`: Last valid output for NaN handling
-`Count`: Bar count for warmup tracking
-`HasPrevClose`: Flag for first-bar handling
### NaN/Infinity Handling
Invalid OHLC inputs are detected and the last valid YZV is substituted. This prevents NaN propagation through the RMA chain.
### Numerical Stability
The implementation uses:
- Epsilon guard (1e-10) for division safety in bias correction
- Clamping of variance to ≥ 0 before sqrt
- Last-valid substitution for non-finite results
## References
- Yang, D., & Zhang, Q. (2000). "Drift-Independent Volatility Estimation Based on High, Low, Open, and Close Prices." *Journal of Business*, 73(3), 477-491.
- Rogers, L. C. G., & Satchell, S. E. (1991). "Estimating Variance from High, Low and Closing Prices." *Annals of Applied Probability*, 1(4), 504-512.
- Parkinson, M. (1980). "The Extreme Value Method for Estimating the Variance of the Rate of Return." *Journal of Business*, 53(1), 61-65.