Quantile Regression
Fit a Quantile Regression of dependent_ticker on independent_tickers at quantile tau.
Also known as: QR.
For more information about the method, see regression_model.get_quantile_regression.
Quantile Regression in Python
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_quantile_regression as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(["AAPL", "MSFT"], api_key="FINANCIAL_MODELING_PREP_KEY")
# AAPL (the first ticker) is dependent; MSFT and Benchmark are independent
toolkit.econometrics.get_quantile_regression(
independent_tickers=["MSFT", "Benchmark"], tau=0.5, period="weekly"
)
Which returns:
| Coefficient | Std. Error | |
|---|---|---|
| Intercept | 0.0007 | 0.0021 |
| MSFT | 0.3593 | 0.0854 |
| Benchmark | 0.6885 | 0.1037 |
Parameters
The function accepts the following parameters:
- dependent_ticker (str | None, optional): The dependent (predicted) asset. Defaults to None, meaning the Toolkit instance’s first ticker.
- independent_tickers (str | list[str] | None, optional): The independent
(predictor) asset(s). Defaults to None, meaning every other ticker in
the Toolkit instance besides
dependent_ticker. - include_benchmark (bool, optional): Whether to include “Benchmark” in the default independent ticker(s) (has no effect when independent_tickers is given explicitly). Defaults to False.
- tau (float, optional): The quantile to fit, in (0, 1). Defaults to 0.5 (the median).
- period (str, optional): The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”.
- column (str, optional): The historical data column to regress on. Defaults to “Return”.
- add_constant (bool, optional): Whether to include an intercept. Defaults to True.
- n_bootstrap (int, optional): The number of bootstrap resamples used for coefficient
standard errors, overriding
statsmodels’ default analytic (kernel density-based) standard errors. Defaults to 0 (use the analytic standard errors). - rounding (int | None, optional): The number of decimals to round the results to. Defaults to None.