Package: arch
archAutoregressive Conditional Heteroskedasticity (ARCH) and other tools for
financial econometrics, written in Python (with Cython and/or Numba used
to improve performance)MetricLatest ReleaseContinuous IntegrationCoverageCode QualityCitationDocumentationModule ContentsUnivariate ARCH ModelsUnit Root TestsCointegration Testing and AnalysisBootstrappingMultiple Comparison TestsLong-run Covariance EstimationPython 3archis Python 3 only. Version 4.8 is the final version that supported Python 2.7.DocumentationDocumentation from the main branch is hosted onmy github pages.Released documentation is hosted onread the docs.More about ARCHMore information about ARCH and related models is available in the notes and
research available atKevin Sheppard's site.ContributingContributions are welcome. There are opportunities at many levels to contribute:Implement new volatility process, e.g., FIGARCHImprove docstrings where unclear or with typosProvide examples, preferably in the form of IPython notebooksExamplesVolatility ModelingMean modelsConstant meanHeterogeneous Autoregression (HAR)Autoregression (AR)Zero meanModels with and without exogenous regressorsVolatility modelsARCHGARCHTARCHEGARCHEWMA/RiskMetricsDistributionsNormalStudent's TGeneralized Error DistributionSee theunivariate volatility example notebookfor a more complete overview.importdatetimeasdtimportpandas_datareader.dataaswebst=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()fromarchimportarch_modelam=arch_model(returns)res=am.fit()Unit Root TestsAugmented Dickey-FullerDickey-Fuller GLSPhillips-PerronKPSSZivot-AndrewsVariance Ratio testsSee theunit root testing example notebookfor examples of testing series for unit roots.Cointegration Testing and AnalysisTestsEngle-Granger TestPhillips-Ouliaris TestCointegration Vector EstimationCanonical Cointegrating RegressionDynamic OLSFully Modified OLSSee thecointegration testing example notebookfor examples of testing series for cointegration.BootstrapBootstrapsIID BootstrapStationary BootstrapCircular Block BootstrapMoving Block BootstrapMethodsConfidence interval constructionCovariance estimationApply method to estimate model across bootstrapsGeneric Bootstrap iteratorSee thebootstrap example notebookfor examples of bootstrapping the Sharpe ratio and a Probit model from statsmodels.# Import dataimportdatetimeasdtimportpandasaspdimportnumpyasnpimportpandas_datareader.dataaswebstart=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 parametersdefsharpe_ratio(x):mu,sigma=12*x.mean(),np.sqrt(12*x.var())returnnp.array([mu,sigma,mu/sigma])# Bootstrap confidence intervalsfromarch.bootstrapimportIIDBootstrapbs=IIDBootstrap(returns)ci=bs.conf_int(sharpe_ratio,1000,method='percentile')Multiple Comparison ProceduresTest of Superior Predictive Ability (SPA), also known as the Reality
Check or Bootstrap Data SnooperStepwise (StepM)Model Confidence Set (MCS)See themultiple comparison example notebookfor examples of the multiple comparison procedures.Long-run Covariance EstimationKernel-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.fromarch.covariance.kernelimportBartlettfromarch.dataimportnasdaqdata=nasdaq.load()returns=data[["Adj Close"]].pct_change().dropna()cov_est=Bartlett(returns**2)# Get the long-run covariancecov_est.cov.long_runRequirementsThese 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+), optionalOptional RequirementsNumba (0.49+) will be used if availableandwhen installed without building the binary modules. In order to ensure that these are not built, you must set the environment variableARCH_NO_BINARY=1and install without the wheel.exportARCH_NO_BINARY=1python-mpipinstallarchor if using Powershell on windows$env:ARCH_NO_BINARY=1python-mpipinstallarchjupyter and notebook are required to run the notebooksInstallingStandard installation with a compiler requires Cython. If you do not
have a compiler installed, thearchshould still install. You will
see a warning but this can be ignored. If you don't have a compiler,numbais strongly recommended.pipReleases are available PyPI and can be installed withpip.pipinstallarchYou can alternatively install the latest version from GitHubpipinstallgit+https://github.com/bashtage/arch.gitSetting the environment variableARCH_NO_BINARY=1can be used to
disable compilation of the extensions.Anacondacondausers can install from conda-forge,condainstallarch-py-cconda-forgeNote: The conda-forge name isarch-py.WindowsBuilding 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.DevelopingThe 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 NotesIf Cython is not installed, the package will be installed
as-ifARCH_NO_BINARY=1was set.Setup does not verify these requirements. Please ensure these are
installed.