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, supports 3.0.0b2+)
  • 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.1.tar.gz (3.4 MB view details)

Uploaded Source

Built Distributions

arch-6.0.1-cp311-cp311-win_amd64.whl (850.6 kB view details)

Uploaded CPython 3.11 Windows x86-64

arch-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (915.2 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

arch-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (890.6 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

arch-6.0.1-cp310-cp310-win_amd64.whl (852.7 kB view details)

Uploaded CPython 3.10 Windows x86-64

arch-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (915.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

arch-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (891.7 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

arch-6.0.1-cp39-cp39-win_amd64.whl (854.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

arch-6.0.1-cp39-cp39-win32.whl (821.3 kB view details)

Uploaded CPython 3.9 Windows x86

arch-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (917.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

arch-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (893.7 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

File details

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

File metadata

  • Download URL: arch-6.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 a9ea622f099110f01ce421b6d298c921ec806abfb38fee4a3dd177ed4872fc24
MD5 49f2590889e1d457f910bbaa09fd1f2a
BLAKE2b-256 9c41de6c71fe3a63f0c97e2199e0968ed4375b00c76adca645610617beb497e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: arch-6.0.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 850.6 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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b7c8d010eb26b9e4a228d125b0a1e5d472e429872aacd8badb5357abe813e1af
MD5 4e4852c462d4eed238cdca3f23c6629d
BLAKE2b-256 606952462549739134a72dc3f220bcb426de692754755ec5e031a02b1e86abc1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for arch-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c4d7987a62e6ca99123ca6971fad97b6e885edf748c4d134fa7cb3789e179e6e
MD5 f19d23ae77eced29514a7eab5b9ab97b
BLAKE2b-256 e9f659933c0c0c8bd02c5805f05bf7a94af6f67c6d3140820b3c3466d2c4f34b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for arch-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9f0c20cf4ca3ff32fadf57a692df1a3130383885bd1b5f9b951ca447c9b3f3fc
MD5 34d7f69c39a0f014d8379827367491f5
BLAKE2b-256 381ec8693d212de72c72bae6939378b535cf7abca8d6090d53dd0ab81448a569

See more details on using hashes here.

File details

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

File metadata

  • Download URL: arch-6.0.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 852.7 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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 66463891644635c1a8a117992d295d1a78773f0121ff3b6918d819706bc7e071
MD5 5da82ff91586fa5d2a1b633b93b100eb
BLAKE2b-256 9e80eaff80839e87f565f26a46396b27711d6278d0d178870d00d13b0c4013f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for arch-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 72fef5d15f157f56bf40126cc1630458b3d6a7f6839df8eb2237bf9d681313bc
MD5 bcb70cca67cadd442827958a3b0783c3
BLAKE2b-256 ed2606e4b72338af4858d7d5a01aae356a688d852ec634f067d0cd275ece63cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for arch-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 85f7b2ae024edda3423d804e122b4699098cbc43fcdabd65ea764497221c127c
MD5 e4e3eaf9584dd20688673b8fb1e8dddd
BLAKE2b-256 0a499ed0cfe19892c5ab88ac9851cfd9554942ad965cc98c62a4ec0113253ca0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: arch-6.0.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 854.4 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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e9976c2160f903f70b5352bed7ea625ba2c398613bd236a991c6a4fa919278ad
MD5 c0ce9fa870c6a067b87593dc40591417
BLAKE2b-256 60ec957cc6bc42a50828f20d435ae952177179357927d10a2679a3d1d0f1ab84

See more details on using hashes here.

File details

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

File metadata

  • Download URL: arch-6.0.1-cp39-cp39-win32.whl
  • Upload date:
  • Size: 821.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.1-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 c6714d5e442aee1a01c1d352366afbd1a2bf6b0372098e10811e194cc077f694
MD5 804e49bb413b6911e13c492006636a0b
BLAKE2b-256 89080cbe43d38bca3cd850d627732dd8bbfc1308e2ef446159923d2f9146bec4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for arch-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1c5850bad17108838f95c216a827fca3505086525d67e3c8390a238ee8167c50
MD5 aec758096a2ba7a5e4387fd541afc0e2
BLAKE2b-256 22ba9bb2ac062f5136aefd66f3aaebbf18c7d69f95273e9e3bbe01c8457c3380

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for arch-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 682c12d51b85b0f4ec8e1114d5e597b6bf8d2d0c76200380c7ddfda3bfd282b0
MD5 a5d6cee500918757726173212f481a4e
BLAKE2b-256 0655a6e38dbe05acb90ec16cc4eeee405a9cdfc00f8e04f93b4bdd163d2adc34

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