Add Yang Zhang Volatility (YZV) indicator#9389
Closed
claygeo wants to merge 3 commits intoQuantConnect:masterfrom
Closed
Add Yang Zhang Volatility (YZV) indicator#9389claygeo wants to merge 3 commits intoQuantConnect:masterfrom
claygeo wants to merge 3 commits intoQuantConnect:masterfrom
Conversation
Implements the Yang Zhang (2000) drift-independent volatility estimator, which combines overnight returns variance, intraday (close-to-open) returns variance, and Rogers-Satchell volatility using an optimal weighting factor k = 0.34 / (1.34 + (n+1)/(n-1)). This is the most efficient known estimator of historical volatility for financial time series, producing tighter estimates than close-to-close or Parkinson estimators with the same amount of data. Includes unit tests with reference data and hand-computed verification. Closes QuantConnect#8145
- Reject period < 2 (division by zero in k formula) - Guard against zero/negative prices (prevents NaN from Math.Log) - Guard against _previousClose <= 0 (prevents Infinity poisoning) - Remove unnecessary using directive
Adds tests for minimum period (2), flat market (zero returns), large overnight gap (20% gap up), invalid period throws, and reset-then-continue producing identical results.
Member
|
Closing for now until previous PR is approved and merged #9388 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the Yang Zhang (2000) drift-independent volatility estimator, the most efficient known estimator of historical volatility for financial time series. Closes #8145.
New indicator:
YangZhangVolatilitycombines three variance components with an optimal weighting factor:Files changed:
Indicators/YangZhangVolatility.cs— New indicator extendingBarIndicator, IIndicatorWarmUpPeriodProvider. Uses 5 internalSumsub-indicators for O(1) rolling computation. Guards zero/negative prices and uninitialized state.Algorithm/QCAlgorithm.Indicators.cs—YZV()helper method (same pattern asRSV())Tests/Indicators/YangZhangVolatilityTests.cs— ExtendsCommonIndicatorTests<IBaseDataBar>with hand-computed verification test (YzvComputesCorrectly)Tests/TestData/spy_with_yzv.csv— 500-row SPY reference data generated with independent Python implementationDesign decisions
_previousClose), computation starts on bar 2, IsReady at bar period+1.Math.Max(0m, yzVariance)before sqrt: Prevents NaN from floating-point rounding. MatchesVariance.csconvention.<= 0guards on all OHLC prices and_previousClose: PreventsMath.Logof zero/negative values producing Infinity/NaN.ArgumentOutOfRangeExceptionto prevent divide-by-zero in(period - 1).Test Coverage
All 8 code paths tested (100%):
Test plan
Plan Completion
13/13 plan items DONE (1 CHANGED:
<= 0guards instead of== 0). All files created, all specifications met.Reference
Yang, D. and Zhang, Q. (2000). "Drift Independent Volatility Estimation Based on High, Low, Open, and Close Prices." Journal of Business, 73(3), 477-491.