arch: ARCH for Python
ARCH is a Python library providing tools for financial econometrics, focusing on Autoregressive Conditional Heteroskedasticity (ARCH) models, unit root tests, cointegration analysis, and bootstrapping. It is actively developed with regular releases, with the current version being 8.0.0, requiring Python 3.10 or newer for optimal compatibility and performance.
Warnings
- breaking Version 8.0.0 and later require Python 3.10+. Older Python versions are no longer supported. The build system has also moved from setuptools to Meson.
- gotcha When using `arch` for financial econometrics, proper handling and preparation of time-series data (e.g., ensuring correct datetime indices, handling missing values, and calculating returns appropriately) is crucial for valid model results. External libraries like `pandas_datareader` (used in quickstart) are not core dependencies and must be installed separately.
- gotcha Mixing `pip` installations with system-managed Python packages (e.g., via `pacman` on Arch Linux) can lead to conflicts, especially during Python version updates. This can break virtual environments and lead to 'module not found' errors.
Install
-
pip install arch -
pip install 'arch[all]'
Imports
- arch_model
from arch import arch_model
- univariate
from arch import univariate
- unitroot
from arch import unitroot
Quickstart
import datetime as dt
import pandas_datareader.data as web
from arch import arch_model
# Fetch financial data (example: FTSE 100 index)
# Requires 'pandas_datareader' to be installed (pip install pandas_datareader)
st = dt.datetime(1990,1,1)
en = dt.datetime(2014,1,1)
data = web.DataReader('^FTSE', 'yahoo', start=st, end=en)
returns = 100 * data['Adj Close'].pct_change().dropna()
# Initialize and fit an ARCH model
am = arch_model(returns, vol='Garch', p=1, o=1, q=1, dist='StudentsT')
res = am.fit(update_freq=5)
print(res.summary())