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/

    How to record performance and figures from cerebro?

    General Code/Help
    2
    5
    117
    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.
    • anarchy89
      anarchy89 last edited by

      I have around a 100 different strategies I am cycling over a years worth of trade weights using the following code,

      returns = []
      if __name__ == "__main__":
      
          for strategy in strategies:
              allocations = []
              print(strategy)
              dump = pd.read_csv(f'{strategy}.csv')
      
              cerebro = bt.Cerebro()
      
              ticker_names = list(set([alls[0] for alls in allocations]))
              targets = {ticker: {} for ticker in ticker_names}
              for all in allocations:
                  targets[all[0]].update({all[1]: all[2]})
      
              for ticker, target in targets.items():
                  data = bt.feeds.PandasData(
                      dataname=yahoodict[ticker],
                      timeframe=bt.TimeFrame.Days,
                      fromdate=datelist[0],
                      todate=datelist[-1],
                  )
                  data.target = target
                  cerebro.adddata(data, name=ticker)
      
              cerebro.addstrategy(Strategy)
              cerebro.broker.setcash(100000)
      
              cerebro.addanalyzer(bt.analyzers.SharpeRatio, _name='mysharpe')
              thestrats = cerebro.run()
             returns.append(cerebro.broker.getvalue())
      

      I am trying to save the results generated from cerebro, but I can only seem to save the returns at the end of the period using getvalue which returns the final value.

      Is there a way to check the daily returns or daily portfolio value instead of just the final broker value or some other details so I can understand the performance of my strategies?

      I have tried this guide here http://actuarialdatascience.com/backtrader_performance_report.html and used the cerebro.report('output/dir/for/your/report') command, but I get an error that there is no such thing as a report function.

      What can I do?

      run-out 1 Reply Last reply Reply Quote 0
      • run-out
        run-out @anarchy89 last edited by

        @anarchy89 You want analyzers. Try this general search as well as the docs.

        RunBacktest.com

        anarchy89 2 Replies Last reply Reply Quote 0
        • anarchy89
          anarchy89 @run-out last edited by

          @run-out from what i understand, these only show overall performance of the strategies correct, they dont show a daily breakdown?

          1 Reply Last reply Reply Quote 0
          • anarchy89
            anarchy89 @run-out last edited by

            @run-out I tried the analysers from the blog post here, https://www.backtrader.com/blog/posts/2016-07-22-benchmarking/benchmarking/, i dont understand the difference between these 2 lines,

            cerebro.addanalyzer(bt.analyzers.TimeReturn, timeframe=bt.TimeFrame.Years,
                                data=data, _name='datareturns')
            
            cerebro.addanalyzer(bt.analyzers.TimeReturn, timeframe=bt.TimeFrame.Years)
                                _name='timereturns')
            

            Could you explain it?

            run-out 1 Reply Last reply Reply Quote 0
            • run-out
              run-out @anarchy89 last edited by

              @anarchy89

              The standard TimeReturn analyzer has been extended to support tracking a data feed. The 2 major parameters invoved:
              
              timeframe (default: None) If None then the complete return over the entire backtested period will be reported
              
              Pass TimeFrame.NoTimeFrame to consider the entire dataset with no time constraints
              
              data (default: None)
              
              Reference asset to track instead of the portfolio value.
              

              So the top analyzer tracks the return for the specific data and gives it the name datareturns while the next line tracks the return for the whole portfolio and gives it the name timereturns, at least that's how i'm reading it.

              RunBacktest.com

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