Skip to content

Commit

Permalink
ENH: Use nanstd and nanmean, remove skipped test (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
analicia authored and twiecki committed Aug 18, 2017
1 parent cd453c7 commit dd634dd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 23 deletions.
4 changes: 2 additions & 2 deletions empyrical/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,10 @@ def sharpe_ratio(returns, risk_free=0, period=DAILY, annualization=None):
returns_risk_adj = np.asanyarray(_adjust_returns(returns, risk_free))
returns_risk_adj = returns_risk_adj[~np.isnan(returns_risk_adj)]

if np.std(returns_risk_adj, ddof=1) == 0:
if nanstd(returns_risk_adj, ddof=1) == 0:
return np.nan

return np.mean(returns_risk_adj) / np.std(returns_risk_adj, ddof=1) * \
return nanmean(returns_risk_adj) / nanstd(returns_risk_adj, ddof=1) * \
np.sqrt(ann_factor)


Expand Down
22 changes: 1 addition & 21 deletions empyrical/tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import random
from copy import copy
from operator import attrgetter
from unittest import TestCase, skip, SkipTest
from unittest import TestCase, SkipTest

from parameterized import parameterized
import numpy as np
Expand Down Expand Up @@ -217,26 +217,6 @@ def test_max_drawdown(self, returns, expected):
expected,
DECIMAL_PLACES)

# Multiplying returns by a positive constant larger than 1 will increase
# the maximum drawdown by a factor greater than or equal to the constant.
# Similarly, a positive constant smaller than 1 will decrease maximum
# drawdown by at least the constant.
@parameterized.expand([
(noise_uniform, 1.1),
(noise, 2),
(noise_uniform, 10),
(noise_uniform, 0.99),
(noise, 0.5)
])
@skip("Randomly fails")
def test_max_drawdown_transformation(self, returns, constant):
max_dd = self.empyrical.max_drawdown(returns)
transformed_dd = self.empyrical.max_drawdown(constant*returns)
if constant >= 1:
assert constant*max_dd <= transformed_dd
else:
assert constant*max_dd >= transformed_dd

# Maximum drawdown is always less than or equal to zero. Translating
# returns by a positive constant should increase the maximum
# drawdown to a maximum of zero. Translating by a negative constant
Expand Down

0 comments on commit dd634dd

Please sign in to comment.