Tukey Bisquare M-Estimator
The Tukey Bisquare M-Estimator of Beaton and Tukey (1974) is a robust regression whose weights fall smoothly to zero: an observation whose residual lies beyond about 4.7 standard deviations is ignored entirely.
The formula for the Tukey Bisquare 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 Tukey’s bisquare psi function of its scaled residual \(u_{t}\), which shrinks residuals more the larger they are and sets those beyond 4.685 scales to zero:
\[u_{t} = \frac{e_{t}}{s}\] \[\psi(u_{t}) = u_{t} \cdot \left(1 - \left(\frac{u_{t}}{4.685}\right)^{2}\right)^{2} \quad \text{if } \left\lvert u_{t}\right\rvert \leq 4.685\] \[\psi(u_{t}) = 0 \quad \text{if } \left\lvert u_{t}\right\rvert > 4.685\] \[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 bisquare 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 4.685 keeps 95% of the efficiency of least squares when the errors are normal. Ignoring the largest residuals makes it the most resistant to outliers of these estimators, but its loss is not convex, so the fit depends on its start and can settle on another solution when the data are far from a straight line.
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: Tukey bisquare regression, Tukey biweight, biweight regression, robust regression.
In the Finance Toolkit this is get_ols with method="bisquare", 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="bisquare", include_benchmark=True)
| Parameter | Type | Description | Example |
|---|---|---|---|
dependent_ticker | str | None | The dependent (predicted) asset. Defaults to None, meaning the Toolkit instance’s first ticker. | "AAPL" |
independent_tickers | str | list[str] | None | The independent (predictor) asset(s). Defaults to None, meaning every other ticker in the Toolkit instance besides dependent_ticker. | ["MSFT", "Benchmark"] |
include_benchmark | bool | Whether to include “Benchmark” in the default independent ticker(s) (has no effect when independent_tickers is given explicitly). Defaults to False. | True |
period | str | The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”. | "weekly" |
column | str | The historical data column to regress on. Defaults to “Return”. | "Return" |
add_constant | bool | Whether to include an intercept. Defaults to True. | False |
cov_type | str | Which covariance estimator to use for the standard errors. Options are: “nonrobust” (classical, assumes homoskedastic errors), “HC0”, “HC1”, “HC2”, “HC3” (heteroskedasticity-robust), “cluster” (cluster-robust, requires clusters), “HAC” (Newey-West, heteroskedasticity-and-autocorrelation-consistent, uses lags). Use get_heteroskedasticity_test to check for heteroskedasticity and get_ljung_box_test to check for autocorrelation first. Defaults to “nonrobust”. | "HC3" |
clusters | pd.Series | None | The cluster label for each observation (e.g. a coarser time bucket derived from the return index, to correct for within-period correlation), required when cov_type="cluster". Aligned to the regression’s own index before use, so it may be indexed by the full period index even though the regression drops periods with missing data. Defaults to None. | None |
lags | int | None | The maximum lag to include when estimating the HAC (Newey-West) covariance matrix, only used when cov_type="HAC". Defaults to None, meaning the Newey & West (1994) rule of thumb floor(4 * (n / 100)^(2/9)) with n the number of observations. | 2 |
rounding | int | None | The number of decimals to round the results to. Defaults to None. | 2 |
show_columns | str | list[str] | None | The columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column. | None, which keeps every column |
method | str | The estimator. Options are: “ols” (Ordinary Least Squares, the least squares fit), “huber” (Huber M-Estimator, robust regression with Huber’s weights), “bisquare” (Tukey Bisquare M-Estimator, robust regression with Tukey’s bisquare weights). The robust regressions take the default cov_type only. Defaults to “ols”. | "ols" |
Which returns:
| Item | Coefficient | Standard Error | t-Statistic | P-Value |
|---|---|---|---|---|
| Intercept | 0.0004 | 0.0003 | 1.0325 | 0.3018 |
| USO | 0.4724 | 0.0169 | 27.8890 | 0.0000 |
| Benchmark | 0.3576 | 0.0328 | 10.8876 | 0.0000 |
3 rows
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 Beaton, A.E. and Tukey, J.W. (1974). “The Fitting of Power Series, Meaning Polynomials, Illustrated on Band-Spectroscopic Data.” Technometrics, 16(2), 147-185.
- Paper Huber, P.J. (1981). “Robust Statistics.” Wiley, section 7.6.
- Library Referenced against statsmodels’ RLM (Huber M-Estimator, Tukey Bisquare M-Estimator)