Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Talib Indicator slowing down code

    General Discussion
    2
    5
    42
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bnewell last edited by

      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 1 Reply Last reply Reply Quote 0
      • run-out
        run-out @bnewell last edited by

        @bnewell Looking at your old post I can see you will likely be pre-processing with pandas. In that case you can use TA-LIB outside with pandas as well, or BTA-LIB which was written by the same person who created backtrader and is designed to work efficiently with pandas.

        B 1 Reply Last reply Reply Quote 0
        • B
          bnewell @run-out last edited by

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

          B 1 Reply Last reply Reply Quote 0
          • B
            bnewell @bnewell last edited by

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

            run-out 1 Reply Last reply Reply Quote 0
            • run-out
              run-out @bnewell last edited by

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

              1 Reply Last reply Reply Quote 1
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
              $(document).ready(function () { app.coldLoad(); }); }