Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Negative PnL Strategy's Sharpe, Sortino and Calmar ratios are zero #472

Answered by kernc
atakanokan asked this question in Q&A
Discussion options

Is there any way for Backtest.run() to return values (instead of 0) for strategies with negative PnL? From what I can see, they all return 0.

You must be logged in to vote

You could remove np.clip() wrapping in these places:

s.loc['Sharpe Ratio'] = np.clip((s.loc['Return (Ann.) [%]'] - risk_free_rate) / (s.loc['Volatility (Ann.) [%]'] or np.nan), 0, np.inf) # noqa: E501

s.loc['Sortino Ratio'] = np.clip((annualized_return - risk_free_rate) / (np.sqrt(np.mean(day_returns.clip(-np.inf, 0)**2)) * np.sqrt(annual_trading_days)), 0, np.inf) # noqa: E501

s.loc['Calmar Ratio'] = np.clip(annualized_return / (-max_dd or np.nan), 0, np.inf)

Do nega...

Replies: 1 comment 5 replies

Comment options

You could remove np.clip() wrapping in these places:

s.loc['Sharpe Ratio'] = np.clip((s.loc['Return (Ann.) [%]'] - risk_free_rate) / (s.loc['Volatility (Ann.) [%]'] or np.nan), 0, np.inf) # noqa: E501

s.loc['Sortino Ratio'] = np.clip((annualized_return - risk_free_rate) / (np.sqrt(np.mean(day_returns.clip(-np.inf, 0)**2)) * np.sqrt(annual_trading_days)), 0, np.inf) # noqa: E501

s.loc['Calmar Ratio'] = np.clip(annualized_return / (-max_dd or np.nan), 0, np.inf)

Do negative Sharpe, Sortino, Calmar ratios make any sense?
You must be logged in to vote
5 replies
Comment options

It would be good to look at cross-asset robustness via SR distribution which Neg->0 SR clipping skews. Would be great to receive the ratios as is and do clipping if needed.

Comment options

@kernc if you think this would be a good PR, I would be more than happy to do it

Comment options

Clipping came in in 028f02d with no elaborate justification. I agree, PR welcome. 👍

Comment options

I remember my thinking: with risk-free rate default assumed 0%, if your strategy's Sharpe is negative, it's better to just divest and keep the money. 😄

Comment options

Opened: #473

Answer selected by atakanokan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /