Logistic Regression
Fit a Logistic Regression (Logit model) of whether dependent_ticker’s return is positive on independent_tickers.
The dependent variable is turned into a binary outcome (1 when the return is positive, 0 otherwise) and the model estimates the probability of that outcome through the logistic (sigmoid) function, which maps any value onto the 0 to 1 range.
The formula is as follows:
\[\text{yₜ} = 1 \;\text{if the dependent ticker's}\; \text{column} (\text{Return by default}) \text{is above}\; 0,\;\; \text{else 0}\] \[P(\text{yₜ} = 1 | \text{xₜ}) = 1 / (1 + \exp(- \text{xₜ'beta})),\;\; \text{with xₜ the independent tickers' column plus a constant}\] \[\text{betâ} = \text{argmax}\; \text{Σ} \left[\text{yₜ} \cdot \ln(\text{pₜ}) + (1 - \text{yₜ}) \cdot \ln(1 - \text{pₜ})\right],\;\; \text{solved by Newton-Raphson (statsmodels Logit)}\] \[\text{Pseudo}\; R ^{2} = 1 - \text{ln}\; L (\text{betâ}) / \text{ln}\; \text{L₀} (\text{McFadden}),\;\; \text{with L₀ the likelihood of a constant-only model}\]The model is fitted by Maximum Likelihood. Coefficients are log-odds: a one-unit increase in an independent ticker changes the log-odds of a positive return by that coefficient, holding the others fixed, so a positive coefficient means a higher probability of a positive return. This answers “does this asset tend to be up when the others move this way” rather than “by how much”, which is what get_ols estimates. get_probit_regression is the closely related alternative with a normal instead of a logistic link.
The coefficients are per unit of the independent ticker’s return, and a unit is a return of 100%: a coefficient of 90 on the benchmark means the log-odds of an up period rise by about 0.9 for every 1% the benchmark moves. With returns of the same period as regressors the model describes co-movement and predicts nothing; a forecast needs regressors known in advance, such as the returns of the previous period.
For more information about the method, see the following paper:
- Berkson, J. (1944). “Application of the Logistic Function to Bio-Assay.” Journal of the American Statistical Association, 39(227), 357-365.
Also known as: logit model, logit regression.
Logistic Regression in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_logistic_regression as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
["AAPL"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2025-01-01",
end_date="2025-12-31",
)
# AAPL (the first ticker) is dependent; the Benchmark is independent
toolkit.econometrics.get_logistic_regression(include_benchmark=True)
Or, after setting up the Finance Toolkit MCP, ask:
How did the daily return of the S&P 500 change the odds of Apple rising on a day in 2025, according to a logit model?
Which returns:
| Coefficient | Std. Error | z-Statistic | P-Value | |
|---|---|---|---|---|
| Intercept | -0.0275 | 0.15 | -0.1836 | 0.8543 |
| Benchmark | 164.846 | 25.4127 | 6.4868 | 0 |
Using Your Own Data
get_logistic_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_logistic_regression()
Parameters
get_logistic_regression accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
dependent_ticker | str | None | The dependent asset (whose up/down direction is predicted). 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 derive returns from. Defaults to “Return”. | "Return" |
add_constant | bool | Whether to include an intercept. Defaults to True. | False |
rounding | int | None | The number of decimals to round the results to. Defaults to None. | 2 |