Repository navigation
REF: Simplify the GARCH starting values and the constraint gradients - #1036
Merged
Merged
Conversation
Keep the deduplication of the candidate grid from #1029 and remove the separate scoring path (_transformed_variance, _starting_value_loglikelihood and the class check on compute_variance). The starting values are bit-identical. Skipping the argument checks and the residual transform of compute_variance saved about 0.6 ms per GARCH(1, 1) fit and 2.6 ms per GJR fit.
alpha is unused without symmetric terms, so GARCH(p=0, o=1, q=1) scored 64 candidates, of which 16 are distinct. Use one value of alpha as well, which gives every distinct candidate in the order of the full grid, so the starting values are unchanged. Parametrize the test of the number of scored candidates over p, o and q.
Return the dictionary with the constraint and its gradient from a single factory, instead of one factory for each. The constraints are unchanged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1036 +/- ##
==========================================
- Coverage 99.50% 99.50% -0.01%
==========================================
Files 154 154
Lines 34897 34868 -29
Branches 2641 2639 -2
==========================================
- Hits 34723 34694 -29
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 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.
Follow-up to #1029 and #1030.
Starting values (#1029). The deduplication of the candidate grid in
GARCH.starting_valuesis kept, and the rest of the change is removed:_transformed_variance,_starting_value_loglikelihood, and the class check oncompute_variance. Each candidate is again scored with_gaussian_loglikelihood, as before #1029. The deduplication now also coversp == 0. In that case alpha is unused, soGARCH(p=0, o=1, q=1)scored 64 candidates of which only 16 are distinct, and now it scores those 16. One value of an unused coefficient gives every distinct candidate, in the order of the full grid, soargmaxpicks the same candidate.Constraint gradients (#1030).
constraint()builds each constraint with one factory that returns the dict with"fun"and"jac", instead of a factory for each. The return value is unchanged: one dict per row ofa, with the same functions.Results are unchanged. All 1,156 arrays I recorded are bit-identical to main: params, standard errors, log-likelihoods and starting values of 39 fits, plus 1,000 random starting-value searches. The 39 fits are 13 models (GARCH, GJR, GARCH(2, 2), GARCH(1, 0, 0), GJR(0, 1, 1), powers 1 and 1.5, ARCH(5), AR mean with t, zero mean with skew-t, GED, rescale) on three data sets each.
Timings (Windows, Python 3.14, compiled recursions, last 2,000 S&P 500 returns; 10th percentile of 160 timings over 8 alternated processes):
jacstarting_values, GARCH(1, 1)starting_values, GJR(1, 1, 1)starting_values, GJR(0, 1, 1)starting_valuesaccounts for 0.6 and 2.6 ms. That path skipped the argument checks ofcompute_variance(about 23 us of the 152 us per candidate) and the residual transform (about 15 us).a @ params - bwithjaca), which would be simpler still. It makes no difference for GARCH(1, 1) and makes GJR(1, 1, 1)-t fits 3-7% faster (16 timed processes). But it changes what the publicconstraint()returns (one dict instead of one per row), and it moves one of the 39 fits (GARCH(2, 2) on 500 days) by up to 4e-6 relative, because the matrix product rounds differently from the row dot products. It is not included.Tests.
test_garch_starting_values_score_distinct_candidatesis parametrized over GARCH(1, 0, 1), GJR(0, 1, 1), GJR(1, 1, 1), GARCH(2, 0, 2) and GARCH(1, 0, 0). It checks that each scored candidate is distinct and that there are 16, or 64 for GJR(1, 1, 1). The GJR(0, 1, 1) case fails on main (64 scored).test_garch_starting_values_use_overridden_compute_varianceis removed with the path it tested.🤖 Generated with Claude Code