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/

    strategy performance on multi-data

    General Code/Help
    2
    2
    1286
    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.
    • A
      asuralm last edited by

      Hi:

      I just read post MULTI-EXAMPLE and multi-data strategy.

      If I simple trade a strategy simultaneously on two different data feed, and I want to compare the same strategy performance on two different symbols.

      1. do the two different data have to be the same length? e.g., one data starts from 2000 and the other is from 2010
      2. how do I obtain the performance of the strategy on the two data respectively?
      3. within the strategy, is there a way to know how many datafeeds are added to the cerebro? For example, does the following code work?
      for d in self.datas 
          o1 = self.buy(data=d, exectype=bt.Order.Market)
      

      Thanks

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

        @asuralm said in strategy performance on multi-data:

        1. do the two different data have to be the same length? e.g., one data starts from 2000 and the other is from 2010

        No, but your system won't start trading until 2010. Because the system is only active when all data feeds are delivering. You can hook into prenext, but in this method it is no guaranteed that you can access the buffers of data feeds, indicators and others.

        1. how do I obtain the performance of the strategy on the two data respectively?

        https://www.backtrader.com/docu/cerebro.html (Section: Returning the results)

        result = cerebro.run(**kwargs)
        

        The format of result returned by run will vary depending on whether optimization is used (a strategy was added with optstrategy):

        • All strategies added with addstrategy

          result will be a list of the instances run during the backtesting

        • 1 or more strategies were added with optstrategy

          result will be a list of list. Each internal list will contain the strategies after each optimization run

        1. within the strategy, is there a way to know how many datafeeds are added to the cerebro?

        No magic here. Standard Python. Trying it is faster as asking (believe it)

        len(self.datas)
        
        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(); }); }