Sharpe Ratio BT vs Pyfolio different values



  • I have a very simple strategy and in the end I run:

    cerebro.addanalyzer(bt.analyzers.SharpeRatio) 
    cerebro.addanalyzer(bt.analyzers.Returns) 
    cerebro.addanalyzer(bt.analyzers.PyFolio)
    

    Then I compare the return and Sharpe from bt to Pyfolio and they are
    different:

    Sharpe Ratio 1.22111855094Total 
    return 0.671019659277
    
    Entire data start date: 2012-09-24
    Entire data end date: 2017-09-22
    Backtest months: 59
    BacktestAnnual return          14.4%
    Cumulative returns     95.6%
    Annual volatility      15.2%
    Sharpe ratio            0.96
    Calmar ratio            0.86
    Stability               0.90
    Max drawdown          -16.8%
    Omega ratio             1.18
    Sortino ratio           1.48
    Skew                    0.86
    Kurtosis                8.21
    Tail ratio              1.02
    Daily value at risk    -1.9%
    Gross leverage          0.60
    Daily turnover          0.2%
    Alpha                   0.04
    Beta                    0.81
    

    Is it due to the Risk Free rate? Comission? Slippage?



  • Look at SharpeRatio analyzer code in backtrader and check how many parameters does it have. Any of those parameters will influence the result. Pyfolio Sharpe ratio has to rely on some default parameters as well, they are probably different than bt.SharpeRatio defaults.



  • These days pyfolio relies on empyrical for calculations like Sharpe.

    The definition of the sharpe_ratio in empyrical (See here: empyrical - Sharpe Ratio

    def sharpe_ratio(returns, risk_free=0, period=DAILY, annualization=None):
    

    There is already a difference with the following :

     - ``riskfreerate`` (default: 0.01 -> 1%)
    

    and a second here:

    - ``timeframe``: (default: ``TimeFrame.Years``)
    

    because empyrical has a default of DAILY. This may be an entirely different thing and not directly related to the timeframe.

    You'll have to check both sources.


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.