Pillinger Works

Machine Learning Basics

ExpertE-043
Ready to move forward?

You can explore the materials without registering, but with a free account you can track your progress and earn rewards along the way. By the end of your learning journey, you can have the knowledge you need to become a profitable Trader!

Join →

Introduction

Machine learning is a family of methods that allows a system to learn relationships from data rather than relying only on manually specified rules. In trading, this can mean estimating a probability, ranking instruments, classifying market conditions, forecasting a return, or deciding whether a predefined setup deserves attention.Machine learning does not remove the need for a trading hypothesis. It changes where complexity lives: instead of writing every relationship explicitly, the researcher gives the model data, a target, and a learning procedure. The model can then discover patterns within the supplied information.That flexibility is both its strength and its main research risk. With enough freedom, a model can learn genuine structure, but it can also learn noise. For an advanced trader, the key skill is therefore not knowing every algorithm. It is understanding what the model is being asked to learn, how the evidence is separated, and how the resulting predictions become actual trades.

1. What Machine Learning Means in Trading

At a basic level, supervised machine learning maps input variables to a target. The inputs may be the features discussed in E-042. The target could be future return, probability of a profitable trade, maximum adverse excursion, or a classification such as whether a setup reaches a predefined objective.The model learns a function from examples. It does not “understand” the market in the human sense. It estimates relationships contained in the training data according to its objective and assumptions.This distinction matters because a model can produce precise numerical predictions while having little out-of-sample value. Prediction output is not evidence of predictive power by itself.

2. Supervised, Unsupervised, and Reinforcement Learning

Supervised learning uses labeled outcomes. This is the most direct framework for many trading research problems: inputs are paired with a future outcome defined in advance.Unsupervised learning searches for structure without a predefined target. Clustering market environments is a common conceptual example.Reinforcement learning frames the problem around actions, states, rewards, and sequential interaction. It is substantially more complex because the learning process can influence the environment and because reward design becomes critical.A trader should select the learning framework because it matches the research question, not because the method sounds sophisticated.

3. Regression and Classification

Regression predicts a continuous quantity, such as a future return or volatility estimate. Classification predicts a category, such as positive versus negative return or whether a trade reaches a target before a stop.The distinction changes the target definition, evaluation metrics, and interpretation of model output.For trading, a classification accuracy of 60% is not automatically useful. If the losing trades are much larger than the winning trades, accuracy can coexist with negative Expectancy. Conversely, a model with modest classification accuracy can be useful if it meaningfully changes the distribution of trade outcomes.

4. Training, Validation, and Test Sets

A machine-learning workflow usually separates data into development stages. Training data are used to fit model parameters. Validation data can be used for model selection or hyperparameter decisions. Test data are reserved for final evaluation.In time-series trading, the split must respect chronology. Randomly shuffling observations can allow information from the future regime to influence the training process.The test set should remain protected from iterative research. If the researcher repeatedly checks test performance and changes the model based on what is observed, the test set has effectively become another development set.

5. The Target Variable Is a Trading Decision

Target design is one of the most important parts of machine-learning research. “Predict the next return” is not yet a complete trading objective.The researcher must define the horizon, price convention, execution assumption, target transformation, and treatment of costs where relevant. A target based on the next close may represent a different economic problem from a target based on the maximum return achievable over the next ten bars.The target should correspond to something the trading system can actually use. Otherwise, excellent predictive performance may have little operational meaning.

6. Training Data and Information Boundaries

Every observation used during training must represent information that would have been available at the relevant historical time. This applies to features, labels, preprocessing, universe definitions, and external datasets.A particularly subtle problem occurs when preprocessing is fitted on the entire dataset before the chronological split. Even if the model never directly sees future prices, future observations can influence scaling, imputation, feature selection, or dimensionality reduction.The information boundary must therefore apply to the entire research pipeline, not just the final model.

7. Model Complexity

Machine-learning models differ greatly in flexibility. A simple linear model has limited degrees of freedom. A deep tree ensemble or neural network can represent far more complex relationships.Greater flexibility can capture nonlinear structure, but it also makes it easier to fit noise. Complexity should therefore be justified by the hypothesis and by evidence that the additional flexibility improves unseen data.The relevant question is not whether a complex model has higher training performance. It is whether its additional complexity produces durable Out-of-Sample information.

8. Overfitting in Machine Learning

Overfitting occurs when a model captures patterns that are too specific to the development sample and therefore fail to generalize.In trading, overfitting can happen through excessive model complexity, too many features, too many hyperparameter searches, repeated dataset reuse, or selective removal of poor results.A model can be overfit even when cross-validation appears acceptable if the research process repeatedly adapts to the validation results. Overfitting is therefore a property of the entire research process, not just of the algorithm.

9. Evaluation Metrics Must Match the Trading Objective

Machine-learning metrics such as mean squared error, log loss, precision, recall, or AUC describe prediction behavior. They do not automatically describe trading profitability.Trading evaluation should connect predictions to a defined decision process. Depending on the strategy, useful outputs can include Expectancy, R-Multiple distribution, drawdown, turnover, costs, and stability across environments.A model should not be selected solely because it wins a generic machine-learning leaderboard if the chosen metric is weakly related to the actual trading objective.

10. Probability Predictions and Calibration

Many trading models produce probabilities rather than binary signals. A prediction of 0.70 can be interpreted as a probability estimate only if the model is reasonably calibrated.If events predicted at 70% happen only 55% of the time, the probability is systematically optimistic. Calibration can therefore matter when probability is used for position sizing or trade selection.Even a well-calibrated probability is not the same as a guaranteed outcome. It remains an estimate based on a particular data-generating environment.

