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.
- do the two different data have to be the same length? e.g., one data starts from 2000 and the other is from 2010
- how do I obtain the performance of the strategy on the two data respectively?
- 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
-
@asuralm said in strategy performance on multi-data:
- 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.- 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
- 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)