Talib Indicator slowing down code
-
Hello,
I recently posted about code being slow, which I have looked into and resolved to a degree; however, I have another interesting issue that I have noticed. It seems as if some of the TALIB indicators are slower than others (when I am thinking the underlying speed of talib shouldn't slow a backtest down by 10x+, so I am thinking it is something in my code.
The current indicator I am having trouble with is bt.talib.HT_DCPERIOD
I have tried the following code below so far.
1. self.rolling_period = bt.talib.HT_DCPERIOD(self.datas[0].lines.close) 2. self.rolling_period = bt.talib.HT_DCPERIOD(self.datas[0]) ... self.log(f"BUY EXECUTED, Price: {order.executed.price}, Cost: {order.executed.value}, Comm {order.executed.comm}, Dom Per: {self.rolling_period.real[0]}")
The simple inclusion of this indicator without using it outside of the print seems to dramatically inhibit code perfomance, when other indicators in TALIB are not.
Related to my old post, I am wondering if I will have to take the talib indicators outside before I run the backtest as well, or am I correct and am I doing something wrong. Thanks!
-
-
@run-out Thanks for the reply,
well, it is odd, because shouldn't all of the data be preprocessed in init? the self.rolling_period... is in init)
the code delays are in the next portion where the printing is, which is why I think it is so odd?
-
@run-out , especially in addition because the other indicators, even the rocket science indicators in talib are not causing speed problems.
When I say speed problems, I am speaking in terms of relativity to the backtrader hello world. For example, the time between each next when adding those lines above cause the hello world processing speed to be substantially longer for each _next calculation, which doesn't make a lot of sense.
-
@bnewell I just tested this talib function on just under two months of minute data, and the times are almost the same.
10 cyles: The average time for ta_lib = True is 1.361 The average time for ta_lib = False is 1.313
I can't reproduce the problem you are having, you may have to troubleshoot on your end.