Trading Dev AcademyFree quant education

Free lesson · Putting it all together

8 / Reconcile fills, costs, cash and performance

Open interactive lessonPractice calculationsExplore labs

Start with the idea

The ledger is the common language linking models, execution and fund accounting. Every fill changes cash and holdings; marking those holdings determines equity.

Symbols, units & horizon
  • C: cash in dollars
  • Δq: signed filled shares, positive buy and negative sell
  • P_fill: actual fill dollars per share
  • f: nonnegative dollar commission for that fill
  • q: confirmed signed holdings
  • P_mark: valuation price per share
  • E: marked equity
  • model: one cash currency and no external flows

When and why to use this

Use one event ledger as the source of truth for backtests, paper trading and performance attribution.

Continue the same one-session example with explicit fills. Start with $10,000 and no holdings. Buy 25 shares at $100 and pay $.25 entry commission. Cash becomes $7,499.75. The closing reference is $101, but the exit fill is $100.92; another $.25 commission leaves final cash $10,022.50 and no shares.

The $25 reference gross gain lost $2 to exit slippage and $.50 to commissions, leaving $22.50. This matches the earlier 10-basis-point round-trip assumption on $2,500 notional. The agreement is a consistency check, not evidence that those costs are realistic.

At every event, reconcile cash, positions, fees and marks. An open losing position still affects equity; realized P&L alone can hide it. Deposits and withdrawals are external capital flows, not investment returns. Include dividends, borrow, funding and currency conversions where the instrument requires them.

Compare signal forecasts, intended positions, submitted orders and actual fills separately. This lets you locate whether a disappointing result came from prediction, sizing, execution or accounting.

Cnew=Cold−ΔqPfill−f,qnew=qold+Δq,E=C+qPmark
Model assumptions, derivation and arithmetic

8 / Reconcile fills, costs, cash and performance

  1. A buy consumes Δq×P_fill cash; a negative sell quantity creates a cash inflow. Deduct the fill’s fee in either case.
  2. Add the signed fill quantity to confirmed holdings.
  3. Value remaining holdings at the stated mark and add cash. Compare ending equity with starting equity after separating external flows.
Work it by hand

Buy: cash=10000−25×100−.25=7499.75 and holdings=25. Sell: cash=7499.75−(−25)×100.92−.25=10022.50 and holdings=0. Net profit=$22.50.

Apply it in a strategy

  • Record each fill once using an immutable identifier.
  • Reconcile marks, cash flows and positions independently of the strategy model.
  • Explain the difference between reference gross P&L, execution costs and net NAV change using fund accounting.

Research deliverable

Reconcile the running example to $10,022.50 ending cash with zero holdings, without double-counting costs.

Python implementation

Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.

def ledger_fill(cash,holdings,quantity,fill_price,fee,mark):
    if min(fill_price,fee,mark)<0: raise ValueError("Nonnegative price/fee/mark required")
    cash=cash-quantity*fill_price-fee
    holdings=holdings+quantity
    return cash,holdings,cash+holdings*mark

cash,holdings,equity=ledger_fill(10000,0,25,100,.25,100)
print(ledger_fill(cash,holdings,-25,100.92,.25,101))

Continue learning

Putting It All Together: Build a Complete Trading Research System — all lessons
  1. 1 / Define the job and a small research contract
  2. 2 / Make a point-in-time data contract
  3. 3 / Turn an idea into a causal feature and a baseline
  4. 4 / Replay decisions into fills and net returns
  5. 5 / Add ML, regime models or RL only at a defined interface
  6. 6 / Convert forecasts into constrained portfolio positions
  7. 7 / Turn targets into idempotent orders and handle partial fills
  8. 8 / Reconcile fills, costs, cash and performance
  9. 9 / Run the miniature system and define the promotion decision

Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations