An issue when calculating profit using TopkDropoutStrategy.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 48.7k
- Forks
- 7.7k
- PR merge metrics
- No merged PRs in 30d
Description
This is a potential issue when calculating profit. https://github.com/microsoft/qlib/blob/main/qlib/backtest/account.py#L194, when you calculate the total profit, you are using the price from last step(which is calculating the day profit), instead of the price where you place you order. Since you update the price after every step https://github.com/microsoft/qlib/blob/main/qlib/backtest/account.py#L245, so you actually overwrite the deal price always with the latest price.
e.g. say you place order at step 2, and close order at step 10, you actually get the profit from step 9 -10, instead of 2 - 10. Because you only calculate profit when you call https://github.com/microsoft/qlib/blob/main/qlib/backtest/executor.py#L604, but you update the price for holding stock for every step.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read qlib/backtest/account.py around lines 194 and 245, then trace the calculation from qlib/backtest/executor.py around line 604. Reproduce the step-2 entry and step-10 close scenario and verify whether profit uses the order price across the holding period. Done means the calculation reflects the entry-to-exit movement rather than only the final step, with regression coverage for this scenario.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- fintech-quant
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100