Huber Loss for Noisy Financial Targets
Squared error punishes a single huge outlier so severely that it can dominate an entire training run; Huber loss behaves like squared error for small mistakes and like absolute error for large ones, which is exactly what noisy, fat-tailed financial targets need.
Prerequisites: Loss Functions for Regression
Train a neural network to predict next-day returns using squared error, and one data-cleaning slip — a stock split not adjusted for, a fat-finger print, an earnings-day 40% gap — creates a single residual that dwarfs every other example in the dataset. Because squared error squares that residual, one bad target can contribute more to the total loss, and to the gradient, than thousands of ordinary days combined. The optimizer chases that one point and distorts the fit everywhere else. Huber loss is designed specifically to stop this from happening.
The analogy: a car's suspension over a pothole
A stiff suspension gives a precise, responsive ride over small bumps — every little variation in the road is transmitted faithfully. But hit one genuine pothole at speed and that same stiffness slams the whole car. A good suspension is nonlinear: firm and precise for small bumps, softer and more forgiving once the bump crosses a certain size, so one bad pothole doesn't define the whole ride. Huber loss gives a model the same kind of suspension: precise (squared-error-like) for ordinary residuals, and deliberately gentler (absolute-error-like) once a residual exceeds a threshold.
The formula
For a residual (true value minus prediction) and a threshold :
In words: for small residuals (within of the target), use ordinary squared error, which is smooth and gives a gradient proportional to the residual itself. Beyond , switch to a term that grows only linearly in rather than quadratically — so a residual of 100 contributes only about 10 times more loss than a residual of 10, not 100 times more. The two pieces are constructed to meet smoothly (same value and same slope) exactly at .
Worked example 1: a normal-sized error and a huge outlier,
Ordinary residual (within the threshold): — same as plain squared error would give.
Outlier residual (a badly cleaned data point): squared error would give . Huber loss instead gives — over 10 times smaller than squared error's penalty, and critically, the gradient at this point is just (constant, the same as at or ), not as it would be under squared error. The optimizer takes a normal-sized step toward fixing this point instead of a step 20 times larger than usual.
Worked example 2: comparing total loss contribution across a small batch
Batch of 4 residuals: (the last one an outlier), with .
Squared error: — the outlier alone accounts for , or 99.8% of total loss. The other three points are numerically irrelevant to the gradient.
Huber loss (): the first three, within threshold, contribute . The outlier contributes . Total — the outlier still dominates, but at a ratio of about 76:1 rather than squared error's roughly 590:1, leaving the three normal points a meaningful share of the gradient.
Huber loss is quadratic (like squared error) for residuals inside a threshold and linear (like absolute error) beyond it, giving small errors a smooth, informative gradient while capping how much a single large outlier can dominate training — a direct fix for the fat-tailed, occasionally-corrupted targets common in financial data.
What this means in practice
Huber loss is the standard robust regression choice wherever targets are numeric and noisy — return prediction, volatility forecasting, PnL regression — and is available in every framework (nn.SmoothL1Loss in PyTorch is a close variant). The threshold is a real hyperparameter to tune: set it too small and Huber loss behaves almost entirely like absolute error, discarding useful curvature information from ordinary-sized residuals; set it too large and it behaves almost entirely like squared error, reintroducing exactly the outlier sensitivity it exists to fix.
The common confusion is thinking Huber loss removes the influence of outliers. It does not — the outlier from worked example 2 still contributed more loss than any single ordinary point, and still pulls the gradient in its direction. What Huber loss removes is the quadratic amplification of that influence; a residual 20 times larger than normal still counts noticeably more, just proportionally rather than by a factor of 400. For genuinely corrupted data, the fix is cleaning the data, not the loss function.
Related concepts
Practice in interviews
Further reading
- Huber, Robust Estimation of a Location Parameter (1964)