Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional Calculations & Roll, Up, Down Helpers #47

Merged
merged 43 commits into from Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ca1b7e3
add stackable helpers
May 19, 2017
c13dc50
start on the test stuff.
May 19, 2017
25c0498
tweak drawdown, add new stats
May 19, 2017
df0559f
replace information ratio with "excess_sharpe"
May 19, 2017
acf449e
add doc strings and a few more stats.
May 19, 2017
686ce87
make all_negative returns all negative.
May 19, 2017
87b3c42
added tests for drawdown, rolling and regular
May 19, 2017
69d3d1d
move the periodicity stuff into separate file
May 19, 2017
ddc5b88
more tests
May 19, 2017
a0707c6
correct definition
May 19, 2017
64c5b1f
update README, rename some stuff in util
May 19, 2017
6ca5e06
add space
May 19, 2017
f527392
update parameterized
May 19, 2017
415ffd9
explicitly require window.
May 19, 2017
2425ea2
lint
May 19, 2017
e9b9f5c
add capture to the simple list
May 19, 2017
925b917
added the other example
May 19, 2017
71cc78b
flake8 linting.
May 19, 2017
18dbd5a
add missing reference
May 19, 2017
9688b4a
added the rest of em
May 19, 2017
1cc5301
:rage: at PEP for making me format it this way.
May 19, 2017
6ceef77
probably should update this as well
May 19, 2017
ebac920
add latest numpy, pandas, only head python version
May 19, 2017
e4835bc
get a couple versions in there.
May 19, 2017
9c3ccf4
remove bottleneck req.
May 25, 2017
a89510e
added stats to the FACTOR_STAT_FUNCS list,
May 31, 2017
d2c7836
revert to original doc strings for alpha-beta
May 31, 2017
aa07b5c
bottleneck a HARD req again.
May 31, 2017
6049309
added doc strings for public helpers
May 31, 2017
ab1eabe
new tests for helpers
Jun 5, 2017
71ea444
switch to one function
Jun 5, 2017
902f2ef
final cleanup
Jun 5, 2017
6efeee1
missed one :rage:
Jun 5, 2017
fc607b1
add more tests
Jun 8, 2017
b90d63f
added final stat tests
Jun 14, 2017
c297c4b
restore some spacing
Jun 14, 2017
0d594e5
same.
Jun 14, 2017
2a52111
update to correct result
Jun 14, 2017
65a6a86
call aligned in the roll, so ndarray can be passed.
Jun 14, 2017
5dcbeb0
linting
Jun 14, 2017
50ef4d3
Merge pull request #1 from cgdeboer/testing
cgdeboer Jun 14, 2017
02b3a4e
satisfy older, more picky versions on numpy :confused:
Jun 14, 2017
dfe495f
revert the bottlneck attempt code
Jun 16, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions .travis.yml
Expand Up @@ -9,18 +9,18 @@ matrix:
env: PANDAS_VERSION=0.17.1 NUMPY_VERSION=1.10.4 SCIPY_VERSION=0.16.1 LIBGFORTRAN_VERSION=1.0
- python: 2.7
env: PANDAS_VERSION=0.18.1 NUMPY_VERSION=1.11.1 SCIPY_VERSION=0.17.1 LIBGFORTRAN_VERSION=3.0

- python: 3.4
env: PANDAS_VERSION=0.16.1 NUMPY_VERSION=1.9.2 SCIPY_VERSION=0.15.1 LIBGFORTRAN_VERSION=1.0
- python: 2.7
env: PANDAS_VERSION=0.19.2 NUMPY_VERSION=1.12.1 SCIPY_VERSION=0.19.0 LIBGFORTRAN_VERSION=3.0
- python: 2.7
env: PANDAS_VERSION=0.20.1 NUMPY_VERSION=1.12.1 SCIPY_VERSION=0.19.0 LIBGFORTRAN_VERSION=3.0
- python: 3.4
env: PANDAS_VERSION=0.17.1 NUMPY_VERSION=1.10.4 SCIPY_VERSION=0.16.1 LIBGFORTRAN_VERSION=1.0
- python: 3.4
env: PANDAS_VERSION=0.18.1 NUMPY_VERSION=1.11.1 SCIPY_VERSION=0.17.1 LIBGFORTRAN_VERSION=3.0

- python: 3.5
env: PANDAS_VERSION=0.17.1 NUMPY_VERSION=1.10.4 SCIPY_VERSION=0.16.1 LIBGFORTRAN_VERSION=1.0
- python: 3.5
env: PANDAS_VERSION=0.18.1 NUMPY_VERSION=1.11.1 SCIPY_VERSION=0.17.1 LIBGFORTRAN_VERSION=3.0
env: PANDAS_VERSION=0.19.2 NUMPY_VERSION=1.12.1 SCIPY_VERSION=0.19.0 LIBGFORTRAN_VERSION=3.0
- python: 3.6
env: PANDAS_VERSION=0.20.1 NUMPY_VERSION=1.12.1 SCIPY_VERSION=0.19.0 LIBGFORTRAN_VERSION=3.0

before_install:
# We do this conditionally because it saves us some downloading if the
Expand Down
70 changes: 68 additions & 2 deletions README.md
@@ -1,11 +1,77 @@
# empyrical

Common financial risk metrics.

## Installation
## Table of Contents

### Installing with `pip`
- [Installation](#installation)
- [Usage](#usage)
- [Support](#support)
- [Contributing](#contributing)
- [Testing](#testing)

## Installation
```
pip install empyrical
```

## Usage

Simple Statistics
```python
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
```python
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
```python
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](https://github.com/quantopian/empyrical/issues/new) for support.

## Contributing

Please contribute using [Github Flow](https://guides.github.com/introduction/flow/). Create a branch, add commits, and [open a pull request](https://github.com/quantopian/empyrical/compare/).

## Testing
- install requirements
- "nose>=1.3.7",
- "parameterized>=0.6.1"

```
python -m unittest
```
17 changes: 16 additions & 1 deletion empyrical/__init__.py
Expand Up @@ -30,7 +30,7 @@
sharpe_ratio,
sortino_ratio,
downside_risk,
information_ratio,
excess_sharpe,
alpha_beta,
alpha,
beta,
Expand All @@ -40,6 +40,21 @@
stability_of_timeseries,
tail_ratio,
cagr,
capture,
up_capture,
down_capture,
up_down_capture,
up_alpha_beta,
down_alpha_beta,
roll_max_drawdown,
roll_up_capture,
roll_down_capture,
roll_up_down_capture,
roll_alpha_beta,
roll_sharpe_ratio,
)

from .periods import (
DAILY,
WEEKLY,
MONTHLY,
Expand Down
17 changes: 17 additions & 0 deletions empyrical/periods.py
@@ -0,0 +1,17 @@
APPROX_BDAYS_PER_MONTH = 21
APPROX_BDAYS_PER_YEAR = 252

MONTHS_PER_YEAR = 12
WEEKS_PER_YEAR = 52

DAILY = 'daily'
WEEKLY = 'weekly'
MONTHLY = 'monthly'
YEARLY = 'yearly'

ANNUALIZATION_FACTORS = {
DAILY: APPROX_BDAYS_PER_YEAR,
WEEKLY: WEEKS_PER_YEAR,
MONTHLY: MONTHS_PER_YEAR,
YEARLY: 1
}