Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    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

    General Code/Help
    2
    4
    981
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      cwse last edited by

      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

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        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.

        C 1 Reply Last reply Reply Quote 1
        • C
          cwse @backtrader last edited by

          @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?

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors