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/

    Fisher Transform - Indicator

    Indicators/Strategies/Analyzers
    2
    16
    4641
    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.
    • P
      Praveen Baratam last edited by

      Are there any plans to implement Ehler's Fisher Transform in Backtrader? It would be great to have it as part of the standard repertoire of indicators than many reinventing the wheel all over again.

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        Not at the moment

        1 Reply Last reply Reply Quote 0
        • P
          Praveen Baratam last edited by

          Can you give me some pointers to implement it?

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators last edited by

            Sorry but there aren't many free resources lately.

            1 Reply Last reply Reply Quote 0
            • P
              Praveen Baratam last edited by Praveen Baratam

              I have written some code and it is working now.

              I believe I am missing something.

              Lets say I want to do Fisher Transform of Chande Momentum Oscillator from TA-Lib... How can we do that? How can we pass CMOto Fisher?

              import backtrader as bt
              import math
              
              __all__ = ['Fisher']
              
              class Fisher(bt.Indicator):
              
                  lines = ('Fx',)
                  params = (('period', 20),)
              
                  _alpha = 0.33
                  _alphaFish = 0.5
              
                  def __init__(self):
              
                      self._scaledPrev = 0
                      self._FxPrev = 0
              
                      self._h = bt.indicators.Highest(self.data, period=self.p.period)
                      self._l = bt.indicators.Lowest(self.data, period=self.p.period)
              
                      super(Fisher, self).__init__()
              
                  def next(self):
              
                      d = self.data[0]
              
                      h = self._h[0]
                      l = self._l[0]
              
                      Fx = self.l.Fx
              
                      scaled = 2 * ((d - l) / (h - l) - .5)
                      scaled = self._alpha * scaled + (1-self._alpha) * (self._scaledPrev if len(Fx) > 1 else scaled)
              
                      if scaled > 0.9999:
                          scaled = 0.9999
                      elif scaled < -0.9999:
                          scaled = -0.9999
              
                      self._scaledPrev = scaled
              
                      Fx[0] = math.log((1 + scaled) / (1 - scaled))
                      self._FxPrev = Fx[0] = self._alphaFish * Fx[0] + (1-self._alphaFish) * (self._FxPrev if len(Fx) > 1 else Fx[0])
              

              The following is the strategy code I am using to plot and check.

              from __future__ import (absolute_import, division, print_function,
                                      unicode_literals)
              
              import backtrader as bt
              
              import Downloader
              import Fisher
              
              
              class St(bt.Strategy):
                  def __init__(self):
                      self.cmo = bt.talib.CMO(self.data.close, timeperiod=10)
                      self.fisher = Fisher(self.cmo, period=10)
              
              data = Downloader(dataname='BN')
              
              cerebro = bt.Cerebro()
              cerebro.adddata(data)
              cerebro.addstrategy(St)
              cerebro.run()
              cerebro.plot()
              
              1 Reply Last reply Reply Quote 0
              • P
                Praveen Baratam last edited by Praveen Baratam

                I have modified my reply several times to avoid clutter. Kindly check the latest modification on this page and advise me how I can pass TA-Lib Chande Momentum Oscillator to custom Fisher indicator as detailed above.

                Thank you.

                1 Reply Last reply Reply Quote 0
                • B
                  backtrader administrators last edited by backtrader

                  You already do:

                  @Praveen-Baratam said in Fisher Transform - Indicator:

                          self.cmo = bt.talib.CMO(self.data.close, timeperiod=10)
                          self.fisher = Fisher(self.cmo, period=10)
                  

                  But this is unnecessary

                  self.addminperiod(self.p.period)
                  

                  Becaue the indicators Highest and Lowest are already telling the system which period they need.

                  1 Reply Last reply Reply Quote 0
                  • P
                    Praveen Baratam last edited by

                    But it is not working.

                    0_1503218428381_FishCMO.png

                    1 Reply Last reply Reply Quote 0
                    • P
                      Praveen Baratam last edited by

                      Please Help

                      1 Reply Last reply Reply Quote 0
                      • B
                        backtrader administrators last edited by

                        The TA-Lib indicators are only batch indicators. Try running cerebro with runonce=False to disable batch mode and force the 2nd indicator to scan the batch indicator value by value.

                        1 Reply Last reply Reply Quote 0
                        • P
                          Praveen Baratam last edited by

                          Thank you. It is working now. :-)

                          Can we make any changes to the custom Fisher indicator so that we dont need to use this hack (runonce=False) when working on TA-Lib indicators?

                          Now that Fisher Transform is implemented, can we integrate this into Backtrader?

                          1 Reply Last reply Reply Quote 0
                          • B
                            backtrader administrators last edited by

                            You can define the indicator class with _nextforce = True.

                            Submit a pull request if you wish.

                            1 Reply Last reply Reply Quote 0
                            • P
                              Praveen Baratam last edited by

                              I mean, is there another way of implementing custom indicators such as Fisher Transform so that they will play nice with TA-Lib indicators, etc.

                              I believe forcing next mode on indicators will impose a steep performance penalty (3-4 times) on execution times.

                              B 1 Reply Last reply Reply Quote 0
                              • B
                                backtrader administrators @Praveen Baratam last edited by

                                Unfortunately there isn't in all cases.

                                1 Reply Last reply Reply Quote 0
                                • P
                                  Praveen Baratam last edited by

                                  I have submitted a pull request for Fisher Transform Indicator that I have implemented but it is not yet merged.

                                  Is there anything I can do to help merge it?

                                  1 Reply Last reply Reply Quote 0
                                  • B
                                    backtrader administrators last edited by

                                    You can use it without being merged. Again, see: Community - EoDevelopment 1.x

                                    1 Reply Last reply Reply Quote 0
                                    • 1 / 1
                                    • First post
                                      Last post
                                    Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors