Huber M-Estimator

The Huber M-Estimator of Huber (1964) is a robust regression: it minimizes a loss that is quadratic for small residuals, like least squares, and linear for large ones, so that a few extreme returns do not dominate the coefficients.

The formula for the Huber M-Estimator starts from the residuals \(e_{t}\) of the current fit and their robust scale s, the median absolute residual scaled to a standard deviation for normal errors:

\[s = \frac{\text{Median}\left(\left\lvert e_{t}\right\rvert\right)}{0.6745}\]

Each observation gets a weight \(w_{t}\) from Huber’s psi function of its scaled residual \(u_{t}\), which leaves residuals within 1.345 scales untouched and caps larger ones at that bound:

\[u_{t} = \frac{e_{t}}{s}\] \[\psi(u_{t}) = u_{t} \quad \text{if } \left\lvert u_{t}\right\rvert \leq 1.345\] \[\psi(u_{t}) = 1.345 \cdot \operatorname{sign}\left(u_{t}\right) \quad \text{if } \left\lvert u_{t}\right\rvert > 1.345\] \[w_{t} = \frac{\psi(u_{t})}{u_{t}}\]

The coefficients are the weighted least squares fit with the weights in the diagonal matrix W, with y the dependent series and X the independent series plus a constant column, repeated from the OLS fit until the sum of the Huber losses of the scaled residuals stops changing:

\[\hat{\beta} = (X' \cdot W \cdot X)^{-1} \cdot X' \cdot W \cdot y\]

The covariance is Huber’s (1981) first covariance, with k coefficients, n observations and \(\psi_{d}\) the derivative of psi, and every coefficient’s z-statistic divides it by its standard error:

\[K = 1 + \frac{\left(\frac{k}{n}\right) \cdot \operatorname{var}\left(\psi_{d}(u)\right)}{\operatorname{mean}\left(\psi_{d}(u)\right)^{2}}\] \[\operatorname{cov}\left(\hat{\beta}\right) = \frac{K^{2} \cdot s^{2} \cdot \left(\frac{\sum_{t=1}^{n} \psi(u_{t})^{2}}{n - k}\right)}{\left(\frac{\sum_{t=1}^{n} \psi_{d}(u_{t})}{n}\right)^{2}} \cdot (X' \cdot X)^{-1}\] \[z = \frac{\hat{\beta}_{j}}{\text{SE}(\hat{\beta}_{j})}\]

The z-statistics have p-values from the standard normal distribution. The bound of 1.345 keeps 95% of the efficiency of least squares when the errors are normal. Huber’s weights never reach zero, so an extreme outlier keeps some pull, and like every M-estimator it does not protect against an extreme value of an independent ticker (a leverage point).

A linear regression explains one series, the dependent ticker, with a straight line (or plane) through one or more other series, the independent tickers. Each coefficient is the expected change in the dependent ticker for a one-unit change in that independent ticker, holding the others fixed, and the intercept is what remains when all of them are zero. With returns this is the familiar way to estimate how strongly one asset moves with others, such as a beta against an index. The estimators differ in how much a single observation may pull the line: least squares squares every residual, the robust M-estimators weight an observation down once its residual is large.

Also known as: Huber regression, robust regression, M-estimation, robust beta.

In the Finance Toolkit this is get_ols with method="huber", the same function as Ordinary Least Squares (OLS).

Example · XOM, USO · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_ols:

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["XOM", "USO"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

# XOM (the first ticker) is dependent; USO and the Benchmark are independent.
# dependent_ticker and independent_tickers choose others, cov_type='HC1' gives
# heteroskedasticity-robust and cov_type='HAC' (with lags) Newey-West standard errors.
toolkit.econometrics.get_ols(method="huber", include_benchmark=True)

Which returns:

Using Your Own Data

get_ols runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany:

from financetoolkit import Economics, Econometrics

economics = Economics(start_date="2000-01-01")

unemployment = economics.get_unemployment_rate(
    countries=["United States", "Germany"], period="monthly"
)

econometrics = Econometrics(data=unemployment, changes="difference")

econometrics.get_ols()

References

  • Paper Huber, P.J. (1964). “Robust Estimation of a Location Parameter.” Annals of Mathematical Statistics, 35(1), 73-101.
  • Paper Huber, P.J. (1981). “Robust Statistics.” Wiley, section 7.6.
  • Library Referenced against statsmodels’ RLM (Huber M-Estimator, Tukey Bisquare M-Estimator)
Share