Skip to main content

ARCH for Python

Project description

arch

arch

Autoregressive Conditional Heteroskedasticity (ARCH) and other tools for financial econometrics, written in Python (with Cython and/or Numba used to improve performance)

Metric
Latest Release PyPI version
conda-forge version
Continuous Integration Build Status
Appveyor Build Status
Coverage codecov
Code Quality Codacy Badge
codebeat badge
Citation DOI
Documentation Documentation Status

Module Contents

Python 3

arch is Python 3 only. Version 4.8 is the final version that supported Python 2.7.

Documentation

Documentation from the main branch is hosted on my github pages.

Released documentation is hosted on read the docs.

More about ARCH

More information about ARCH and related models is available in the notes and research available at Kevin Sheppard's site.

Contributing

Contributions are welcome. There are opportunities at many levels to contribute:

  • Implement new volatility process, e.g., FIGARCH
  • Improve docstrings where unclear or with typos
  • Provide examples, preferably in the form of IPython notebooks

Examples

Volatility Modeling

  • Mean models
    • Constant mean
    • Heterogeneous Autoregression (HAR)
    • Autoregression (AR)
    • Zero mean
    • Models with and without exogenous regressors
  • Volatility models
    • ARCH
    • GARCH
    • TARCH
    • EGARCH
    • EWMA/RiskMetrics
  • Distributions
    • Normal
    • Student's T
    • Generalized Error Distribution

See the univariate volatility example notebook for a more complete overview.

import datetime as dt
import pandas_datareader.data as web
st = dt.datetime(1990,1,1)
en = dt.datetime(2014,1,1)
data = web.get_data_yahoo('^FTSE', start=st, end=en)
returns = 100 * data['Adj Close'].pct_change().dropna()

from arch import arch_model
am = arch_model(returns)
res = am.fit()

Unit Root Tests

  • Augmented Dickey-Fuller
  • Dickey-Fuller GLS
  • Phillips-Perron
  • KPSS
  • Zivot-Andrews
  • Variance Ratio tests

See the unit root testing example notebook for examples of testing series for unit roots.

Cointegration Testing and Analysis

  • Tests
    • Engle-Granger Test
    • Phillips-Ouliaris Test
  • Cointegration Vector Estimation
    • Canonical Cointegrating Regression
    • Dynamic OLS
    • Fully Modified OLS

See the cointegration testing example notebook for examples of testing series for cointegration.

Bootstrap

  • Bootstraps
    • IID Bootstrap
    • Stationary Bootstrap
    • Circular Block Bootstrap
    • Moving Block Bootstrap
  • Methods
    • Confidence interval construction
    • Covariance estimation
    • Apply method to estimate model across bootstraps
    • Generic Bootstrap iterator

See the bootstrap example notebook for examples of bootstrapping the Sharpe ratio and a Probit model from statsmodels.

# Import data
import datetime as dt
import pandas as pd
import numpy as np
import pandas_datareader.data as web
start = dt.datetime(1951,1,1)
end = dt.datetime(2014,1,1)
sp500 = web.get_data_yahoo('^GSPC', start=start, end=end)
start = sp500.index.min()
end = sp500.index.max()
monthly_dates = pd.date_range(start, end, freq='M')
monthly = sp500.reindex(monthly_dates, method='ffill')
returns = 100 * monthly['Adj Close'].pct_change().dropna()

# Function to compute parameters
def sharpe_ratio(x):
    mu, sigma = 12 * x.mean(), np.sqrt(12 * x.var())
    return np.array([mu, sigma, mu / sigma])

# Bootstrap confidence intervals
from arch.bootstrap import IIDBootstrap
bs = IIDBootstrap(returns)
ci = bs.conf_int(sharpe_ratio, 1000, method='percentile')

Multiple Comparison Procedures

  • Test of Superior Predictive Ability (SPA), also known as the Reality Check or Bootstrap Data Snooper
  • Stepwise (StepM)
  • Model Confidence Set (MCS)

See the multiple comparison example notebook for examples of the multiple comparison procedures.

