Skip to content

v1.7.1: P&L, import and review fixes from a full audit - #50

Merged
simonro merged 3 commits into
mainfrom
fix/v1.7.1-audit
Nov 10, 2026
Merged

simonro merged 3 commits into
mainfrom
fix/v1.7.1-audit

Conversation

@simonro

@simonro simonro commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Why

A full audit of v1.7.0 found 12 bugs, 6 of which could show wrong P&L or other numbers. Every fix below has a regression test that fails on v1.7.0 and passes here. Four ChatGPT review passes on the fixes found 10 more edge cases, all fixed and tested.

Fixes

Import and grouping

  • Reversals: a single fill that flips the position (long 100, sell 200) used to make one open trade with $0 P&L. It is now split at zero. The split is redone when an earlier fill arrives in a later import, it survives an unchanged execution edit, and a re-import still recognises the original line.
  • Fractional shares: fills that add up to a closed position are a closed trade.
  • Option duplicates: duplicate detection includes the full option contract (expiry, strike, type, second strike), including the Thinkorswim cross-section match.
  • Later option fills: fills on an open single-leg option split into round trips. A fill joins an open vertical only when it is the same vertical.
  • Notes and tags: they follow their fills when a regroup renumbers trades. When two reviewed trades merge, both reviews are kept (every column).

Numbers

  • Manual trades: options and futures use the contract multiplier in the backend, the Add Trade preview, and Trade Details ROI and dollar risk. A manual exit at $0 is stored as a closing fill.
  • KPIs: profit factor uses net P&L on both sides. Open positions no longer count in win rate, expectancy or trade count (KPIs and the year view).

Other

  • Diary uploads: the date is validated, the server makes unique file names, and nothing can be written outside the uploads folder.
  • Stale data: Day Review reloads lifetime numbers when the account changes. Late responses no longer overwrite Day Review, Reports or a regenerated review.

Effect on the bundled samples

Sample v1.7.0 v1.7.1
Thinkorswim 4 trades, net $720.75 Same trades and net. Profit factor 10.70 becomes 10.52 (net instead of gross).
IBKR BABA and NVDA each one open trade at $0 BABA and NVDA reversals now show their real round trips (+$17.41, -$7.95, +$2.28). Win rate counts closed trades only.
Generic Identical

Tested

  • Backend: 366 passed (21 new in test_audit_fixes.py).
  • Frontend: 99 passed (6 new). The CI build compiles cleanly.
  • Every new test fails on the code before its fix.
  • A rebuilt trade that cannot be stored rolls the whole import back.
  • Stored trades are not rewritten. The README tells users how to correct an affected day (delete and re-import).

ChatGPT-reviewed (4 passes).

🤖 Generated with Claude Code

tapetoedge and others added 3 commits November 8, 2026 09:55
Import
- A fill that flips the position (long 100, sell 200) is split at zero: the long closes with its P&L
  and the short opens. The split is redone when an earlier fill arrives in a later import, survives
  an unchanged execution edit, and a re-import still recognises the original statement line.
- Fractional shares that add up to a closed position are a closed trade (tolerance everywhere,
  execution edits keep fractional size).
- Duplicate detection knows the option contract (expiry, strike, type, second strike), in the
  database fingerprints and in Thinkorswim's cash-balance / trade-history matching.
- Later fills on an open single-leg option are regrouped into round trips; a fill joins an open
  vertical only when it is the same vertical.
- Notes and tags follow their fills when a regroup renumbers trades; when two reviewed trades merge,
  both reviews are kept.

Numbers
- Manual option and futures trades use the contract multiplier (backend, Add Trade preview, Trade
  Details ROI and dollar risk). A manual exit at $0 is a closing fill.
- Profit factor uses net P&L on both sides; open positions no longer count in win rate, expectancy
  or trade count (KPIs and the year view).

Other
- Diary uploads: validated date, server-made unique file names, nothing outside the uploads folder.
- Day Review reloads lifetime numbers per account; late responses no longer overwrite Day Review,
  Reports or a regenerated review.

Every fix has a regression test that fails on v1.7.0 (backend/tests/test_audit_fixes.py, frontend
integration and TradeDetail tests). ChatGPT-reviewed (3 passes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e rebuild fails

- When a regroup scores which new trade inherits an old trade's notes, the two halves of a split
  reversal count as different fills, so notes on the short no longer move to the preceding long.
- If a rebuilt trade cannot be stored, the whole import is rolled back instead of leaving the
  trades it replaced deleted.

ChatGPT-reviewed (4th pass, on the private port).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonro
simonro merged commit 733717d into main Nov 10, 2026
3 checks passed
@simonro
simonro deleted the fix/v1.7.1-audit branch November 10, 2026 01:20
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.

2 participants