Backtrader Community

    • 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/

    order.ref keeps increasing after new cerebro instantiation

    General Discussion
    2
    2
    424
    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.
    • N
      nimrare last edited by nimrare

      Hi,

      I am a new backtrader user and I really love it so far. Thanks for this awesome piece of software. One thing I noticed though, was that the order reference always keeps increasing, even after creating a new cerebro instance.

      Concretely, I have a function that calculates a portfolio performance, given some input assets. This function is called in a loop. Every function call should create a new cerebro instance, yet the order reference always keeps increasing. Is this expected behavior and why?

      The program looks like the following:

      def calculate_performance(assets, start, end):
      
          cerebro = bt.Cerebro()
      
          ...
      
          results = cerebro.run()
          return cerebro.broker.getvalue()
      
      if __name__ == "__main__":
      
          for assets in asset_list:
      
              ending_value = calculate_performance(assets, start, end)
      
      

      Thanks a lot in advance!

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

        @nimrare said in order.ref keeps increasing after new cerebro instantiation:

        why?

        Because you are in a single Python script.

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