Repository navigation
Conversation
The Net ROI column divided net P&L by avgEntry x quantity, ignoring the contract multiplier, so futures/options/forex/CFD returns were too large by the multiplier (x2 for MNQ, x100 for options). A zero notional showed 0.00% and a negative entry price showed 0%. - packages/core: netReturnOnNotional(), net P&L / (|avg entry| x qty x multiplier), null when a multiplier-priced trade has no multiplier or the notional is zero. Unit tests for futures, options, missing multiplier, equities/crypto, negative prices and zero notional. - /api/trades sends each row's contractMultiplier. - The Trades list and the trade page both use the helper, so the two figures always agree. Fixes LuxAlgo#34 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream LuxAlgo#39 fixed the same Net ROI bug with netReturnOnEntry (more guards and tests). Resolve the conflicts to upstream's helper and drop this branch's duplicate netReturnOnNotional and its test, keeping only the CHANGELOG entry, which upstream's fix did not add. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 #34.
What was wrong
The Trades list Net ROI column computed
netPnl / (avgEntry × quantity). It ignored the contract multiplier, which the list API did not even send. So futures, options, forex and CFD rows showed returns too large by exactly the multiplier (×2 for MNQ, ×100 for options). The trade page's Net / entry notional was already right, so the two disagreed. Two edge cases on the same line also misled: a zero notional showed0.00%, and a negative entry price showed0%.Change
packages/core: new pure functionnetReturnOnNotional(), next totradeRisk/tradeR. It returns net P&L ÷ (|avg entry| × quantity × multiplier). It returnsnull(rendered "–") when a multiplier-priced asset has no multiplier configured, or when the notional is zero. This follows the "analytics live in core" rule./api/trades: each row now carriescontractMultiplier(null when not configured).Tests
packages/core/tests/net-return.test.tscovers the multiplier for futures (MNQ ×2) and options (×100), "unknown" instead of a wrong number when a futures/option/forex/CFD trade has no multiplier, equities and crypto at one unit, a negative-priced spread, and a zero notional.Local gates:
pnpm typecheckpasses. The new tests pass. In the fullvitest run, 537/538 passed. The one failure wasreview-export.test.ts(the PDF builder), which timed out under heavy CPU load on my machine; it passes when re-run on its own, both on this branch and onmain. Prettier was run on every changed file.Verified in a running journal with MNQ futures and option spreads: the list now matches the trade page (e.g. 4 MNQ, +$283 → 0.11% instead of 0.23%; SPY put spread, −$1.30 → −0.53% instead of −52.63%).
🤖 Generated with Claude Code