Repository navigation
Conversation
…illiquidity Signed-off-by: huuan26 <phanbuihuuan261103@gmail.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.



Summary
Fix close/volume index misalignment and
ValueError: operands could not be broadcast togethercrashes in_amihud_illiquiditywhenframe["close"]containsNaNor non-finite values, and handle zero-volume or non-positive traded-value bars cleanly without emitting runtime divide-by-zero warnings.Previously,
_amihud_illiquiditydropped missing entries fromcloseandvolumeindependently (close = _numeric_series(...)vs.volume = _numeric_series(...)). Whenever a bar had a valid volume and a missingclose(or trailingNaNclose at the end of a rolling cross-sectional window), taking the lastperiodelements from each vector misaligned timestamps or caused unequal-length broadcasting errors that could abort cross-factor correlation checks insideFactorResearchEngine.run.Changes
_amihud_illiquidity, coercecloseandvolumewith non-finite values mapped toNaN, filter both series through the samevalid_close = raw_close.notna().to_numpy()mask, alignprev_close,curr_close, andcurr_volumeon identical valid-close bar slices, computeabs_returns / np.where(traded_value > 0.0, traded_value, np.nan)undernp.errstate(divide="ignore", invalid="ignore"), and returnfloat("nan")if no finite daily ratio remains.test_amihud_illiquidity_aligns_close_and_volume_with_missing_or_zero_barscovering trailingNaNcloses, internalNaNcloses paired with distinct volumes, all-zero volumes, and insufficient valid closes (factor.insufficientHistory).test_factor_research_correlation_survives_nan_close_in_amihud_illiquidityregression test confirmingFactorResearchEngine.runretainsamihud_illiquidityinfactorCorrelationwhen a constituent has aNaNclose on a research date.Test plan
docker compose up -d --build(not run; pure unit/factor calculation fix)pytest tests/test_factor_registry.py tests/test_factor_research.py tests/test_qlib_factor_adapter.py -v(59 passed, 1 skipped;test_factor_research_builds_talib_081_panel_with_selected_parametersskipped locally because optionaltalibis not installed)coverage run --branch --include="app/services/factors/registry.py" -m pytest tests/test_factor_registry.py tests/test_factor_research.py -q(28 passed, 1 skipped; zero missed statements/branches in_amihud_illiquidity)ruff check app scripts tests,python -m py_compile run.py,python -m compileall -q app scripts testspython scripts/backend_quality_check.py,python scripts/check_requirements_lock.py,python scripts/check_docs.py,python scripts/check_version.py,python scripts/check_mojibake.pyAPI documentation (if routes/schemas changed)