ENH: Add PreWhitenedRecolored (VAR-HAC and PWRC) long-run covariance - #874
Open
WatchTree-19 wants to merge 4 commits into
Open
WatchTree-19 wants to merge 4 commits into
WatchTree-19 wants to merge 4 commits into
Conversation
Files from the varhac branch (6b1cc78) as of April 2020.
… long run Port arch.covariance.var to current main: arch._typing, functools.cached_property, arch.vendor._decorators.Appender and modern type hints. Add a ZeroLag kernel used for VAR-HAC (kernel=None). ZeroLag is not added to KERNELS so the kernel names accepted by arch.unitroot are unchanged. Kernel names are normalized in the same way as arch.unitroot._shared._check_kernel. Recolor the kernel long-run covariance of the VAR residuals, D Omega_e D', as in Andrews & Monahan (1992). The previous code recolored the residual short-run covariance, so the kernel and bandwidth had no effect on the long run. Add a regression test that computes the recolored long run directly for positive bandwidths. Document the prewhitening, lag selection, kernel and recoloring steps and what each returned covariance contains, add examples, register the covariance_data fixture and add the VAR-based estimators to the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #874 +/- ##
==========================================
+ Coverage 99.54% 99.56% +0.01%
==========================================
Files 78 81 +3
Lines 15847 16364 +517
Branches 1296 1358 +62
==========================================
+ Hits 15775 16292 +517
Misses 38 38
Partials 34 34
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:
|
Adds tests for kernel=None against a direct D Sigma_e D' computation, the ZeroLag kernel, the bandwidth check when kernel is None, the error raised for a nonstationary VAR, and sample_autocov without centering.
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.
This picks up #363 and the
varhacbranch, the VAR-HAC and pre-whitened recolored items on the roadmap in #351. The first commit is your 2020var.py,test_var.pyandcovariance_data.pyexactly as they were on the branch, so the history shows where it came from. The second ports it to current main and fixes the recoloring step.Port:
arch._typing,functools.cached_property,arch.vendor._decorators.Appender, current type hints,np.intin the tests.ZeroLagadded tokernel.pyforkernel=None, but kept out ofKERNELS, so the kernel list used byarch.unitrootis unchanged.var.pybuilds its own name lookup fromarch.covariance.kernel, normalised the same way as_check_kernel, so there is no import fromarch.unitroot.arch/conftest.py, the debugto_csvincovariance_data.pyis removed, and the "Vector AR-based Estimators" section is in the docs. The Notes TODO is replaced and there is a runnable example.Fix:
covrecoloredkern_cov.short_run, so the kernel and bandwidth had no effect on the long run. It now recolors the kernel long run of the VAR residuals,D @ Omega_e @ D.T, keeping yourT / (T - N)scale. Withbandwidth=0orkernel=Nonenothing changes, which is why the existing tests passed. For a 3-series VAR(3) sample withlags=2, QuadraticSpectral and bandwidth 7.5, the [0, 0] element was 159.64 against 120.49 from a direct computation.Tests:
test_recolored_kernel_long_runfits the VAR withlstsq, runs the kernel on the residuals and recolors, over all kernels, two bandwidths andcenter. 576 cases fail before the fix and pass after.arch/tests/covarianceandarch/tests/unitrootpass (5783 passed, 2 skipped).black,isortandruffare clean.Cross-check with R
sandwich(univariate, VAR(1) prewhitening, Bartlett,adjust=FALSE,sandwich=FALSE): identical to about 1e-14 once R's bandwidth is taken as arch's plus one and the scale is converted (arch equals R times n/(n-2) here).A few things I left as they were and would value your view on:
short_runis the residual covariance rather than the covariance of x, solong_run = short_run + oss + oss'does not hold even at bandwidth 0.long_run. They are documented as such for now.bandwidthreports the value computed on x, while the kernel runs on the residuals.df_adjustis accepted but the kernel is built withdf_adjust=0and the fixedT / (T - N)scale is used.Happy to change any of these whichever way you prefer.