Skip to content

fix: only require the selected indicator analysis weight column - #2403

Open
朱甲文(Jiawen Zhu) (andone-07) wants to merge 1 commit into
microsoft:mainfrom
andone-07:fix/indicator-analysis-selected-weight
Open

朱甲文(Jiawen Zhu) (andone-07) wants to merge 1 commit into
microsoft:mainfrom
andone-07:fix/indicator-analysis-selected-weight

Conversation

@andone-07

@andone-07 朱甲文(Jiawen Zhu) (andone-07) commented Nov 15, 2026 •

Copy link
Copy Markdown

Description

Select the requested weight column before evaluating it in indicator_analysis. Keep order-count weighting for mean and pos, and absolute weighting for amount_weighted and value_weighted. Document the required count column.

Motivation and Context

The function documents deal_amount and value as optional except in their respective weighted modes. Building weights_dict currently reads both columns and calls .abs() on them before selecting a method. Consequently, a valid mean-only input raises KeyError: 'deal_amount'; either weighted mode also requires the unrelated weight column. Non-numeric unused columns can similarly raise TypeError.

For example, pd.DataFrame({'ffr': [0.5, 1.0], 'pa': [0.02, -0.01], 'pos': [1.0, 0.0], 'count': [1, 3]}) should return ffr=0.875, pa=-0.0025, and pos=0.25 with the default method. The baseline raises KeyError instead.

How Has This Been Tested?

  • python -m pytest tests/test_all_pipeline.py -q: 3 passed (221.81 seconds).
  • Regression tests under tests/backtest/test_indicator_analysis.py exercise 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=20 reports 712 passed, 1 skipped, 13 deselected (1022.78 seconds). The skip is the repository's explicitly disabled high-frequency backtest. Full make pylint also passes for both qlib and scripts (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

  • Fix bugs
  • Add new feature
  • Update documentation

Prepared with AI assistance.

Copilot AI balanced review requested due to automatic review settings November 15, 2026 08:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 mean and pos.
  • Documents the required count column and clarifies mean behavior.
  • 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

@andone-07

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

2 participants