fix(backtests): prevent instant deals from blocking aggregation - #30
Merged
Conversation
Instant deals (start === end), produced by a stop-loss triggering in the same candle it opened (duration: null), were added to activeDeals during the open pass after the close pass for that time point had already run. Their end time point was never revisited, so they stayed "active" forever, permanently consuming a concurrency slot and blocking every later deal. Effect: with a low concurrency limit the aggregated P&L chart truncated to the date of the first instant deal (months early), totals were understated, and intrinsic concurrency was inflated. Their net was also silently dropped. Finalize instant deals immediately: count their P&L and win/loss, but never add them to activeDeals and never subject them to the concurrency limit. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Owner
Author
|
🎉 This PR is included in version 2.7.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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.
Проблема
В агрегации бектестов график P&L портфеля «не доходил до конца» — обрывался на месяцы раньше реального конца периода, а суммы занижались. Зависело от лимита одновременных позиций, хотя при числе бектестов меньше лимита блокировки быть не должно.
Причина
В
aggregateBacktestsMetricsна каждой временной точке сначала закрываются сделки (end === timePoint), потом открываются (start === timePoint). Сделка сstart === end(мгновенный стоп-лосс — buy и SL в одну минуту/свечу,duration: null) добавляется вactiveDealsуже после фазы закрытия этой точки. Еёendбольше никогда не встретится → она навсегда висит как открытая, занимая слот одновременности и блокируя все последующие сделки.Подтверждено на реальных данных (XRPUSDT + SOLUSDT): у SOL две такие сделки → при низком лимите график обрывался на ~2025-08, intrinsic concurrency раздувался с 1 до 3. P&L этих сделок при этом терялся.
Фикс
Мгновенные сделки (
end <= timePoint) финализируются сразу: учитываются в P&L и win/loss, но не кладутся вactiveDealsи не блокируются лимитом.Проверки
🤖 Generated with Claude Code