Back to Community
Negative Sharpe Ratio for a positive return. why?

Hi,

So I just started learning from Quantopian and while I was playing with the following algorithm, I got a negative value of Sharpe Ratio while the returns were positive.

def initialize (context):
context.vrx = sid(10908)

def handle_data (context, data):
order_target_percent(context.vrx, -1.0)

Shorting VRX

Please explain this.

9 responses

Same strategy, same asset but negative returns resulted positive Sharpe and positive Sortino.

Entire data start date: 2013-09-03
Entire data end date: 2017-08-01

Backtest Months: 46

Total Returns
-9.47%
Benchmark Returns
63.86%
Alpha
0.41
Beta
-1.45
Sharpe
0.31
Sortino
0.48
Volatility
0.72
Max Drawdown
-70.28%

Can somebody explain this?

@Saravanakumar: Would you be willing to share the dates over which you backtested that strategy?

@Vladimir: Would you be willing to share the code that produced the resulting metrics that you shared? Either posting them here or sharing the backtest/algo privately without our support team would be helpful.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

@jamie Please check the link attached and let me know if you need any more details.

VRX Shorting Data

Jamie.

Unfortunately, from April 2017, I can't attach my backtests to the reply. Can you tell me why?
To get positive Sharpe and positive Sortino with negative return, I used this simple code:

def initialize (context):  
    context.stock = symbol('VRX')  
    schedule_function(trade, date_rules.every_day(), time_rules.market_open(minutes = 15))  
def trade(context, data):  
    if get_open_orders(): return  
    if data.can_trade(context.stock):  
        order_target_percent(context.stock, -1.0)  

Vladimir, can you open up a ticket with support? Unfortunately, when I run the code you shared from 2013-09-03 to 2017-08-01 with $1M or $10M starting capital, I'm unable to reproduce the results that you reported in your earlier comment.

Saravanakumar, thanks for sharing that information. It looks like the strategy you shared is rising far above 1x leverage, and I'm wondering if that could be the cause of the problem. Leverage above 1x doesn't explain why the total returns and Sharpe ratio have different signs, they should still have the same sign, but I'm wondering if this is what's causing the bug. I've reported this to our engineers to take a look. In the meantime, you should look into using the Optimize API to control the leverage used by your algorithm. The long-short equity template algorithms uses Optimize to place orders.

(Edited) Initial capital for the code above would be helpful.

For testing here's an example of the opposite, positive Sharpe while negative returns.

Entire data start date: 2013-09-03
Entire data end date: 2017-08-01
Initial capital 10000
https://www.quantopian.com/posts/negative-returns-resulted-positive-sharpe-and-positive-sortino

This is probably due to the fact that Quantopian uses daily arithmetic returns to calculate Sharpe ratios.

Continuously compounded returns are always lower than arithmetic returns (as you have to subtract sigma^2/2).
Consequently, given enough volatility, a strategy with a positive average daily return can produce a negative compound return.

Using Vladimir’s numbers, the strategy’s average daily return is around 0.31*0.72 / 252 = + 8.9 bp / day
Whereas sigma^2/2 = (72%/sqrt(252))^2/2 = 10.3 bp
Consequently, the strategy has a negative compound return despite having a positive average arithmetic return.

@Xander is correct. In general, you can get a positive Sharpe Ratio and negative cumulative returns any time the arithmetic mean of (1 + daily_returns) is greater than 1, but the geometric mean of (1 + daily_returns) is less than 1. I've written up a short notebook (using the simpler algorithm posted by Vladimir above) explaining why how and why this happens.

Loading notebook preview...
Notebook previews are currently unavailable.
Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.