Trading Dev AcademyFree quant education

Free lesson · Putting it all together

4 / Replay decisions into fills and net returns

Open interactive lessonPractice calculationsExplore labs

Start with the idea

A backtest must translate a decision into an order, an order into a fill, and a fill into a cash change. A correctly shifted signal is necessary but does not describe execution by itself.

Symbols, units & horizon
  • w: fraction of starting account equity exposed for the interval
  • r_asset: entry-to-exit gross asset return
  • c: round-trip cost divided by entry notional
  • E_0: starting equity in dollars
  • r_account: net account return excluding cash interest
  • Π: dollar change for this simplified interval

When and why to use this

Use the one-period identity as a test oracle for your event-driven simulator and cost accounting.

For one teaching session, suppose the completed-close signal is positive, next open is $100 and next close is $101. A 25% position in a $10,000 account means 25 reference shares. The gross asset move is 1%; assumed round-trip costs are 10 basis points of entry notional. Net account return is .25×(.01−.001)=.00225, or $22.50.

This scalar return calculation is a cross-check for the explicit ledger later. It assumes a fixed weight for one interval, no overlapping position, no cash yield and costs proportional to entry exposure. A real rebalance with changing equity or partial fills needs the corresponding event ledger.

An order placed after close cannot simply fill at that same known close. The next-open convention is itself an assumption; gaps, auction access, spreads and participation may prevent that price for your size. Do not infer intrabar path or stop/limit priority from daily high/low alone.

Run a reference implementation on tiny scenarios: no signal, flat prices with costs, a gap, an incomplete fill and an invalid price. Compare its cash result with a second independent calculation before selecting a large backtesting engine.

raccount=w(rasset−c),Π=E0raccount
Model assumptions, derivation and arithmetic

4 / Replay decisions into fills and net returns

  1. Compute the gross asset return from executable entry and exit assumptions.
  2. Subtract the cost rate measured against the same entry notional.
  3. Multiply by account exposure w, then by starting equity for dollar P&L. Do not subtract per-exposure costs from the entire account twice.
Work it by hand

w=.25, r_asset=.01, c=.001 and E₀=$10,000 give r_account=.00225 and P&L=$22.50. If prices are flat, costs alone produce a $2.50 loss.

Apply it in a strategy

  • Specify decision, submission and fill timestamps separately.
  • Check toy ledgers before comparing high-level backtest outputs.
  • Use implementation shortfall to connect execution assumptions with measured costs.

Research deliverable

Write one explicit event trace and reconcile its net return with the per-exposure arithmetic.

Mechanics & research · reviewed 12 September 2026

Abstract and metadata reviewed 12 September 2026. Reports comparisons of 15 strategies, five engines and 180 S&P 500 stocks under four cost regimes, with differences linked to implementation. Exact historical sample endpoints and source-code findings were not independently reviewed or reproduced. This motivates a cash-ledger reference test rather than recommending an engine.

Further reading: Yin et al. · Implementation Risk in Portfolio Backtesting · March 2026 preprint ↗

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 interval_result(equity,weight,asset_return,cost_rate):
    if equity<=0 or not 0<=weight<=1 or cost_rate<0: raise ValueError("Invalid long-only interval")
    account_return=weight*(asset_return-cost_rate)
    return account_return,equity*account_return

print(interval_result(10000,.25,.01,.001))

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