Thanks a lot for the fast answer. That makes sense!
Posts made by jburb
RE: Strategy.__init__() slows down the whole backtest after it’s first execution?
Strategy.__init__() slows down the whole backtest after it’s first execution?
I am new to backtrader and python and noticed something seeming weird to me. To get a feeling how long it takes to calculate an indicator really often, I added the following code to the --init-- method of the class testStrategy:
startTime = time.time() for i in range(1, 100000): bt.indicators.SimpleMovingAverage( self.datas, period=self.params.maperiod) time2 = time.time()-startTime print("time needed " + str(time2))
When running the program, it takes about 20 seconds to execute the --init-- method, what makes sense to me. However, afterwards it takes much longer to execute the rest of the program (the actual testing). As far as I have understood backtrader/python the --init--() method is only executed ones, right after the instantiation of the testStrategy object. But if I increase the number of loops from 100.000 to 1.000.000, the steps after executing the --init-- method the first time take ten times longer.
Can anybody explain this behavior? Why is the rest of the program executed more slowly?
My program equals the second last step of the quickstart guide.
Thanks for any help in advance.