Free lesson · Research & robust tuning
Write the experiment before the strategy
Open interactive lessonPractice calculationsExplore labs
Start with the idea
A backtest answers a precisely specified counterfactual: what would this decision process have done with the information and trading opportunities available then? Ambiguity creates room for accidental hindsight.
Symbols, units & horizon
- w_t: portfolio exposure decided at t and feasible before the next return
- r_(t+1): next holding-period simple return
- c: proportional cost per unit absolute weight change
- | |: absolute value
- R_net: return fraction on the declared capital base
- t−1: previous decision
- Example excludes financing and market impact
When and why to use this
Use the experiment contract to distinguish model improvements from changes in entry timing, leverage, benchmark or cost assumptions.
Define the universe, point-in-time membership, feature availability, label horizon, executable entry, position sizing, costs and benchmark before choosing parameters. Specify whether the goal is alpha, lower execution cost or better risk estimation; different goals require different target variables and evaluations.
Separate economic hypothesis from implementation hypothesis. “Inventory pressure reverses” is an economic claim; “a five-bar normalised imbalance captures it” is a particular measurement. Compare alternative measurements under one documented search budget, including unsuccessful attempts.
A reproducible experiment includes immutable data identifiers, code version, configuration, random seeds and a ledger. Report per-period net returns with cash and risk conventions. A signal evaluated at the close cannot earn the return that ended at that same close.
Write the experiment before the strategy
- An exposure w held over the next return earns w times that return on the chosen fixed capital convention.
- Changing exposure from w_previous to w trades an absolute amount |w−w_previous|. Multiply by the one-way unit cost c.
- Subtract costs at the rebalance and align each decision only with the following return. Wealth compounding is a separate operation using 1+R_net.
Move from weight 0 to .5 before a +1% next-period return. At cost .001 per unit turnover, net=.5(.01)−.001(.5)=.0045, or .45%.
Apply it in a strategy
- Write the hypothesis and failure condition, then fix data and execution conventions.
- Implement a minimal baseline and verify one period by hand before expanding the sample.
- Archive every comparison, including failed candidates, with the same benchmark and capital definition.
Research deliverable
A reproducible research manifest plus a daily decision-and-P&L ledger is the minimum evidence package.
Research sources, review dates and limitations
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 next_period_net(weights,next_returns,cost,initial_weight=0):
if len(weights)!=len(next_returns) or cost<0: raise ValueError("Aligned arrays and nonnegative cost required")
previous=initial_weight
result=[]
for w,r in zip(weights,next_returns):
result.append(w*r-cost*abs(w-previous))
previous=w
return result
print(next_period_net([.5],[.01],.001))Continue learning
Strategy Research, Backtesting & Robust Optimisation — all lessons- Write the experiment before the strategy
- Walk-forward validation, overlapping labels and purging
- Hyperparameter optimisation without an unrestricted search
- Multiple trials, false discoveries and selection diagnostics
- Dependent returns, block bootstrap and realistic stress tests
- Fine-tuning, retraining and the research-to-production decision
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations