The ML Framework Landscape
Choosing the right ML framework for trading is critical. Each has strengths and weaknesses. This guide covers every major framework with real performance data from Kaggle competitions and production trading systems.
Gradient Boosted Trees (Best for Tabular Data)
XGBoost
The gold standard for tabular financial data. Used in winning Kaggle solutions consistently.
import xgboost as xgb
model = xgb.XGBRegressor(
n_estimators=100,
max_depth=4,
learning_rate=0.1,
subsample=0.8,
colsample_bytree=0.8,
tree_method='hist'
)
model.fit(X_train, y_train)
- Pros: Fast, interpretable, handles missing data, built-in regularization
- Cons: Not for sequential data, requires feature engineering
- Best for: Price prediction, signal generation, feature importance
LightGBM
Faster than XGBoost with similar accuracy. Uses leaf-wise growth instead of level-wise.
import lightgbm as lgb
model = lgb.LGBMRegressor(
n_estimators=100,
max_depth=4,
learning_rate=0.1,
num_leaves=31,
subsample=0.8
)
model.fit(X_train, y_train)
- Pros: Faster training, lower memory, better for large datasets
- Cons: Can overfit on small datasets
- Best for: Large-scale trading, real-time prediction
CatBoost
Best for categorical features. Handles categorical data natively without encoding.
import catboost as cb
model = cb.CatBoostRegressor(
iterations=100,
depth=4,
learning_rate=0.1,
cat_features=categorical_columns
)
model.fit(X_train, y_train)
- Pros: Best for categorical data, ordered boosting reduces overfitting
- Cons: Slower than LightGBM
- Best for: Mixed data types, categorical features
Deep Learning (Best for Sequential Data)
PyTorch
Most flexible deep learning framework. Preferred by researchers.
import torch
import torch.nn as nn
class TradingLSTM(nn.Module):
def __init__(self, input_size, hidden_size, num_layers):
super().__init__()
self.lstm = nn.LSTM(input_size, hidden_size, num_layers)
self.fc = nn.Linear(hidden_size, 1)
def forward(self, x):
out, _ = self.lstm(x)
return self.fc(out[:, -1, :])
- Pros: Dynamic computation graph, easy debugging, strong community
- Cons: Slower inference than TensorFlow
TensorFlow
Best for production deployment. TFLite for mobile, TF Serving for production.
- Pros: Production-ready, TFLite for edge, TF Serving for API
- Cons: Less flexible than PyTorch, steeper learning curve
Online Learning Frameworks
River
Python library for online machine learning. Perfect for streaming financial data.
from river import ensemble, preprocessing
model = preprocessing.StandardScaler() | ensemble.AdaptiveRandomForestRegressor()
- Pros: Handles streaming data, no retraining needed, memory efficient
- Cons: Limited to simple models
Framework Comparison Table
| Framework | Best For | Speed | Accuracy | Ease of Use |
|---|---|---|---|---|
| XGBoost | Tabular data | Fast | High | Easy |
| LightGBM | Large datasets | Fastest | High | Easy |
| CatBoost | Categorical data | Medium | Highest | Easy |
| PyTorch | Sequential data | Medium | Highest | Hard |
| TensorFlow | Production | Fast | High | Medium |
| River | Streaming data | Fastest | Medium | Easy |
My Recommendation for Trading
- Start with XGBoost: Most reliable for tabular financial data
- Add LightGBM: For speed and ensemble diversity
- Use PyTorch only for: Sequential data (price series) or unstructured data (news, images)
- Use River for: Online learning when you cannot retrain offline
SEBI Disclaimer
This article is for educational purposes only. Algorithmic trading involves substantial risk of loss.
A Practical Comparison Grid by Task
Match the framework to the input shape. Tabular rows with a dozen to a few hundred features belong to gradient-boosted trees: XGBoost, LightGBM, or CatBoost handling sparse holiday gaps and mixed dtypes natively. Sequential inputs belong to recurrent or convolutional networks, which sacrifice the tabular flexibilities for memory of order. Rich, unstructured inputs like order-book snapshots or charts belong to neural stacks with embeddings. The grid saves weeks of tutorials spent applying the wrong tool, because a timeseries model on a tabular file and a tabular model on image data both fail the same way: excellent loss, useless live predictions.
HistGradientBoosting vs the Big Three
Scikit-learn's HistGradientBoostingClassifier offers a free, dependency-light histogram learner with native missing handling and categorical support, and it is fully adequate for small financial feature sets. It trails the specialised libraries on huge data where the C++ kernels and GPU paths shine, but a 2,500-row Nifty file will not show that gap. Use it for a first pass, a second opinion, or a production path where you refuse the pip dependency; keep XGBoost and LightGBM for the heavy scanning and experiment volume where their ecosystems and speed pay off.
Deep Learning vs Trees for Sequential Features
The frequent failure in trading frameworks is crossing the streams: feeding flat daily features to an LSTM because it is "more advanced", when a tree model would read the same table better. Trees win whenever the signal sits in individual feature levels and monotone relationships; networks win when the signal sits in the shape of the sequence or the arrangement of many small inputs. A fair test holds the labels and validation identical, then compares a tuned XGBoost against a tuned LSTM on rolling out-of-time folds. Do that comparison once per project before committing the stack, and let the log-loss decide which framework your deployment budget serves.
Online Learning for Fast Regimes
Live intraday strategies on Indian futures and options rarely want a full nightly retrain; they want incremental updates. The river framework and scikit-learn's partial_fit interfaces update models stream-wise, which suits rotating Tuesday-to-Friday regimes and candle-by-candle VWAP tracking. The cost is discipline: online models drift quietly, so pair every online learner with a rolling performance monitor and a reset rule. If the regime broke last month, an online model that re-learned the new regime is an asset; an online model that never noticed is a liability that a batch refit would have caught.
The Case for Sticking with One Framework
For a retail project, the best framework is usually the one you already understand deeply. Framework hopping costs real money in debugging every switch. The feature pipeline, the validation harness, and the deployment shell transfer cleanly between tree libraries once the estimators are swapped, so the safe upgrade path is: master XGBoost end to end, then benchmark the alternative on identical folds when a specific problem demands it. Consistency in validation beats cleverness in framework choice every single backtest.
- Tabular: XGBoost, LightGBM, CatBoost.
- Sequential: small LSTM or GRU only after a tree baseline loses.
- Structured inputs: neural stacks with embeddings.
- Fast updates: river-style online learners with a reset rule.
Reference Configurations: One Harness, Many Tuned Bases
The framework choice becomes a small decision when every candidate runs the identical harness: the same feature table, the same calendar split, the same objective, and the same early stopping. Build that harness once, then store each library's tuned reference configuration as a versioned file - the default, the financial default, and the intraday variant - because a configuration written down reproduces a result and a remembered one repeats a story. The comparisons that matter span three axes: training time at your row counts, out-of-time loss at your feature set, and ease of deployment to the live scorer. Keep GPU acceleration off until profiling names it, and let the harness, not the preference, appoint the winner that carries your production path.