Skip to content

REF: Simplify the GARCH starting values and the constraint gradients - #1036

Merged
bashtage merged 3 commits into
mainfrom
wip-simplify-perf
Nov 19, 2026
Merged

bashtage merged 3 commits into
mainfrom
wip-simplify-perf

Conversation

@bashtage

@bashtage bashtage commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to #1029 and #1030.

Starting values (#1029). The deduplication of the candidate grid in GARCH.starting_values is kept, and the rest of the change is removed: _transformed_variance, _starting_value_loglikelihood, and the class check on compute_variance. Each candidate is again scored with _gaussian_loglikelihood, as before #1029. The deduplication now also covers p == 0. In that case alpha is unused, so GARCH(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, so argmax picks 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 of a, 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):

main this branch this branch without the constraint jac
fit + std_err, GARCH(1, 1), normal 22.8 ms 23.9 ms (+5%) 33.3 ms (+46%)
fit + std_err, GJR(1, 1, 1), t 45.8 ms 49.0 ms (+7%) 70.3 ms (+53%)
starting_values, GARCH(1, 1) 1.3 ms 1.9 ms
starting_values, GJR(1, 1, 1) 4.6 ms 7.2 ms
starting_values, GJR(0, 1, 1) 4.5 ms 1.9 ms (-58%)
  • The gain from PERF: Give SLSQP the exact gradient of the linear constraints #1030 is kept in full.
  • Removing the scoring path of PERF: Score each distinct GARCH starting value once #1029 costs 1.1 ms per GARCH(1, 1) fit (5%) and 3.2 ms per GJR fit (7%), of which starting_values accounts for 0.6 and 2.6 ms. That path skipped the argument checks of compute_variance (about 23 us of the 152 us per candidate) and the residual transform (about 15 us).
  • I also tried a single vector-valued constraint (a @ params - b with jac a), 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 public constraint() 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_candidates is 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_variance is removed with the path it tested.
  • The full-grid test of PERF: Score each distinct GARCH starting value once #1029 is unchanged and passes, including GJR(0, 1, 1).

🤖 Generated with Claude Code

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

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.50%. Comparing base (fd6fa53) to head (fbbc4e6).

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              
Flag Coverage Δ
adder 99.44% <100.00%> (-0.01%) ⬇️
subtractor 99.44% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bashtage
bashtage marked this pull request as ready for review November 19, 2026 09:35
@bashtage
bashtage merged commit d3e858f into main Nov 19, 2026
28 checks passed
@bashtage
bashtage deleted the wip-simplify-perf branch November 19, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant