Durbin-Watson Test
Calculate the Durbin-Watson statistic for first-order autocorrelation in the residuals of a regression of dependent_ticker on independent_tickers.
OLS standard errors assume that the residuals of consecutive periods are uncorrelated. The Durbin-Watson statistic compares each residual with the one before it.
The formula is as follows:
\[\text{DW} = \text{SUM\_\{t} = \text{2\}} ^{\text{\{n\}}} ((e_{t} - e_{t-1}) ^{2}) / \text{SUM\_\{t} = \text{1\}} ^{\text{\{n\}}} (e_{t} ^{2})\]-
e_t are the residuals of the OLS regression of the dependent ticker’s
column(Return by default) on the independent tickers’column -
Interpretation: DW < 1.5 positive autocorrelation likely, DW > 2.5 negative autocorrelation likely, otherwise no strong evidence
The statistic ranges from 0 to 4. A value near 2 means no first-order autocorrelation; values below 2 point to positive autocorrelation (consecutive residuals tend to share the same sign, often a sign of an omitted trend or lagged effect) and values above 2 to negative autocorrelation (residuals tend to alternate in sign). Like heteroskedasticity, autocorrelation leaves the coefficients unbiased but makes the standard errors unreliable; a “HAC” cov_type in get_ols, or get_gls with an AR(1) omega, are common remedies. There is no exact p-value: the returned interpretation is a rule of thumb (below 1.5 is likely positive, above 2.5 likely negative autocorrelation).
For more information about the method, see the following paper:
- Durbin, J., & Watson, G.S. (1950). “Testing for Serial Correlation in Least Squares Regression I.” Biometrika, 37(3/4), 409-428.
Also known as: DW statistic.
Durbin-Watson Test in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_durbin_watson_test as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
["HD", "LOW"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2025-01-01",
end_date="2025-12-31",
)
# HD (the first ticker) is dependent; LOW is independent
toolkit.econometrics.get_durbin_watson_test()
Or, after setting up the Finance Toolkit MCP, ask:
Did a regression of Home Depot's daily returns on Lowe's have autocorrelated residuals in 2025, according to Durbin-Watson?
Which returns:
| Value | |
|---|---|
| Durbin-Watson Statistic | 1.8584 |
| Interpretation | No Strong Evidence |
Using Your Own Data
get_durbin_watson_test 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_durbin_watson_test()
Parameters
get_durbin_watson_test accepts the following parameters.
| 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 in the underlying regression. Defaults to True. | False |
rounding | int | None | The number of decimals to round the results to. Defaults to None. | 2 |