Concept
Bagging
Bagging is a Machine Learning concept. The Library holds 1 implementation — a working definition you can pull into Quant.
Top Bagging indicator
The top custom implementation, built on the original standard Bagging formula.
1 total
What is bagging?
Bagging, short for bootstrap aggregating, is an ensemble method that trains many copies of the same model on different bootstrap samples of the training data and averages their predictions (or takes a majority vote for classification). It was introduced by Leo Breiman in 1996. Each bootstrap sample is drawn from the original training set with replacement, so each model sees a slightly different version of history and makes slightly different errors; averaging washes much of that disagreement out.
The method exists to attack variance. A flexible learner such as a deep decision tree fits its particular training sample aggressively, so retraining on a slightly different sample can produce a very different model. Bagging does not make any single model better; it makes the ensemble's output more stable by averaging over the sampling noise. Bias is largely unchanged, which is why bagging helps high-variance learners a lot and stable learners such as heavily regularized linear models very little.
Traders care because financial prediction is exactly the setting where variance dominates: signal-to-noise is low, effective sample sizes are small, and a model refit on a shifted window can flip its conclusions. Bagged models tend to produce steadier signals across refits, and the bootstrap structure yields a useful byproduct, out-of-bag predictions, where each observation is scored only by the models that never trained on it. One caution is specific to markets: standard bootstrap resampling assumes roughly independent observations, and overlapping or autocorrelated financial samples violate that, so block bootstrap variants are often preferred.
How it's calculated
The canonical form averages B models, each trained on an independent bootstrap resample of the training set.
Each bootstrap sample omits roughly 36.8 percent of the original observations on average; those out-of-bag observations provide a built-in validation estimate.
For classification, averaging predicted probabilities is a common alternative to hard voting.
With autocorrelated financial series, block or stationary bootstrap variants resample contiguous chunks to respect serial dependence.
How traders use it
- Stabilizing noisy signal models: bagging a high-variance learner over bootstrap samples of the training window tends to reduce the signal flip-flopping that plagues single models refit on rolling data, at the cost of extra computation.
- Out-of-bag evaluation: the out-of-bag error gives a nearly free estimate of generalization performance, useful when data is too scarce to sacrifice a large holdout, though it does not replace proper walk-forward testing on time-ordered data.
- As the engine inside random forests: bagging plus per-split feature randomness is the random forest recipe, and most practical exposure to bagging in trading comes through that algorithm.
- Guarding against sample sensitivity: comparing predictions across the bagged members reveals how much a conclusion depends on which observations happened to be sampled, a cheap robustness check related in spirit to model overfitting diagnostics.
- Honest limitation: bagging cannot fix a biased or information-free feature set, and averaging many models trained on the same flawed data produces a confident version of the same flaw.
Bagging vs. other ensemble approaches
Random Forest: A random forest is bagging applied to trees with an extra decorrelation trick, random feature subsets at each split; plain bagging uses the full feature set in every model.
Gradient Boosting: Boosting trains models sequentially, each correcting the last, and mainly reduces bias; bagging trains models independently in parallel and mainly reduces variance.
Model stacking: Stacking combines different model types through a trained meta-learner; bagging combines many instances of one model type through simple averaging or voting.
Ensemble voting of signals: Signal voting aggregates heterogeneous trading rules at the decision level; bagging is a statistical procedure that manufactures its ensemble from one learner and resampled data.
Concept family
Machine Learning
32 concepts mapped · 32 in the Library
Bagging FAQ
When does bagging actually help?
When the base learner is unstable, meaning small changes in training data change its predictions materially. Deep decision trees are the classic beneficiary; stable, heavily regularized models gain little.
How many models should be bagged?
Performance typically plateaus somewhere in the tens to hundreds of replicates, and adding more mostly costs computation. Monitoring out-of-bag error as B grows shows where the curve flattens.
Is the ordinary bootstrap valid for time series?
Not strictly, because it destroys serial dependence. Block bootstrap variants, which resample contiguous segments, are the standard adaptation for autocorrelated financial data.
Does bagging prevent overfitting?
It reduces the variance component of overfitting but leaves bias and data-snooping problems untouched. A bagged model validated on the training period can still fail out of sample.
Build Bagging your way.
Quant writes, tests, and refines it with you — then it runs on LuxAlgo charting or ports to TradingView.
