Random Effects
Fit a Random Effects estimator explaining a panel of dependent_tickers (the entities) by a regressor x, via Swamy-Arora feasible Generalized Least Squares.
Also known as: RE, GLS panel estimator, Swamy-Arora estimator.
See get_fixed_effects for how dependent_tickers/independent_tickers/ independent_column are shaped into a panel, and panel_data_model.get_random_effects for the full estimator formula, references, and how it compares to Fixed Effects. Unlike Fixed Effects, Random Effects retains and estimates a single, population-average intercept rather than one intercept per entity – more efficient than Fixed Effects if entity effects are indeed uncorrelated with the regressor(s) (see get_hausman_test to check that assumption).
Random Effects in Python
get_random_effects is part of the Econometrics module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_random_effects as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
["AAPL", "MSFT", "AMZN"], api_key="FINANCIAL_MODELING_PREP_KEY"
)
toolkit.econometrics.get_random_effects(
independent_column="Volume", period="weekly"
)
Which returns:
| Coefficient | Std. Error | t-Statistic | P-Value | |
|---|---|---|---|---|
| Intercept | 0.0094 | 0.0012 | 7.7341 | 0.0000 |
| Volume | -0.0000 | 0.0000 | -5.1258 | 0.0000 |
Parameters
get_random_effects accepts the following parameters:
- independent_tickers (str | list[str] | None, optional): The factor
ticker(s), whose
columnvalues are broadcast identically to every entity at each date. Mutually exclusive withindependent_column. Note: since thisToolkitinstance’s historical data is aligned onto a common calendar across tickers, a broadcast factor’s entity mean is identical for every entity, leaving no between-entity variation to identify Random Effects’ between-regression step – preferindependent_columnhere unlessdependent_tickersgenuinely differ in their date coverage (e.g. different listing histories). - independent_column (str | None, optional): A different historical data
column, taken per-entity from each of
dependent_tickers’ own data, to use as the regressor. Mutually exclusive withindependent_tickers. - dependent_tickers (str | list[str] | None, optional): The panel of
entity tickers to explain. Defaults to None, meaning every ticker in
the
Toolkitinstance (other thanindependent_tickers, if given). - period (str, optional): The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”.
- column (str, optional): The dependent variable’s historical data column. Defaults to “Return”.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to None.