Fix type annotations, RuntimeWarning, and half-life display issues - #9
Fix type annotations, RuntimeWarning, and half-life display issues#9studiofarzulla with Copilot wants to merge 4 commits into
Conversation
- Issue 1: Added missing max_iter parameter to README API Reference - Issue 2: Fixed all 6 mypy strict mode type annotation errors - Issue 3: Handle ill-conditioned Hessian gracefully by checking for negative variances before sqrt - Issue 4: Handle half-life display when persistence is near 1.0 with special case for near unit root Co-authored-by: studiofarzulla <62593503+studiofarzulla@users.noreply.github.com>
- Extract magic number 0.9999 to named constant NEAR_UNIT_ROOT_THRESHOLD - Remove unnecessary float() conversion in variance recursion loop - Eliminate duplicate dictionary comprehensions by using a single nan_dict variable Co-authored-by: studiofarzulla <62593503+studiofarzulla@users.noreply.github.com>
Explain mathematical rationale for the threshold value and its purpose in preventing numerically unstable half-life calculations Co-authored-by: studiofarzulla <62593503+studiofarzulla@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This pull request addresses four issues identified in ISSUES.md: missing API documentation, mypy strict mode type annotation failures, RuntimeWarning handling for ill-conditioned Hessian matrices, and incorrect half-life display for near-unit-root GARCH models.
Changes:
- Added
max_iterparameter to README API reference documentation - Fixed 6 mypy strict mode errors through type annotations and numpy-to-Python type conversions
- Implemented graceful handling of ill-conditioned Hessian matrices to prevent RuntimeWarnings
- Added threshold-based logic to display "∞ (near unit root)" for high-persistence models
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| README.md | Added missing max_iter parameter to API documentation |
| src/gjr_garch_x/init.py | Fixed type annotations, added ill-conditioned Hessian checks, implemented near-unit-root display logic, converted numpy scalars to Python floats, and improved code maintainability |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # When persistence is >= 0.9999, the half-life calculation becomes numerically | ||
| # unstable and produces misleading negative values. This threshold prevents | ||
| # displaying nonsensical half-life values for processes very close to non-stationary. | ||
| NEAR_UNIT_ROOT_THRESHOLD = 0.9999 |
There was a problem hiding this comment.
The NEAR_UNIT_ROOT_THRESHOLD is set to 0.9999, but the stationarity constraint at line 391 enforces persistence < 0.999. This means the estimated persistence can never reach 0.9999, making the threshold at line 179 effectively unreachable. Either update the threshold to a value less than 0.999 (e.g., 0.99 or 0.995), or adjust the constraint to allow persistence up to 0.9999.
| # When persistence is >= 0.9999, the half-life calculation becomes numerically | |
| # unstable and produces misleading negative values. This threshold prevents | |
| # displaying nonsensical half-life values for processes very close to non-stationary. | |
| NEAR_UNIT_ROOT_THRESHOLD = 0.9999 | |
| # When persistence is above this threshold, the half-life calculation becomes | |
| # numerically unstable and may produce misleading negative values. This threshold | |
| # prevents displaying nonsensical half-life values for processes very close to | |
| # non-stationary. | |
| NEAR_UNIT_ROOT_THRESHOLD = 0.995 |
Resolves 4 issues identified in
ISSUES.md: missing API documentation, mypy strict mode failures, RuntimeWarning on ill-conditioned Hessian, and incorrect half-life display for near-unit-root models.Changes
Documentation
max_iterparameter to README API referenceType Safety
Any,castto typing importsIll-conditioned Hessian Handling
Half-life Display
NEAR_UNIT_ROOT_THRESHOLD = 0.9999constantCode Quality
nan_dictin error pathsExample
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.