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

Fixed future deprecating warning and divide by zero warning #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions gemini/empyrical/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def max_drawdown(returns, out=None):
cumulative = np.empty(
(returns.shape[0] + 1,) + returns.shape[1:],
dtype='float64',
)
)
cumulative[0] = start = 100
cum_returns(returns_array, starting_value=start, out=cumulative[1:])

Expand Down Expand Up @@ -627,7 +627,7 @@ def omega_ratio(returns, risk_free=0.0, required_return=0.0,
return np.nan
else:
return_threshold = (1 + required_return) ** \
(1. / annualization) - 1
(1. / annualization) - 1

returns_less_thresh = returns - risk_free - return_threshold

Expand Down Expand Up @@ -697,15 +697,19 @@ def sharpe_ratio(returns,
returns_risk_adj = np.asanyarray(_adjust_returns(returns, risk_free))
ann_factor = annualization_factor(period, annualization)

np.multiply(
np.divide(
nanmean(returns_risk_adj, axis=0),
nanstd(returns_risk_adj, ddof=1, axis=0),
# handle 0.
if nanstd(returns_risk_adj, ddof=1, axis=0) == 0.0:
out = np.zeros_like(out)
else:
np.multiply(
np.divide(
nanmean(returns_risk_adj, axis=0),
nanstd(returns_risk_adj, ddof=1, axis=0),
out=out,
),
np.sqrt(ann_factor),
out=out,
),
np.sqrt(ann_factor),
out=out,
)
)
if return_1d:
out = out.item()

Expand Down Expand Up @@ -787,7 +791,10 @@ def sortino_ratio(returns,
if _downside_risk is not None else
downside_risk(returns, required_return, period, annualization)
)
np.divide(average_annual_return, annualized_downside_risk, out=out)
if annualized_downside_risk == 0.0:
out = np.zeros_like(out)
else:
np.divide(average_annual_return, annualized_downside_risk, out=out)
if return_1d:
out = out.item()
elif isinstance(returns, pd.DataFrame):
Expand Down Expand Up @@ -1508,7 +1515,7 @@ def tail_ratio(returns):
return np.nan

return np.abs(np.percentile(returns, 95)) / \
np.abs(np.percentile(returns, 5))
np.abs(np.percentile(returns, 5))


def capture(returns, factor_returns, period=DAILY):
Expand Down
10 changes: 5 additions & 5 deletions gemini/helpers/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def analyze_bokeh(algo, title=None, show_trades=False):
continue

p.line(records['date'], records[c], color='grey',
legend=c, y_range_name="Records")
legend_label=c, y_range_name="Records")

# print(algo.data[['date', 'close', 'sma50', 'sma150']])

Expand All @@ -54,12 +54,12 @@ def analyze_bokeh(algo, title=None, show_trades=False):

p.line(algo.data.index, algo.data['base_equity'],
color='#CAD8DE',
legend='Buy and Hold')
# ,y_range_name="equity_y_axis")
legend_label='Buy and Hold')
# ,y_range_name="equity_y_axis")
p.line(algo.data.index, algo.data['equity'],
color='#49516F',
legend='Strategy')
#,y_range_name="equity_y_axis")
legend_label='Strategy')
#,y_range_name="equity_y_axis")

cmo_above_50 = bokeh.models.Span(location=50,
dimension="width",
Expand Down