Optimization: How to test strategy on different datafeeds
jf last edited by
I managed to test different parameters of a strategy (eg. different moving-average window lengths) on a fixed datafeed. However, I failed so far to test a fixed set of parameters on different datafeeds.
For example (simplified), I would like to test a simple moving average crossover strategy with a window length of 7 days for three different stocks such as Apple, Google, Facebook, etc and see where it performs best.
I created a list with the different tickers, and then use
asset = random.sample(tickerlist,1)
Then for import something like:
data = bt.feeds.PandasData(dataname=asset)
This way I get a ticker out of my list. I then set all the optimization parameters that could affect data pre-loading to false:
cerebro = bt.Cerebro(stdstats=False, optreturn=False, runonce=False, preload=False, optdatas=False, maxcpus=1)
However, it seems that the "random.sample" is not re-executed at each run, as it always re-loads the same datafeed.
Any idea on how I could solve this would be highly appreciated!
Some selected code lines don't really help. But most probably you believe that you can
runmultiple times, which isn't true. You need to create and run a new cerebro instance for each scenario you want to tes.