Skip to content

Conversation

@feedseawave
Copy link

@feedseawave feedseawave commented Dec 30, 2025

Description

This PR refactors the SoftTopkStrategy to address the non-deterministic weight allocation issue during portfolio rebalancing.

Motivation and Context

  • Fix Portfolio Overflow Logic: Addressed the issue where final_stock_weight was incorrectly handled when the number of held stocks exceeded topk (common when trade_impact_limit prevents immediate liquidation of old positions).
  • Priority-based Allocation: Implemented a "COMPLIANCE_FIRST" or "IMPACT_FIRST". budget logic.
  • Synchronization: Buy orders are now synchronized with the actual "freed budget" from sells, maintaining the target risk degree ($1 - \text{cash}$) more accurately.
  • Code Cleanup: Improved code readability by aligning comments and standardizing variable naming conventions

How Has This Been Tested?

  • Pass the test by running: pytest qlib/tests/test_all_pipeline.py under upper directory of qlib.
  • If you are adding a new feature, test on your own test scripts.

Screenshots of Test Results (if appropriate):

  1. Pipeline test:
  2. Your own tests:
image

Types of changes

  • Fix bugs
  • Add new feature
  • Update documentation

@feedseawave
Copy link
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.

1 participant