Fixed Effects
Fit a Fixed Effects (“within”) estimator explaining a panel of dependent_tickers (the entities) by a regressor x, controlling for entity-specific (and/or time-specific) fixed effects.
Also known as: within estimator, FE, least squares dummy variable (LSDV) estimator.
Unlike this module’s other regression methods (get_ols, get_wls, …), which each compare a handful of individual ticker return series on equal footing, this treats dependent_tickers as a genuine panel of entities – e.g. every stock in the Toolkit instance – observed over time. The regressor x is built in exactly one of two ways (provide exactly one of the two arguments below):
independent_tickers: a COMMON factor (or factors) applied identically to every entity at each date (e.g. a market benchmark, mirroring a Fama-French-style factor regression).independent_column: a PER-ENTITY regressor – each entity’s own value of a different historical data column (e.g. does"Volume"explain"Return", across the panel).
Fixed Effects removes any purely entity-specific, time-invariant characteristic (e.g. a stock’s typical risk premium) before estimating the regressor’s coefficient(s), by demeaning every variable by its entity’s mean. See panel_data_model.get_fixed_effects for the full formula and references.
No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Fixed Effects for you. Just ask in plain English.
Calculate the Fixed Effects in Python
The Fixed Effects is available in the Econometrics module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_fixed_effects as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(["AAPL", "MSFT"], api_key="FINANCIAL_MODELING_PREP_KEY")
toolkit.econometrics.get_fixed_effects(
independent_tickers="Benchmark", period="weekly"
)
Which returns:
| Coefficient | Std. Error | t-Statistic | P-Value | |
|---|---|---|---|---|
| Benchmark | 1.0772 | 0.0331 | 32.5314 | 0.0000 |
| Entity Effect: AAPL | 0.0022 | nan | nan | nan |
| Entity Effect: MSFT | 0.0017 | nan | nan | nan |
Parameters
get_fixed_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. - 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”.
- entity_effects (bool, optional): Whether to control for time-invariant entity-specific characteristics. Defaults to True.
- time_effects (bool, optional): Whether to control for entity-invariant, time-specific shocks. Defaults to False.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to None.
Related Panel Data
The Econometrics module page introduces the module, and the sidebar lists all of its functions.