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/

    After optimization, how to obtain optimization results ?

    General Discussion
    2
    3
    95
    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.
    • MuSaCN
      MuSaCN last edited by

      I usually use:

          def stop(self):
              print("stop(): ", self.params.Para0, self.broker.getvalue(), self.broker.get_cash())
      

      After optimization, It just print message. how to obtain opt results?

      1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        please go over the following docs:

        • https://www.backtrader.com/docu/cerebro/#returning-the-results
        • https://www.backtrader.com/docu/optimization-improvements/#results-management

        some example from the docs:

        def runstrat(pargs=None):
            args = parse_args(pargs)
        
            cerebro = bt.Cerebro()
            data = bt.feeds.BacktraderCSVData(dataname=args.data)
            cerebro.adddata(data)
        
            cerebro.addanalyzer(bt.analyzers.Returns)
            cerebro.optstrategy(StFetcher, idx=StFetcher.COUNT())
            results = cerebro.run(maxcpus=args.maxcpus, optreturn=args.optreturn)
        
            strats = [x[0] for x in results]  # flatten the result
            for i, strat in enumerate(strats):
                rets = strat.analyzers.returns.get_analysis()
                print('Strat {} Name {}:\n  - analyzer: {}\n'.format(
                    i, strat.__class__.__name__, rets))
        
        1 Reply Last reply Reply Quote 2
        • MuSaCN
          MuSaCN last edited by

          thanks, it is useful to me.

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
          $(document).ready(function () { app.coldLoad(); }); }