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



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


  • administrators

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

    why?

    Because you are in a single Python script.


Log in to reply
 

});