Long-run Covariance Estimation

Kernel-based estimators of long-run covariance including the Bartlett kernel which is known as Newey-West in econometrics. Automatic bandwidth selection is available for all of the covariance estimators.

from arch.covariance.kernel import Bartlett
from arch.data import nasdaq
data = nasdaq.load()
returns = data[["Adj Close"]].pct_change().dropna()

cov_est = Bartlett(returns ** 2)
# Get the long-run covariance
cov_est.cov.long_run

Requirements

These requirements reflect the testing environment. It is possible that arch will work with older versions.

  • Python (3.9+)
  • NumPy (1.19+)
  • SciPy (1.5+)
  • Pandas (1.1+)
  • statsmodels (0.12+)
  • matplotlib (3+), optional

Optional Requirements

  • Numba (0.49+) will be used if available and when installed without building the binary modules. In order to ensure that these are not built, you must set the environment variable ARCH_NO_BINARY=1 and install without the wheel.
export ARCH_NO_BINARY=1
python -m pip install arch

or if using Powershell on windows

$env:ARCH_NO_BINARY=1
python -m pip install arch
  • jupyter and notebook are required to run the notebooks

Installing

Standard installation with a compiler requires Cython. If you do not have a compiler installed, the arch should still install. You will see a warning but this can be ignored. If you don't have a compiler, numba is strongly recommended.

pip

Releases are available PyPI and can be installed with pip.

pip install arch

You can alternatively install the latest version from GitHub

pip install git+https://github.com/bashtage/arch.git

Setting the environment variable ARCH_NO_BINARY=1 can be used to disable compilation of the extensions.

Anaconda

conda users can install from conda-forge,

conda install arch-py -c conda-forge

Note: The conda-forge name is arch-py.

Windows

Building extension using the community edition of Visual Studio is simple when using Python 3.8 or later. Building is not necessary when numba is installed since just-in-time compiled code (numba) runs as fast as ahead-of-time compiled extensions.

Developing

The development requirements are:

  • Cython (0.29+, if not using ARCH_NO_BINARY=1)
  • pytest (For tests)
  • sphinx (to build docs)
  • sphinx-immaterial (to build docs)
  • jupyter, notebook and nbsphinx (to build docs)

Installation Notes

  1. If Cython is not installed, the package will be installed as-if ARCH_NO_BINARY=1 was set.
  2. Setup does not verify these requirements. Please ensure these are installed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arch-6.0.0.tar.gz (3.4 MB view details)

Uploaded Source

Built Distributions

arch-6.0.0-cp311-cp311-win_amd64.whl (884.3 kB view details)

Uploaded CPython 3.11 Windows x86-64

