Repository navigation
BUG: Debias the variance ratio for a known zero drift - #1043
Open
QuantIntellect wants to merge 1 commit into
Open
QuantIntellect wants to merge 1 commit into
QuantIntellect wants to merge 1 commit into
Conversation
With trend="n" the drift is known to be 0, but the debiased variance estimates still divided by nq - 1 and by Lo and MacKinlay's m, which correct for an estimated drift. Divide by nq and q(nq - q + 1), which make the estimates unbiased when the drift is known to be 0. The ratio was inflated by (nq - 1) / (nq - q), so the test rejected a random walk too often.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1043 +/- ##
=======================================
Coverage 99.50% 99.50%
=======================================
Files 154 154
Lines 34868 34886 +18
Branches 2639 2640 +1
=======================================
+ Hits 34694 34712 +18
Misses 98 98
Partials 76 76
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
With
trend="n"the drift is known to be 0 (mu = 0, unitroot.py L2161-L2162). The debiased variances, which are the default, still apply Lo and MacKinlay's corrections for an estimated drift: the one-period sum of squares is divided by nq − 1, and the q-period sum by m = q(nq − q + 1)(1 − q/nq) (L2179-L2182). Under the null, with the drift known to be 0, the two sums of squares have expected values nqσ² and q(nq − q + 1)σ², so the divisors that make the estimates unbiased are nq and q(nq − q + 1). As a result the ratio is inflated by exactly (nq − 1)/(nq − q). That is small whenlagsis much smaller than nq (1.004 for 1,000 increments andlags=5), but it is 1.10 for ten years of monthly data withlags=12.Under the null, with 5,000 Gaussian random walks without drift for each row:
trend="n"trend="c"trend="n"trend="c"On the same draws with this change,
trend="n"has mean ratios of 0.997, 1.011 and 1.012, and rejects 5.2%, 6.3% and 5.4% of the time, in line withtrend="c". With Gaussian increments the mean ratio is exactly 1 with this change, and exactly (nq − 1)/(nq − q) before it, so the remaining differences in the means are simulation noise.This goes back to when
VarianceRatiowas added (dce161d). The only test that checks the ratio's value withtrend="n",test_variance_ratio_no_constant, usesdebiased=False.Change
For
trend="n", the debiased variances divide by nq and q(nq − q + 1), sovr,statandpvaluechange fortrend="n"with the default arguments.trend="c",debiased=Falseandoverlap=Falseare unchanged. I left the extra observation thatdebiased=Truerequires in place, althoughtrend="n"no longer needs it.Tests
test_variance_ratio_no_constant_debiasedchecks the ratio against the formula.test_variance_ratio_debiased_centeredchecks, for each trend, that the mean ratio over 1,000 Gaussian random walks without drift is within 0.06 of 1. The"c"case passes on main too.The first test and the
"n"case of the second fail on main, and all of them pass with the change.pytest arch/tests -m "not slow"passes (31426 passed, 319 skipped), and ruff, black, isort and numpydoc are clean.