Merged
Conversation
- Fix SELL logic: correctly reduce position.quantity after selling (core bug) Previously positions were never decremented, causing sold positions to be settled again at backtest end, inflating final balance. - Fix settleRemainingPositions: profitLoss now correctly computes settlementValue - cost (was incorrectly using settlementValue.negate()) - Fix max drawdown calculation: use current balance instead of previous iteration's runningBalance - Frontend: add comment noting chart shows cash balance, not total equity
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.
Fixes #39
Changes
Backend (BacktestExecutionService.kt)
SELL logic fix (core bug): Position quantity is now correctly reduced after selling. Previously
position.quantitywas never decremented, causing already-sold positions to be settled again at backtest end, inflating final balance and creating 224+ duplicate SETTLEMENT records.settleRemainingPositions fix:
profitLossnow correctly computessettlementValue - costinstead ofsettlementValue.negate(). For closed settlements at avgPrice, this now correctly yields ~0 PnL.Max drawdown fix: Uses current trade's balance instead of the previous iteration's
runningBalance, preventing maxDrawdown from exceeding initial balance.Frontend (BacktestChart.tsx)
equityAfterfield in trade records (schema change).Testing