11. Feature Importance Is Not Causation

Machine-learning tools can estimate which variables contribute to prediction. Feature importance, permutation importance, or related techniques can help investigate the model.However, importance does not prove that a variable causes the outcome. A feature may be a proxy for another variable or may be useful only under a particular market structure.Interpretability tools are therefore diagnostic instruments. They should generate questions for research rather than be treated as causal proof.

12. Class Imbalance and Rare Events

Trading datasets can contain imbalanced targets. For example, a particular extreme event may occur rarely while normal observations dominate the sample.A model can achieve high overall accuracy simply by favoring the common class. This can be misleading when the rare class contains most of the trading value.Evaluation should therefore examine the relevant conditional outcomes and their economic consequences rather than relying on accuracy alone.

13. Cross-Validation for Time Series

Traditional random cross-validation assumes observations can be mixed without violating the information structure. Financial time series often do not satisfy that assumption.Time-aware validation methods preserve chronology and can use rolling or expanding training windows. The exact design should reflect how the model would actually be retrained in live use.Cross-validation does not magically remove Data Snooping. Repeatedly comparing many model designs through the same validation process can still produce an apparently strong result by chance.

14. Out-of-Sample Evidence and Model Selection

Out-of-Sample testing is especially important when machine-learning models have many possible configurations. A model should be selected using protected research stages, then evaluated on genuinely unseen data.If many candidate models are compared and the best one is chosen based on the same holdout, the holdout has been consumed by the selection process.Strong evidence requires discipline around model versions, research logs, dataset boundaries, and the number of comparisons performed.

15. From Prediction to Position Size

A prediction becomes a trading system only when it is converted into an action. That action may be binary entry, ranking, threshold selection, or a continuous position size.The conversion rule can dominate the realized results. A model that predicts small positive returns may not justify a trade after costs. A model that produces a useful ranking may work better when combined with portfolio-level allocation.The complete chain should therefore be evaluated: prediction → decision rule → sizing → execution → realized R-Multiple.

16. Case Study — The 72% Accuracy Model

A classification model predicts whether a stock will be positive over the next five sessions. Its test accuracy is 72%, which initially appears impressive.Further analysis shows that the model predicts the common class extremely well but performs poorly on the smaller group of large negative moves. When translated into the actual trading rule, the resulting Expectancy is negative because losses are concentrated in those missed events.The lesson is straightforward: prediction accuracy is not a trading objective. The economic distribution of the resulting trades must be evaluated.

17. Case Study — The Complex Model Loses to the Simple Model

A trader compares a linear model with a much more flexible ensemble. The complex model has substantially better training performance and slightly better validation performance.On the protected Out-of-Sample period, the simple model performs similarly while the complex model deteriorates. The additional flexibility had captured sample-specific structure.The correct conclusion is not that complex models are useless. It is that complexity needs evidence. If the extra degrees of freedom do not produce stable unseen-data value, they have not earned their place in the system.

18. Machine Learning Does Not Replace Research Discipline

Machine learning can automate parts of pattern discovery, but it does not eliminate the need for hypothesis design, data quality, Sample Size analysis, Statistical Significance, and controlled validation.In fact, the flexibility of machine learning can make research discipline more important. A powerful model can search a large hypothesis space without making that space economically meaningful.The researcher remains responsible for defining what counts as information, what counts as success, and what evidence is sufficient to justify deployment.

19. Build the Smallest Useful ML System

A practical first machine-learning system can be deliberately simple: a small feature set, one clearly defined target, one baseline model, one chronological validation design, and one protected Out-of-Sample evaluation.The baseline is important. If a simple rule or naive benchmark performs similarly, the machine-learning model may not add enough value to justify its complexity.Only after the baseline is understood should the researcher add features, alternative models, or more advanced optimization.

20. Professional Machine-Learning Trading Framework

A professional workflow can be organized into these stages:1. Define the trading hypothesis and economic target.2. Define the information boundary and historical dataset.3. Build a small, time-correct feature set.4. Define a simple baseline.5. Choose the simplest suitable model family.6. Train and validate chronologically.7. Record every model and research decision.8. Control the number of comparisons and protect the final holdout.9. Translate predictions into explicit trading rules and sizing.10. Evaluate Expectancy, R-Multiples, drawdown, costs, and stability.11. Reproduce the entire pipeline in live conditions.12. Monitor whether live behavior remains consistent with the validated model.The purpose is not to build the most sophisticated model. It is to determine whether machine learning adds reliable information to an already well-defined trading process.

21. Expert Exercise — Build a Baseline ML Experiment

Choose one trading hypothesis and design a small experiment before training any sophisticated model.Define the target, horizon, features, information boundary, training period, validation period, protected Out-of-Sample period, baseline strategy, primary evaluation metric, and trading conversion rule.Train one simple model first. Record its predictions and translate them into actual trades with realistic costs. Then compare the result with the baseline.Only after this should you introduce one additional source of complexity. Record whether the change improves unseen-data Expectancy and R-Multiple behavior, not merely training loss.

22. Knowledge Check

1. What does machine learning add to a trading research process?2. What is the difference between supervised and unsupervised learning?3. Why must time-series validation respect chronology?4. Why is target definition a trading decision?5. How can preprocessing create information leakage?6. Why does greater model complexity increase Overfitting risk?7. Why is classification accuracy not enough to evaluate a trading model?8. What does probability calibration mean?9. Why does feature importance not prove causation?10. Why should a simple baseline be built before a sophisticated ML system?A strong answer recognizes that machine learning is a flexible estimation tool, not an automatic source of edge. The quality of the result depends on the target, data, information boundary, model complexity, validation process, trading conversion, and Out-of-Sample evidence.