Free lesson · Research & backtests
Make the accounting identity your first test
Open interactive lessonPractice calculationsExplore labs
Start with the idea
Signals are intentions; positions and fills create financial results. A good simulator can explain every dollar through an accounting identity before it reports a Sharpe ratio.
Symbols, units & horizon
- wₜ₋₁: capital weights held before current returns
- Rₜ: aligned asset return vector
- T: transpose for the weighted sum
- R_net: portfolio return after all listed costs
- c_trade,c_borrow,c_funding: costs as fractions of NAV for the same period
- w_target: intended posttrade weights
- w_pretrade: weights after price drift and before trading
- Δw: target minus pretrade weight
- cᵢ: cost per unit weight traded
- | |: absolute value, making sales and purchases count positively
When and why to use this
Use the identity to reconcile trade-level and portfolio-level results and to inspect a suspected timing bug. Turnover connects signal instability to actual economic drag.
A strategy must translate forecasts into positions and then into cash flows. Use beginning-of-period positions for the returns earned during that period. Costs follow actual trades, including exits and changes in size, rather than just the existence of a signal.
Express the cash ledger as a return
- Beginning positions earn , including correctly accounted distributions. Divide by prior NAV and recognise to obtain .
- Divide each dollar expense by the same NAV, then subtract trading, borrow and funding costs. Financing on cash and derivatives needs a consistent ledger convention.
A .5 weight in an asset returning 2% contributes 1% of NAV. Costs of .08%+.02%+.01% leave .89% net.
Translate traded weight into costs
- Actual rebalancing change is target weight minus drifted pretrade weight. Use its magnitude for traded notional/NAV: .
- Sum magnitudes for turnover. Multiply each by its one-way cost rate and sum for portfolio cost. A move from +.2 to −.1 trades .3 of NAV.
Trades of .3 and .1 of NAV at rates 10 bp and 20 bp cost .3×10+.1×20=5 bp of NAV; total absolute turnover=.4.
Weights are relative to NAV. Pretrade weights drift with prices; comparing targets to yesterday’s targets misses this drift. This turnover definition is total absolute traded weight; some reports divide it by two. Quote the convention. The cost rate is per traded dollar and includes the appropriate spread, commission, and impact estimates.
- Test a constant-price path: the only loss should be explicitly modelled costs.
- Test a single position by hand, then confirm the portfolio agrees with the cash and position ledgers.
- Add the initial capital observation when measuring drawdown; otherwise an immediate first-period loss can disappear.
- Stress costs, delayed fills, unavailable borrow, stale prices, and halved liquidity before accepting the model.
Research sources, review dates and limitations
Extend the research question
Keep an experiment ledger containing all trials, preprocessing choices, source versions and failed hypotheses. Reproduce one small result before escalating complexity.
Continue with the connected research module →
Connect the ideas: Cash flows and accounting
Retrieve: Track units, signed cash movements and ownership at each event.
Check the change: Instrument obligations, financing and external capital flows change the ledger you need.
Math & notation → Markets & returns → Trading different assets → Execution & microstructure → Fund operations & capstone → Putting it all together
Self-assessed. Write your explanation before opening this comparison. A deposit raises the balance without being investment P&L. Reconcile external flows separately from fills, fees and marked holdings.Explain it yourself: Why can an account balance rise without an investment profit?
Connect the ideas: Information and decision time
Retrieve: Use only information available when the decision is made.
Check the change: Observation dates, release delays, revisions and label maturity require different availability checks.
Statistics → Point-in-time data → Time series → Research & robust tuning → Financial machine learning → Putting it all together
Self-assessed. Write your explanation before opening this comparison. No. A revised value or delayed release may still contain unavailable information. Audit actual availability timestamps and fit preprocessing inside each training window.Explain it yourself: Does shifting a feature by one row guarantee that it was available?
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 portfolio_net_return(weights, asset_returns, trade_cost, borrow_cost, funding_cost):
if len(weights) != len(asset_returns):
raise ValueError("Asset arrays must align")
gross = sum(w*r for w,r in zip(weights,asset_returns))
return gross-trade_cost-borrow_cost-funding_cost
def turnover_cost(target, pretrade, unit_costs):
if not len(target) == len(pretrade) == len(unit_costs):
raise ValueError("Asset arrays must align")
changes = [abs(a-b) for a,b in zip(target,pretrade)]
return sum(changes), sum(c*dw for c,dw in zip(unit_costs,changes))
print(turnover_cost([.6,.4], [.5,.5], [.001,.001]))Continue learning
Research & Backtest Design — all lessons- Build a point-in-time dataset
- Separate model selection from evaluation
- Account for dependence and multiple experiments
- Make the accounting identity your first test
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations