quantopian / empyrical

Common financial risk and performance metrics. Used by zipline and pyfolio.
https://quantopian.github.io/empyrical
Apache License 2.0
1.27k stars 398 forks source link

max_drawdown returns pd.Series, not float #98

Closed eigenfoo closed 6 years ago

eigenfoo commented 6 years ago

Example:

import numpy as np
import pandas as pd
import empyrical as ep

dr = pd.date_range('2015/01/01', '2018/01/01')

px = pd.DataFrame(data=abs(np.random.randn(len(dr)) + 10),
                  columns=['FOO'],
                  index=dr)

rets = px.pct_change().dropna()
rets.index = rets.index.tz_localize('UTC')

ep.stats.max_drawdown(rets)

Output:

0   -0.450319
dtype: float64

This causes downstream problems for me, e.g. here: https://github.com/quantopian/empyrical/blob/ea9a9b7bde56dd14f7fad72b3bd3c27836a709b9/empyrical/stats.py#L547 since the truth value of a pd.Series is ambiguous.

np.__version__ = 1.14.2
pd.__version__ = 0.18.0
ep.__version__ = 0.4.3
twiecki commented 6 years ago

Yup, that's a bug.

eigenfoo commented 6 years ago

Just kidding, I used a pd.DataFrame instead of a pd.Series. This is actually in the docs, I'll close this down.

twiecki commented 6 years ago

It should be a scalar, not a DataFrame or Series.

eigenfoo commented 6 years ago

No in other words, px and rets in my code snippet above were DataFrames, but should have been Series.