• Stars
    star
    1,268
  • Rank 37,109 (Top 0.8 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Common financial risk and performance metrics. Used by zipline and pyfolio.

Build Status

PyPI

empyrical

Common financial risk metrics.

Table of Contents

Installation

pip install empyrical

Usage

Simple Statistics

import numpy as np
from empyrical import max_drawdown, alpha_beta

returns = np.array([.01, .02, .03, -.4, -.06, -.02])
benchmark_returns = np.array([.02, .02, .03, -.35, -.05, -.01])

# calculate the max drawdown
max_drawdown(returns)

# calculate alpha and beta
alpha, beta = alpha_beta(returns, benchmark_returns)

Rolling Measures

import numpy as np
from empyrical import roll_max_drawdown

returns = np.array([.01, .02, .03, -.4, -.06, -.02])

# calculate the rolling max drawdown
roll_max_drawdown(returns, window=3)

Pandas Support

import pandas as pd
from empyrical import roll_up_capture, capture

returns = pd.Series([.01, .02, .03, -.4, -.06, -.02])

# calculate a capture ratio
capture(returns)

# calculate capture for up markets on a rolling 60 day basis
roll_up_capture(returns, window=60)

Support

Please open an issue for support.

Deprecated: Data Reading via pandas-datareader

As of early 2018, Yahoo Finance has suffered major API breaks with no stable replacement, and the Google Finance API has not been stable since late 2017 (source). In recent months it has become a greater and greater strain on the empyrical development team to maintain support for fetching data through pandas-datareader and other third-party libraries, as these APIs are known to be unstable.

As a result, all empyrical support for data reading functionality has been deprecated and will be removed in a future version.

Users should beware that the following functions are now deprecated:

  • empyrical.utils.cache_dir
  • empyrical.utils.data_path
  • empyrical.utils.ensure_directory
  • empyrical.utils.get_fama_french
  • empyrical.utils.load_portfolio_risk_factors
  • empyrical.utils.default_returns_func
  • empyrical.utils.get_symbol_returns_from_yahoo

Users should expect regular failures from the following functions, pending patches to the Yahoo or Google Finance API:

  • empyrical.utils.default_returns_func
  • empyrical.utils.get_symbol_returns_from_yahoo

Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

Testing

  • install requirements
    • "nose>=1.3.7",
    • "parameterized>=0.6.1"
./runtests.py

More Repositories

1

zipline

Zipline, a Pythonic Algorithmic Trading Library
Python
17,443
star
2

pyfolio

Portfolio and risk analytics in Python
Jupyter Notebook
5,596
star
3

alphalens

Performance analysis of predictive (alpha) stock factors
Jupyter Notebook
3,330
star
4

qgrid

An interactive grid for sorting, filtering, and editing DataFrames in Jupyter notebooks
Python
3,034
star
5

research_public

Quantitative research and educational materials
Jupyter Notebook
2,400
star
6

trading_calendars

Calendars for various securities exchanges.
Python
608
star
7

qdb

Quantopian Remote Debugger for Python
Python
315
star
8

quantopian-algos

Library of algorithm scripts for Quantopian
Python
174
star
9

pgcontents

A Postgres-backed ContentsManager implementation for Jupyter
Python
150
star
10

coal-mine

Coal Mine - Periodic task execution monitor
Python
114
star
11

bayesalpha

Bayesian models to compute performance and uncertainty of returns and alpha.
Python
105
star
12

algorithm-component-library

A collection of code snippets that can be constructed into larger trading algorithms.
Python
103
star
13

PenguinDome

Simple Linux Mobile Device Management
Python
90
star
14

libpy

Utilities for writing C++ extension modules.
C++
82
star
15

warp_prism

Quickly move data from postgres to numpy or pandas.
C
64
star
16

qgrid-notebooks

Notebooks which will provide a demo of Qgrid functionality
Jupyter Notebook
20
star
17

serializable-traitlets

JSON-Serializable IPython Traitlets
Python
13
star
18

metautils

Utilities for writing metaclasses.
Python
8
star
19

DockORM

An object-relational mapper for docker containers.
Python
8
star
20

quantopian-drafts

Drafts for new Quantopian features.
6
star
21

aqueduct-client

Python wrapper for Quantopian's Aqueduct API
Python
2
star
22

nose_xunit_gevent

Xunit for the nose_gevented_multiprocess plugin
Python
2
star
23

quantopian.github.io

CSS
1
star