Fully Modified OLS
The Fully Modified OLS (FMOLS) of Phillips and Hansen (1990) corrects the OLS regression afterwards instead of adding terms to it: it removes the part of the dependent price that the regressor’s shocks explain in the long run, and the bias that the correlation of those shocks with the errors leaves in the slope, with nonparametric estimates of the long-run covariances.
The formula for the Fully Modified OLS starts from the static OLS regression of the dependent on the independent price and pairs its residual hat(u_t) with the change of the regressor Delta \(B_{t}\) into \(w_{t}\), for \(t = 2\), …, T:
\[A_{t} = \alpha + \beta \cdot B_{t} + u_{t}\]It estimates the covariance hat(Sigma) of \(w_{t}\), the weighted sum hat(Lambda) of its autocovariances up to the truncation lag l, and from them the long-run covariance hat(Omega) and the one-sided long-run covariance hat(Delta):
\[\hat{\Sigma} = \frac{\sum_{t=2}^{T} w_{t} \cdot w'_{t}}{n}\] \[\hat{\Lambda} = \sum_{s=1}^{l} \frac{\left(1 - \frac{s}{l + 1}\right) \cdot \sum_{t=s + 2}^{T} w_{t-s} \cdot w'_{t}}{n}\] \[\hat{\Omega} = \hat{\Sigma} + \hat{\Lambda} + \hat{\Lambda}'\] \[\hat{\Delta} = \hat{\Sigma} + \hat{\Lambda}\]The correction removes from the dependent price what the regressor’s shocks explain in the long run, and the bias term hat(delta_plus) from the slope:
\[A_{\text{plus},t} = A_{t} - \left(\frac{\hat{\omega}_{1,2}}{\hat{\omega}_{2,2}}\right) \cdot \Delta B_{t}\] \[\hat{\delta}_{\text{plus}} = \hat{\Delta}_{2,1} - \frac{\hat{\Delta}_{2,2} \cdot \hat{\omega}_{2,1}}{\hat{\omega}_{2,2}}\] \[\hat{\theta} = (Z' \cdot Z)^{-1} \cdot (Z' \cdot A_{\text{plus}} - n \cdot e_{2} \cdot \hat{\delta}_{\text{plus}})\]The covariance of the estimates scales the OLS one by the long-run variance of the errors given the regressor’s shocks:
\[\omega_{c} = \hat{\omega}_{1,1} - \hat{\omega}_{1,2} \cdot \hat{\omega}_{2,2}^{-1} \cdot \hat{\omega}_{2,1}\] \[\operatorname{cov}\left(\hat{\theta}\right) = \omega_{c} \cdot (Z' \cdot Z)^{-1}\]Where \(A_{t}\) and \(B_{t}\) are the prices of the dependent and the independent ticker, alpha the constant and beta the long-run slope (the hedge ratio), T the number of observations and \(n = T - 1\), l the truncation lag, hat(omega_{i,j}) and hat(Delta_{i,j}) the elements of hat(Omega) and hat(Delta), hat(theta) the estimates of the constant and the slope, \(Z_{t}\) the regressors 1 and \(B_{t}\) and \(e_{2}\) the vector (0, 1)’. The slope’s t-statistic is standard normal, with a two-sided p-value: a p-value below the significance level (0.05 for the 5% level) means the hedge ratio differs from 0. The estimate depends on the truncation lag l, and in small samples it can keep part of the bias that it corrects asymptotically.
When two prices are cointegrated, the OLS slope of one on the other is consistent, it converges to the true long-run relation even faster than in an ordinary regression, but its standard errors and t-statistics are not valid: the regression errors are autocorrelated and correlated with the shocks of the regressor, which biases the slope in finite samples and makes its distribution non-standard. A cointegrating regression estimator corrects this, so that the slope, the hedge ratio of a pairs trade, comes with a standard error that can be used to judge it. The estimators assume that the pair is cointegrated; a cointegration test comes first.
Also known as: FMOLS, fully modified ordinary least squares, Phillips-Hansen estimator.
In the Finance Toolkit this is get_cointegrating_regression with method="fully_modified_ols", the same function as Cointegrating Regression.
Example · KO, PEP · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_cointegrating_regression:
from financetoolkit import Toolkit
toolkit = Toolkit(
["KO", "PEP"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
regression = toolkit.econometrics.get_cointegrating_regression(method="fully_modified_ols")
regression[["Intercept", "Slope", "Slope Standard Error", "Slope P-Value"]]
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”. | "weekly" |
column | str | The historical data column to use. Defaults to “Adj Close”. | "Return" |
method | str | The estimator. Options are: “dynamic_ols” (Dynamic OLS), “fully_modified_ols” (Fully Modified OLS), “canonical_cointegrating_regression” (Canonical Cointegrating Regression). Defaults to “dynamic_ols”. | "dynamic_ols" |
leads_lags | int | The number of leads and of lags of the differenced regressor in “dynamic_ols”. Defaults to None, chosen by the BIC. | None, chosen by the BIC |
bandwidth | int | The truncation lag l of the long-run (co)variances. Defaults to the Schwert (1989) rule of thumb, capped at (n - 5) // 3 for short samples. | 0.02 |
include_benchmark | bool | Whether to include “Benchmark” among the tickers paired up. Defaults to False. | True |
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 |
Which returns:
| Item | Intercept | Slope | Slope Standard Error | Slope P-Value |
|---|---|---|---|---|
| ('KO', 'PEP') | 36.1507 | 0.1397 | 0.0691 | 0.0431 |
| ('PEP', 'KO') | 117.5590 | 0.4875 | 0.2437 | 0.0455 |
2 rows
Using Your Own Data
get_cointegrating_regression 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_cointegrating_regression()
References
- Paper Phillips, P.C.B. and Hansen, B.E. (1990). “Statistical Inference in Instrumental Variables Regression with I(1) Processes.” Review of Economic Studies, 57(1), 99-125.
- Library Referenced against arch’s FullyModifiedOLS (Fully Modified OLS)