For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Sharpe Ratio by Year



  • Hi,

    Is it possible for the Sharpe Ratio analyzer to produce a table of the sharpe ratios per year? At present I can only produce a single sharpe ratio figure for all the years of data (I am looking at about 15 years, so would like 15 SRs). Eg:

    Year 1: SR1
    Year 2: SR2
    Year 3: SR3...

    Current Sharpe ratio code:

    cerebro.addanalyzer(bt.analyzers.SharpeRatio, timeframe=bt.TimeFrame.Years, riskfreerate=0.03, annualize=True)
    sharperatio = strat0.analyzers.getbyname('sharperatio')
    sharperatio.get_analysis()
    

    Thanks!
    cwse


  • administrators

    Such thing doesn't exist. The 1st thing you would have to define is in which sub-year timeframe the results would be calculated, to then produce the Sharpe Ratio of that year for that selected timeframe.



  • @backtrader I would ideally like the same output as "Time Return" which gives by year. Is there a simple way I can code this using the existing SharpeRatio analyzer?


  • administrators

    Of course, TimeReturn produces a per year result, because a return needs only 2 values, the starting and ending values and it doesn't matter if there is no variability, there is no division by zero.

    The SharpeRatio needs at least 2 return values and they have to be different. That's why it is usually done on a multiyear basis.

    To get a yearly Sharpe Ratio you have to work with timeframes below Years.

    @cwse said in Sharpe Ratio by Year:

    Is there a simple way I can code this using the existing SharpeRatio analyzer?

    No.