arch-6.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (950.8 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

arch-6.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (919.2 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

arch-6.0.0-cp310-cp310-win_amd64.whl (883.4 kB view details)

Uploaded CPython 3.10 Windows x86-64

arch-6.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (949.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

arch-6.0.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (917.6 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

arch-6.0.0-cp39-cp39-win_amd64.whl (884.1 kB view details)

Uploaded CPython 3.9 Windows x86-64

arch-6.0.0-cp39-cp39-win32.whl (845.3 kB view details)

Uploaded CPython 3.9 Windows x86

arch-6.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (950.2 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

arch-6.0.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (918.8 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

File details

Details for the file arch-6.0.0.tar.gz.

File metadata

  • Download URL: arch-6.0.0.tar.gz
  • Upload date:
  • Size: 3.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.12

File hashes

Hashes for arch-6.0.0.tar.gz
Algorithm Hash digest
SHA256 f42caa5444f98ca12d5f32395149314b94e033291154e3c9e8747c99d637c169
MD5 821f5a5fb650df47f7e866259350ee1e
BLAKE2b-256 35752b1a9f22f6aa94ae7c827fdb0d6373e3cc182ae8f9c36636b744e08cec43

See more details on using hashes here.

File details

Details for the file arch-6.0.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: arch-6.0.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 884.3 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for arch-6.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 efa7071636e7719eff82228f9e4b96775a38eca9a6f1202cf47197bfdc2e045b
MD5 2f0ffa4cd07b224595512d6da28191ac
BLAKE2b-256 953dd23c7f5985ddc4a5be60be9c660057096b899ceed0bd87088d4edede3708

See more details on using hashes here.

File details

Details for the file arch-6.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for arch-6.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 34373c9da024c2e37f1cd03976c1fb9a5e66f7de335b4d3a22d639036153f8a9
MD5 528302ef5b19e85442b2f324da98c230
BLAKE2b-256 e49cef03bd87cc6c1a6ab345f1789bc94d17b7952e94473538bc27a2eef4d38e

See more details on using hashes here.

File details

Details for the file arch-6.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for arch-6.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 691bf968cb864b67c9821c7d16f853b42947007d3e8d129b838b34ae90986ea9
MD5 4c28336b3244ad489a9644bdb4c2fffc
BLAKE2b-256 41756ce52cbaf03b07f7cf976586525bcecc3c6e5b94a62057206f24a8729ee3

See more details on using hashes here.

File details

Details for the file arch-6.0.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: arch-6.0.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 883.4 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for arch-6.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7e202114106691bf4da44136e7913212879854e20137ac7c3cf9523440f5c50f
MD5 291fed24c16945bb99958abab50bc7ad
BLAKE2b-256 c110fd37103d687d0bc831e02480d845c3630c2968ffb6f214163c65742675e0

See more details on using hashes here.

File details

Details for the file arch-6.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for arch-6.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 31a4ed3091436b4d4cb8926f9f105a8e32552f54ff63e263b77c00e4a6d27af7
MD5 c2dc4d394ce3ffeae550600fe8be5220
BLAKE2b-256 09fe847de1eb01437f41d470301fb734330a0e035816f950565f2a663db9f0a0

See more details on using hashes here.

File details

Details for the file arch-6.0.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for arch-6.0.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 236da36b83afe0ca5f15ce8411611ff724b8473d080dcc79f8f92ec81d99ad14
MD5 a920746647edfbb089ae765aabaf4061
BLAKE2b-256 c888cce15ab6df3f4550e3c6326aafd3d05bc57b5c02ff6351230fb6ac9a7fb5

See more details on using hashes here.

File details

Details for the file arch-6.0.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: arch-6.0.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 884.1 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for arch-6.0.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d7a68674b7d8541b820c6c81775036a96e717fdde6f790ac3dca732d3cb76a55
MD5 dbcfd6e07cded4572e42692bb95519e5
BLAKE2b-256 6753066bc8fe0692c0ab1d50f15e32fd2e228ea642e108ebf646d8fde40c79ce

See more details on using hashes here.

File details

Details for the file arch-6.0.0-cp39-cp39-win32.whl.

File metadata

  • Download URL: arch-6.0.0-cp39-cp39-win32.whl
  • Upload date:
  • Size: 845.3 kB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for arch-6.0.0-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 4ae3065489a9d5e8a8616338de217044d617246303fb3bd55cd2c28ab1cdf86b
MD5 96b4c968af14339ff19957b90796e2ab
BLAKE2b-256 d7309ae514851df5568f622497e4b015b4d16533ae1e6dc26fc8735cf0d15162

See more details on using hashes here.

File details

Details for the file arch-6.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for arch-6.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 917167c5be4811e40c46877db57bdc74aab4d4bdf9806e4df2109825b1f74c7b
MD5 11cd701a4481c1380a682c2bbd4aae5c
BLAKE2b-256 7a4ca41d2c8bf5ed6386791b00a09315712899ff414531f7ad2cfd222530c83f

See more details on using hashes here.

File details

Details for the file arch-6.0.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for arch-6.0.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 97bfff54b0631e77ca5a4994d24f96b8de9a054eb10ea4452e79d1b387fe300a
MD5 731033d3fd4b028c533a0ded23861e69
BLAKE2b-256 7468b533b09bd1520827b41a456296e1bd590b4af700e99a49a3a1e629a34dc3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page