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 does the backtrader get the cash or value of each step?

    General Discussion
    3
    4
    1210
    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

      After the backtest, I want the value of funds for each step

      results = cerebro.run()
      

      After this code, what can I do to get it? I did not find a similar answer from the official document.

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

        I use the following analyzer to get cash and value.

        class CashMarket(bt.analyzers.Analyzer):
            """
            Analyzer returning cash and market values
            """
            def create_analysis(self):
                self.rets = {}
                self.vals = 0.0
        
            def notify_cashvalue(self, cash, value):
                self.vals = (cash, value)
                self.rets[self.strategy.datetime.datetime()] = self.vals
        
            def get_analysis(self):
                return self.rets
        

        RunBacktest.com

        1 Reply Last reply Reply Quote 1
        • MuSaCN
          MuSaCN last edited by

          Thank you for sharing your code.
          Since the backtrader has a plot() function to draw the fund curve, it must store them internally.

          1 Reply Last reply Reply Quote 0
          • A
            ab_trader last edited by

            @MuSaCN said in How does the backtrader get the cash or value of each step?:

            After this code, what can I do to get it?

            one of the ways is using debugging tools get into results variable and check what data it contains.

            • If my answer helped, hit reputation up arrow at lower right corner of the post.
            • Python Debugging With Pdb
            • New to python and bt - check this out
            1 Reply Last reply Reply Quote 1
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors