Skip to content

Fix Trades list Net ROI: apply the contract multiplier (#34) - #35

Open
on101094 wants to merge 2 commits into
LuxAlgo:mainfrom
on101094:fix/net-roi-contract-multiplier
Open

on101094 wants to merge 2 commits into
LuxAlgo:mainfrom
on101094:fix/net-roi-contract-multiplier

Conversation

@on101094

@on101094 on101094 commented Oct 4, 2026

Copy link
Copy Markdown

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 showed 0.00%, and a negative entry price showed 0%.

Change

  • packages/core: new pure function netReturnOnNotional(), next to tradeRisk/tradeR. It returns net P&L ÷ (|avg entry| × quantity × multiplier). It returns null (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 carries contractMultiplier (null when not configured).
  • Trades list and trade page both call the helper, so they always agree. A missing value sorts last instead of as 0.
  • CHANGELOG: entry under Unreleased → Fixed.

Tests

packages/core/tests/net-return.test.ts covers 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 typecheck passes. The new tests pass. In the full vitest run, 537/538 passed. The one failure was review-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 on main. 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

on101094 and others added 2 commits October 4, 2026 04:51
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>
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.

Trades list "Net ROI" ignores the contract multiplier (futures/options show ×multiplier returns)

1 participant