Autocorrelation (ACF)
Calculate the Autocorrelation Function (ACF) of each asset’s daily returns for a range of lags.
The ACF measures the correlation between a return series and a lagged version of itself. A significant ACF at a given lag indicates that returns are not fully independent over time, which is relevant for assessing return predictability and volatility clustering (as opposed to a trading-signal use case, which is why this lives in the Risk module rather than Technicals).
Autocorrelation (ACF) in Python
get_autocorrelation is part of the Risk module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_autocorrelation as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(["AMZN", "TSLA"], api_key="FINANCIAL_MODELING_PREP_KEY")
toolkit.risk.get_autocorrelation()
Which returns:
| AMZN | TSLA | Benchmark | |
|---|---|---|---|
| 1 | -0.0109 | -0.0306 | -0.0366 |
| 2 | -0.0013 | 0.0121 | 0.0066 |
| 3 | -0.0216 | 0.0006 | -0.0571 |
| 4 | 0.01 | 0.0117 | -0.0344 |
| 5 | -0.0063 | -0.0302 | 0.0002 |
| 6 | 0.0018 | 0.0298 | -0.022 |
| 7 | -0.0451 | 0.0209 | -0.0076 |
| 8 | -0.0281 | 0.0092 | -0.013 |
| 9 | 0.0017 | 0.0675 | 0.0529 |
| 10 | -0.0162 | -0.0293 | -0.0133 |
Parameters
get_autocorrelation accepts the following parameters:
- lags (int, optional): The number of lags to calculate the ACF for. Defaults to 10.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to 4.