Fix TopkDropoutStrategy dynamic risk sizing#2281
Open
Kevin-Li-2025 wants to merge 1 commit into
Open
Conversation
Author
|
Quick follow-up on scope: this is intentionally a small fix for #2276. I added a focused regression test where |
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
Fixes #2276.
TopkDropoutStrategyexposesget_risk_degree(trade_step)so subclasses can implement dynamic market-timing / position-sizing logic, but the buy budget used the fixedself.risk_degreefield directly. This makes dynamic risk overrides ineffective for new buys.This PR routes the buy budget through
get_risk_degree(trade_step)and adds a focused regression test that keepsself.risk_degree = 0.95while overridingget_risk_degree()to return0.25; the generated buy order must use the dynamic 25% budget.Tests
PYTHONPYCACHEPREFIX=/private/tmp/qlib-pycache /usr/bin/python3 -m py_compile qlib/contrib/strategy/signal_strategy.py tests/backtest/test_topk_dropout_strategy.pygit diff --checkPYTHONPYCACHEPREFIX=/private/tmp/qlib-pycache /opt/homebrew/bin/python3.11 - <<'PY' ...isolated harness that stubs Qlib package-level imports, loadsqlib/contrib/strategy/signal_strategy.py, and verifies dynamic risk produces a 25-share order from 1000 cash at price 10Note: direct local
pytest -q tests/backtest/test_topk_dropout_strategy.pyis blocked in this unbuilt source tree by missing compiled extensions (qlib.data._libs.rolling). I attemptedsetup.py build_ext --inplace; this checkout lacks generated C++ sources and needs the project Cython build path first. The added test is a normal repository test and should run in CI after the extension build step.