Free lesson · Putting it all together
3 / Turn an idea into a causal feature and a baseline
Open interactive lessonPractice calculationsExplore labs
Start with the idea
A feature is a measurable input, not an order. First compute something simple from past observations, then state how it would inform a decision.
Symbols, units & horizon
- P_t: completed close at time t in dollars per share
- k: positive integer lookback
- j: lag from 0 through k−1
- m_t: trailing mean in dollars per share
- z_t: dimensionless relative deviation
- t: close-time decision index, before the next session
When and why to use this
Use a small causal baseline to establish the input/output contract before introducing richer sequence features or predictive models.
For the running example, use a short trailing price average as a transparent continuation feature. After close t, compare that completed close with the average of the last k completed closes. The average includes today’s close because the decision occurs afterward. It must not include the next open or close.
A positive feature is only a candidate signal. It could reflect market exposure rather than an independent edge. Fix the lookback during an experiment, include cash and buy-and-hold comparisons, and specify what happens when history is too short.
Normalize only when it solves a defined problem. For cross-asset comparison, differences in volatility and price scale matter; a raw $1 change is not comparable across all instruments. Learn any fitted normalization parameters inside training windows.
Before adding ML, verify the baseline output against a spreadsheet-sized sample. Changing future observations must leave earlier feature values unchanged. This prefix check catches many accidental shifts and centered-window errors.
3 / Turn an idea into a causal feature and a baseline
- Select only the k completed closes through time t and add them.
- Divide by k to obtain the trailing mean.
- Divide the latest close by that mean and subtract one. Positive z means above the chosen average, not a proved positive expected return.
Completed closes [98,99,100] average $99. The feature at the last close is 100/99−1≈.010101, or 1.0101%. Nothing from the following session is needed.
Apply it in a strategy
- Compute the baseline from a hand-selected historical window.
- Check forecast timing and prefix invariance.
- Measure performance versus benchmark exposure before introducing a learned model.
Research deliverable
Produce a feature table with source timestamps and show that changing future rows does not alter past features.
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 trailing_feature(closes,index,lookback):
if not isinstance(lookback,int) or lookback<1 or index>=len(closes) or index<lookback-1: raise ValueError("Enough completed history required")
window=closes[index-lookback+1:index+1]
if any(p<=0 for p in window): raise ValueError("Positive share prices required")
average=sum(window)/lookback
return average,closes[index]/average-1
print(trailing_feature([98,99,100],2,3))Continue learning
Putting It All Together: Build a Complete Trading Research System — all lessons- 1 / Define the job and a small research contract
- 2 / Make a point-in-time data contract
- 3 / Turn an idea into a causal feature and a baseline
- 4 / Replay decisions into fills and net returns
- 5 / Add ML, regime models or RL only at a defined interface
- 6 / Convert forecasts into constrained portfolio positions
- 7 / Turn targets into idempotent orders and handle partial fills
- 8 / Reconcile fills, costs, cash and performance
- 9 / Run the miniature system and define the promotion decision
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations