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



  • 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


  • administrators

    @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)
    

Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.