Quant interview toolkit · P&L accounting

Selling half a winning position did not create half its profit

You buy 100 shares at £100 and the midprice rises to £102. The position shows a £200 gain. You sell 50 shares, but the sale executes at £101.90. Did you “realize half the £200” and still have £100 unrealized? Close, but not quite: the bid-side execution cost takes £5 from total economic value.

Rebuild the position from cash and inventory

Ignore fees, dividends and financing for one paragraph. The initial purchase costs £10,000, so cash changes by −£10,000 and inventory becomes 100 shares. At a £102 midprice, inventory is marked at £10,200. Total wealth relative to the pre-purchase cash position is therefore +£200.

Now sell 50 shares at £101.90. The sale brings in £5,095. Cumulative cash flow from the two trades is −£10,000+£5,095=−£4,905-£10{,}000+£5{,}095=-£4{,}905. Remaining inventory is 50 shares worth 50(£102)=£5,10050(£102)=£5{,}100 at the mid. Sum cash and marked inventory: −£4,905+£5,100=£195-£4{,}905+£5{,}100=£195. The position’s total economic P&L is £195 before other costs.

StageCumulative trade cash flowShares heldMid-marked inventoryTotal P&L
Just after buying at £100−£10,000100£10,000£0
Mid rises to £102−£10,000100£10,200£200
Sell 50 at £101.90−£4,90550£5,100£195

Had those 50 shares sold at the £102 mid, total wealth would still be £200. Selling at £101.90 instead of the mark costs 50(£0.10)=£550(£0.10)=£5. This is an execution effect, not merely an accounting relabeling.

Realized and unrealized are a split of the total

Under a simple average-cost convention, the 50 sold shares have £100 cost basis each. Their realized trading gain is 50(£101.90−£100)=£9550(£101.90-£100)=£95. The 50 remaining shares have marked unrealized gain 50(£102−£100)=£10050(£102-£100)=£100. Together they equal £195. If you later sell the remaining shares, their execution price and fees determine the final cash outcome.

With multiple purchase prices, FIFO, average cost and other accepted lot conventions can assign different amounts to realized versus unrealized P&L after a partial sale. They do not change cash already received or the market value of what remains. Do not confuse a change in accounting label with a gain generated by the trade itself. Tax rules can make lot selection economically relevant, but that is a separate calculation and depends on jurisdiction and account details.

The self-financing update

Let qt−1q_{t-1} be shares held just before a new trade, Mt−1M_{t-1} the prior mark, MtM_t the new mark, Δqt\Delta q_t the signed number of shares purchased at execution price PtexecP_t^{\rm exec}, and ctc_t explicit fees. Cash changes by −ΔqtPtexec−ct-\Delta q_t P_t^{\rm exec}-c_t. If wealth is cash plus shares marked at MtM_t, then period P&L can be decomposed as

ΔWt=qt−1(Mt−Mt−1)+Δqt(Mt−Ptexec)−ct.\Delta W_t =q_{t-1}(M_t-M_{t-1}) +\Delta q_t(M_t-P_t^{\rm exec})-c_t.

The first term is mark-to-market change on inventory already held. The second is the cost or benefit of trading away from the current mark. For the sale above, Δq=−50\Delta q=-50 and M−Pexec=£0.10M-P^{\rm exec}=£0.10, so the second term is −£5. The formula makes spread cost visible without using a realized/unrealized convention.

Marks require care. The midprice is not always the liquidation price for a large position. If the book is thin, a bid-side or impact-aware liquidation mark can give a lower value. A mark should also have a timestamp and source; stale marks can make P&L appear smooth and then jump when prices refresh. Return smoothing and Sharpe annualization discusses one consequence of stale marks.

Explicit fees belong in the same reconciliation. If the partial sale at £101.90 also costs £2 in fees, cash from the sale rises by only £5,093 and total P&L becomes £193. Under the simple cost-basis split, realized gain on the 50 sold shares is £93 after the fee and the remaining marked gain is £100. Changing the mark from £102 mid to a £101.80 liquidation value for the remaining 50 shares would reduce the reported total by another £10. The fee is an actual cash cost; the mark change is a valuation choice about the unsold inventory. Both matter, but they should be identified separately.

Make the ledger complete

Real portfolio P&L may include dividends, coupons, borrow fees, funding interest, FX conversion, corporate actions and tax or exchange fees. Add those as cash flows or value changes in a consistent currency. For a derivative, the relevant mark may be a model price rather than a traded mid, and model parameter changes can create P&L even if the underlying price barely moves. The simple share example is a foundation for reconciling the complete ledger, not a full accounting policy.

A reproducible daily report stores beginning cash and inventory, every fill and fee, ending inventory, ending marks, and external deposits or withdrawals. Reconcile the ending wealth to the prior wealth plus trading and market changes. If the realized and unrealized columns disagree with the cash-plus-inventory total, the report has an accounting problem before it has a trading insight.

Sell part of the position and reconcile P&L

The book bought 100 shares at £100. The sale fee applies only if at least one share is sold.

Practice

Execution priceIn the example, what would total P&L be if the partial sale executed at £101.80 instead of £101.90, with the same £102 mid mark?
Show answer

The sale proceeds would be £5,090, £5 less than before. Remaining inventory stays marked at £5,100. Total P&L becomes £190 before explicit fees.

LabelsIf an accounting policy changes which purchase lot is assigned to a sale, must the cash-plus-marked-inventory total P&L change?
Show answer

No. The split between realized and unrealized can change, but the actual trade cash flows and current inventory mark do not change solely because the cost-basis label changed.