Fisher Transform - Indicator
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.
Not at the moment
Can you give me some pointers to implement it?
Sorry but there aren't many free resources lately.
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 h = self._h l = self._l 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 = math.log((1 + scaled) / (1 - scaled)) self._FxPrev = Fx = self._alphaFish * Fx + (1-self._alphaFish) * (self._FxPrev if len(Fx) > 1 else Fx)
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()
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.
You already do:
self.cmo = bt.talib.CMO(self.data.close, timeperiod=10) self.fisher = Fisher(self.cmo, period=10)
But this is unnecessary
Becaue the indicators
Lowestare already telling the system which period they need.
But it is not working.
TA-Libindicators are only batch indicators. Try running cerebro with
runonce=Falseto disable batch mode and force the 2nd indicator to scan the batch indicator value by value.
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?
You can define the indicator class with
_nextforce = True.
Submit a pull request if you wish.
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.
Unfortunately there isn't in all cases.
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?
You can use it without being merged. Again, see: Community - EoDevelopment 1.x