
The big picture
Machine learning estimates relationships from examples. In markets, the data change, the signal is weak and a plausible prediction may disappear after trading costs. This expert topic develops a complete research design from timestamped features to walk-forward evaluation and monitored deployment. Random forests, neural networks and reinforcement learning are alternative tools within that design; none creates reliable market foresight simply by being sophisticated.
Core concepts
Learning objectives
- Define an executable prediction target and timestamp-safe features.
- Compare simple baselines with tree, sequence and decision-learning models.
- Design walk-forward tests with label-overlap purging and an appropriate gap.
- Evaluate calibration, net results, capacity and drift before considering controlled use.
Define an experiment before choosing an algorithm
1.1 Prediction time determines usable information
Specify the decision timestamp, universe, holding horizon and available action. Predicting tomorrow’s close-to-close direction is not the same as earning that return: a signal formed after today’s close cannot necessarily trade at today’s close. Define the first executable price and the rules for missing, suspended and delisted securities. Keep unsuccessful securities in historical universes where appropriate; a dataset containing only today’s survivors overstates what a historical investor could have selected.
1.2 A target must match an executable decision
A supervised target can be a future return, direction or event. Record exactly which future interval creates each label. Features might include lagged returns, volumes, volatility or dated disclosures, but their values must have been available at prediction time. Distinguish an economic period-end from the publication date of its results. For news sentiment, preserve the original release timestamp, language, revisions and duplicate stories before claiming a text-based signal anticipates price.
Step-by-step method
- Write the decision, action and target interval explicitly.
- Build a point-in-time universe with data lineage.
- Verify release times and the first realistic execution opportunity.
A filing concerns March results but was released in May. The learner makes it available only after the May release, rather than giving a March model information investors had not yet received.
Engineer features and choose proportionate models
2.1 Transformations can leak information
Fit scaling, imputation, feature selection and text vocabularies on training data only. A pipeline helps keep those operations inside each training fold. Lag a rolling indicator consistently with the decision timestamp; a full-day high is unavailable at midday. Avoid interpolation that uses future observations to fill past values. Join macro releases by their actual availability and preserve revised versus originally published data when the distinction affects the experiment.
2.2 Complexity should answer a research need
Start with a no-change or majority-class baseline and a simple regularised model. Random forests combine decision trees and can represent nonlinear interactions, but correlated noisy features still invite overfitting. LSTM networks model sequences with learned state; they require justified sequence construction and enough relevant data. Reinforcement learning chooses actions based on a reward and simulated environment, so unrealistic fills or rewards can teach exploitation of the simulator rather than a usable strategy.
Step-by-step method
- Create a feature-availability audit for every input.
- Fit all learned transformations within the training window.
- Compare advanced models with a reproducible simple baseline.
A sentiment tool appears accurate because the text collection includes updated articles written after the market moved. Removing those revisions and using original timestamps provides a fairer, often weaker, experiment.
Validate chronologically and isolate model selection
3.1 Walk forward into genuinely later observations
Randomly mixing financial rows can train on the future or place near-duplicate observations on both sides of a split. Walk-forward evaluation trains on an earlier window and tests on a later one, repeating with either expanding or rolling training history. Keep an untouched final period for a final research decision. Hyperparameters and feature choices belong inside a nested training-and-validation process, not in repeated adjustments to the final holdout after viewing results.
3.2 Purge overlapping labels and impose a justified gap
Labels covering several future days can overlap a test interval even when their feature dates are earlier. Purging removes training observations whose label intervals overlap the protected evaluation interval. A gap or embargo separates adjacent dependent observations where justified; its length must follow the label horizon and information dependencies, not an arbitrary universal number. A library’s chronological splitter and gap option are useful building blocks, but do not automatically audit label overlap, cross-asset grouping or all forms of leakage.
Step-by-step method
- Draw training, label and evaluation intervals on a timeline.
- Purge intersecting label intervals and justify any gap.
- Freeze choices before using the final holdout once.
A five-day target for a training observation ends inside the next test block. The learner excludes that observation even though its feature date precedes the test, because part of its answer belongs to the evaluation period.
Evaluate probabilities and economics together
4.1 Accuracy alone can conceal failure
Compare class balance, confusion matrices, probability calibration and suitable loss measures. A model can achieve high accuracy by always predicting the majority outcome. A well-calibrated probability means outcomes occur at approximately the stated frequency across comparable predictions, not that any individual prediction is certain. Assess performance across market regimes, securities and dates rather than allowing a few exceptional observations to dominate the conclusion. Report uncertainty and the number of experiments attempted.
4.2 Costs, turnover and capacity determine feasibility
Translate predictions into a predeclared position rule, then simulate fees, relevant taxes, spread, slippage, borrow constraints, participation limits and realistic latency. Teaching example: an assumed gross edge of12 basis points per trade becomes9,5,1 and−3 basis points when round-trip costs are3,7,11 and15 basis points. Increasing turnover can erase a small signal. Unavailable shorting or insufficient order-book depth cannot be solved by assuming frictionless execution.
Step-by-step method
- Evaluate baseline-relative statistical performance and calibration.
- Apply an executable decision rule to unseen observations.
- Stress costs, delays, turnover and position capacity.
Two models have similar directional accuracy. The model that trades far less may retain a better net outcome under the declared costs, but the learner verifies this only on chronologically unseen data rather than selecting it by in-sample profit.
Document, monitor and stop a failed experiment
5.1 Reproducibility is part of the evidence
Save source provenance, licences, timestamp rules, code version, parameters, random seeds and split dates. Record unsuccessful experiments so that the research history does not become a catalogue of winners. Explain why the feature should contain relevant information and test its sensitivity to small design changes. An apparently strong result that vanishes with a different start date or realistic fill assumption needs investigation before any operational consideration.
5.2 Deployment changes the risk problem
Begin with paper evaluation and independent review, not automatic orders. Any later live use requires authorised broker access, applicable permissions, position controls and a tested operational process. Monitor data completeness, prediction distribution, calibration, realised net outcomes and changing market conditions. Define a pause rule for broken inputs, excessive drawdown, abnormal orders or model drift. Retraining does not automatically repair deterioration; it creates another model that needs appropriate validation and version control.
Step-by-step method
- Package the experiment so another reviewer can reproduce it.
- Run a forward paper test with fixed rules and realistic costs.
- Set monitoring thresholds, authorised overrides and a retirement rule.
A news feed changes its timestamp format and shifts articles into the wrong day. A data-quality alert pauses the paper system; retraining immediately on the corrupted inputs would deepen the problem rather than solve it.
A small assumed edge can disappear after costs
| Measure | Value |
|---|---|
| Cost3bp | 9 basis points |
| Cost7bp | 5 basis points |
| Cost11bp | 1 basis points |
| Cost15bp | -3 basis points |
Reference table
| Input or decision | Incorrect handling | Required control |
|---|---|---|
| Financial statements | Use the accounting period-end | Use the actual public-release timestamp |
| Scaling and feature selection | Fit on the complete dataset | Fit separately inside each training fold |
| Multi-day target | Ignore overlapping outcome windows | Purge labels crossing the evaluation interval |
| News sentiment | Use later article revisions | Preserve original version and publication time |
| Model choice | Tune repeatedly to final test | Use nested validation and a fixed final holdout |
Glossary of key terms
- Calibration
- Agreement between predicted probabilities and observed frequencies over comparable cases.
- Embargo
- A deliberately excluded separation interval used to reduce information dependence around evaluation.
- Feature
- An input available when a prediction is made.
- Label
- The outcome a supervised model is trained to estimate.
- Leakage
- Use of information unavailable at the decision time or improperly shared across evaluation boundaries.
- Overfitting
- Learning incidental sample patterns that fail to generalise.
- Purging
- Removing observations whose outcome intervals contaminate a protected evaluation interval.
- Walk-forward evaluation
- Repeated training on earlier data and testing on later data under fixed chronological rules.
Frequently asked questions
Does a more complex network guarantee better returns?
No. Complexity can amplify noise, overfitting and implementation costs.
Is a chronological split sufficient on its own?
No. Audit publication times, transformations, overlapping labels and instrument groups.
Does high accuracy imply profit?
No. Class balance, payoff size, execution, turnover and costs matter.
Can a model place PSX orders automatically?
Only if the actual authorised access, permissions and controls are established; this research example assumes no such access.
Common pitfalls
| Common mistake | A better approach |
|---|---|
| Scaling the entire dataset first | Fit transformations only inside each training fold. |
| Repeatedly tuning to the final holdout | Use nested validation and retain a genuinely untouched final test. |
| Ignoring publication timestamps | Use information only from its actual release time. |
| Reporting gross backtest returns alone | Show cost, delay, capacity and uncertainty stress results. |
Your learner task
Write a paper research protocol for a dated-news sentiment classifier. Specify target, available features, publication timestamps, baseline, walk-forward windows, label-overlap removal, gap rationale, net-cost simulation and a final holdout. Include a reproducibility checklist and failure criteria.
Sources & verification
Use the linked documents to check the factual and regulatory context. Source dates and limitations are stated where relevant. Educational examples and analytical frameworks are not personalised recommendations.
- scikit-learn · Common pitfalls and recommended practices ↗
Official software documentation supporting training-only transformations and pipelines. It does not validate a trading strategy.
- scikit-learn · TimeSeriesSplit ↗
Chronological splitting and gap parameter; researchers must separately audit label overlaps and financial data availability.
- PSX Regulations · updated 23 September 2026 ↗
Dated official rules. Verify later notices, actual contracts, eligibility and permissions; a rulebook does not establish liquid retail access.
Editorial review: 22 October 2026
