Skip to main content
Version: v5

openbb-econometrics

openbb-econometrics adds the obb.econometrics namespace: 21 commands that run econometric models and tests on data you pass in. It fetches nothing itself. The input is any tabular dataset, such as the results of a provider command, a pandas DataFrame, or a list of dictionaries, and every command returns an OBBject.

Installation​

pip install openbb-econometrics
openbb-build

The package depends on openbb-core[pandas], statsmodels, linearmodels, scipy, and arch.

Each command is also a POST endpoint under /api/v1/econometrics/ when the environment is served with openbb-api.

Commands​

GroupCommandModel or test
Toolscorrelation_matrixPearson, Kendall, or Spearman correlation of every numeric column
Toolssummary_statisticsCount, mean, standard deviation, quartiles, skew, and excess kurtosis per column
Regressionols_regressionOLS coefficient table with standard errors, t-statistics, p-values, and 95% intervals
Regressionols_regression_summaryOLS fit statistics: R², adjusted R², F-statistic, AIC, BIC, log-likelihood, and the statsmodels text summary
DiagnosticsautocorrelationDurbin-Watson statistic on OLS residuals
Diagnosticsresidual_autocorrelationBreusch-Godfrey LM test on OLS residuals
DiagnosticsheteroskedasticityBreusch-Pagan and White tests
DiagnosticsnormalityJarque-Bera test on OLS residuals
Diagnosticsvariance_inflation_factorVIF for each column
Time seriesunit_rootAugmented Dickey-Fuller test
Time serieskpssKPSS stationarity test
Time seriescointegrationEngle-Granger two-step test for every pair of columns
Time seriescointegration_johansenJohansen trace and maximum-eigenvalue tests
Time seriescausalityGranger causality test
Time seriesgarchGARCH-family conditional volatility model
Panelpanel_pooledPooled OLS
Panelpanel_betweenBetween estimator
Panelpanel_fixedFixed effects, entity and optionally time
Panelpanel_random_effectsOne-way random effects
Panelpanel_first_differenceFirst-difference estimator
Panelpanel_fmacFama-MacBeth

ols_regression, ols_regression_summary, and the panel estimators accept a cov_type argument for heteroskedasticity-consistent standard errors: HC0 through HC3 for OLS, and "robust" for the panel models. The panel commands expect data indexed by entity and time, so pass a DataFrame with a two-level MultiIndex.

Example: factor regression​

This example regresses the daily excess return of the XLE energy ETF on the Fama-French three factors. Prices come from obb.cboe, factors from obb.famafrench, and neither needs a credential. Fama-French returns are in percent, so the ETF return is scaled to match.

from openbb import obb

prices = obb.cboe.equity.historical(symbol="XLE", start_date="2022-01-01").to_df()
factors = obb.famafrench.factors(frequency="daily", start_date="2022-01-01").to_df()

returns = prices["close"].pct_change().mul(100).rename("xle")
data = factors.join(returns, how="inner").dropna()
data["xle_excess"] = data["xle"] - data["rf"]

ols = obb.econometrics.ols_regression(
data=data,
y_column="xle_excess",
x_columns=["mkt_rf", "smb", "hml"],
cov_type="HC1",
)
ols.to_df()

The result has one row per regressor, including the intercept const. The same arguments work with the diagnostic commands:

fit = obb.econometrics.ols_regression_summary(
data=data, y_column="xle_excess", x_columns=["mkt_rf", "smb", "hml"]
)
print(fit.results.summary)

obb.econometrics.heteroskedasticity(
data=data, y_column="xle_excess", x_columns=["mkt_rf", "smb", "hml"]
).to_df()

Stationarity and causality​

unit_root and kpss test opposite null hypotheses: ADF assumes a unit root, KPSS assumes stationarity. Running both on the same column gives a clearer answer than either alone.

obb.econometrics.unit_root(data=data, column="xle", regression="c")
obb.econometrics.kpss(data=data, column="xle", regression="c")
obb.econometrics.causality(data=data, y_column="xle", x_column="mkt_rf", lag=5)

kpss reports p_value_interpolated=False when the statistic falls outside statsmodels' lookup table, meaning the true p-value is more extreme than the one reported. cointegration tests every pair of the columns you name, and cointegration_johansen tests them jointly and reports one row per cointegration rank.

GARCH volatility models​

garch fits a model from the GARCH family with the arch library and returns the estimated conditional volatility for each observation. It is best applied to a return series, not to prices.

ArgumentValuesDefault
meanConstant, Zero, LS, AR, ARX, HAR, HARXConstant
lagsLag order for the AR, ARX, HAR, and HARX means0
x_columnsExogenous regressors for the LS, ARX, and HARX meansNone
volGARCH, ARCH, EGARCH, FIGARCH, APARCH, HARCHGARCH
pOrder of the symmetric ARCH term1
oOrder of the asymmetric (leverage) term0
qOrder of the lagged volatility term1
powerPower applied to volatility; 2.0 is standard GARCH2.0
distributionnormal, t, skewt, gednormal

The fitted parameters, AIC, BIC, and log-likelihood are returned in extra["results_metadata"] rather than in results.

egarch = obb.econometrics.garch(
data=data,
column="xle",
vol="EGARCH",
o=1,
distribution="t",
)
egarch.to_df()
egarch.extra["results_metadata"]

Chart​

With openbb-charting installed, correlation_matrix accepts chart=True. It is the only command in this extension with a chart view.

Go to the reference for every parameter and returned field.