P&L analysis

The P&L Analysis page (/app/journal/analysis) is Journal's main screen โ your entire trade history with realised P&L, unrealised P&L, and corporate-action-adjusted round trips.
What you see
- Summary cards โ total realised, unrealised (on open positions), invested capital, total P&L
- Per-symbol breakdown โ every symbol you've traded with its realised P&L, open position (if any), win/loss ratio
- Segment filter โ EQ / F&O / All
- Time period filter โ monthly, yearly, all-time
How the P&L engine works
Journal's P&L is computed by _pair_trades โ a FIFO pairing engine that matches buys against sells, accounts for corporate actions, and produces both realised and unrealised P&L.
The flow for each symbol is roughly:
- Load all trades in chronological order
- Apply corporate action adjustments:
- Stock splits โ adjust qty and price for every pre-split trade
- Mergers โ convert old symbol trades to the new symbol
- Demergers โ create virtual child-symbol buys at the allocated cost basis, reduce parent cost per tax law (ยง49 2C/2D)
- Buybacks โ create virtual sell trades for off-market tenders
- F&O expiry โ settle ITM options at intrinsic value, handle physical delivery for stock options
- Merge partial fills by order_id (VWAP)
- Run FIFO pairing โ each sell consumes oldest unrealised buys
- Clamp negative EQ positions at day boundaries (intraday shorts are allowed, next-day short positions are not)
- Return: realised P&L per round trip, unrealised P&L per open position
Known correctness boundary
The P&L engine has been cross-validated against Kite's P&L report to within 1-2% (our number is typically slightly higher, because we correctly reduce parent cost basis on partial demergers which Kite's report does not โ see ยง49(2C/2D)).
Specific edge cases documented:
- RELIANCE / JIOFIN demerger โ partial (9.8% cost allocation), handled via sell+rebuy virtual trades
- ITC / ITCHOTELS demerger โ partial (13.51%), same approach
- TATAMOTORS / TMPV / TMCV demerger โ full split (60.6% / 39.4%), creates child symbols at allocated cost
- POWERGRID / RECLTD / PFC splits โ rounding artifacts fixed via step 1c correction
- ITM option settlement โ NIFTY/BANKNIFTY cash-settle at intrinsic; stock options physical-delivery
- Granules buyback โ reconstructed from off-market tender data
See the CLAUDE.md in the repo for the full list.
Open positions
Open positions (unrealised) come from the same pairing pass โ after all sells are consumed, whatever remains on the buy side is "open". For each open position, Journal fetches the latest price from the historical_prices table (Yahoo Finance cached) and computes unrealised P&L.
Caveat: option contracts (CE/PE) don't have Yahoo Finance prices. Open option positions show in the listing but unrealised P&L is null.
Prerequisites
You need tradebook data. See Tradebook import.
Related
- Tradebook import โ getting your trades into the system
- Patterns & edge โ going beyond raw P&L to find what works
- Benchmark โ comparing your equity curve against an index or MF