Repository navigation
fix: only require the selected indicator analysis weight column - #2403
Open
朱甲文(Jiawen Zhu) (andone-07) wants to merge 1 commit into
Open
朱甲文(Jiawen Zhu) (andone-07) wants to merge 1 commit into
朱甲文(Jiawen Zhu) (andone-07) wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change to method-specific weight-column selection in indicator analysis.
No open issues 🎉
What changed in this PR
Fixes indicator_analysis so each method reads only its required weight column, allowing unused optional columns to be absent or non-numeric.
Changes:
- Selects the weight column before evaluation, preserving absolute weighting for amount/value modes and order-count weighting for
meanandpos. - Documents the required
countcolumn and clarifiesmeanbehavior. - Adds regression coverage for weighting modes, minimal inputs, invalid methods, missing required columns, empty frames, and non-numeric unused columns.
| File | Description |
|---|---|
| tests/backtest/test_indicator_analysis.py | Adds regression tests for weight selection and input edge cases. |
| qlib/contrib/evaluate.py | Defers weight-column access until method selection and clarifies documentation. |
Review effort: Balanced
Author
|
@microsoft-github-policy-service agree |
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.
Description
Select the requested weight column before evaluating it in
indicator_analysis. Keep order-count weighting formeanandpos, and absolute weighting foramount_weightedandvalue_weighted. Document the requiredcountcolumn.Motivation and Context
The function documents
deal_amountandvalueas optional except in their respective weighted modes. Buildingweights_dictcurrently reads both columns and calls.abs()on them before selecting a method. Consequently, a valid mean-only input raisesKeyError: 'deal_amount'; either weighted mode also requires the unrelated weight column. Non-numeric unused columns can similarly raiseTypeError.For example,
pd.DataFrame({'ffr': [0.5, 1.0], 'pa': [0.02, -0.01], 'pos': [1.0, 0.0], 'count': [1, 3]})should returnffr=0.875,pa=-0.0025, andpos=0.25with the default method. The baseline raisesKeyErrorinstead.How Has This Been Tested?
python -m pytest tests/test_all_pipeline.py -q: 3 passed (221.81 seconds).tests/backtest/test_indicator_analysis.pyexercise all three methods with complete and minimal column sets, signed weights, the default method, invalid methods, missing required columns, empty frames, and non-numeric unused columns.On baseline
54355232463878d2eebb91fe0ee5fa7fa1f5976c, the regression tests report 9 failures and 12 passes. With the fix in an isolated Python 3.12.14 environment, all 21 pass. The backtest directory reports 25 passed and 1 skipped.pip check, flake8, changed-file Black, changed-module pylint, mypy and the documentation build pass.After preparing the same sample day-data and RL fixtures as the source CI workflow,
cd tests && python -m pytest . -m "not slow" --durations=20reports 712 passed, 1 skipped, 13 deselected (1022.78 seconds). The skip is the repository's explicitly disabled high-frequency backtest. Fullmake pylintalso passes for bothqlibandscripts(10.00/10).Validation scope: Linux, Python 3.12.14. Of the 13 deselected slow tests, the three pipeline tests passed separately; the other ten slow tests were not run. The repository Black/nbqa entrypoints are blocked by a sandbox multiprocessing socket restriction. Sequential Black API checks pass on all 350 source/test Python files, but this does not claim that notebook checks or the cross-platform CI matrix passed.
Types of changes
Prepared with AI assistance.