TA-Lib indicator fails with KeyError:
-
Was trying to use a TA-Lib indicator and received the following error:
Using:
self.xx = bt.talib.LINEARREG_ANGLE(self.data.close, timeperiod=10)
Error:
KeyError: <module 'backtrader.talib' from '/home/randy/.virtualenvs/backtrader3/lib/python3.6/site-packages/backtrader/talib.py'>
TA-Lib 0.4.10 is installed. I've also tried using
period
instead of the standardtimeperiod
for TA-Lib. -
period
ortimeperiod
play no role. The error indicates theKeyError
to be in the module which should indicate thatLINEARREG_ANGLE
has not been found.Being the question if other things like for example a simple moving average are there or not ...
The
talib
integration simply asksta-lib
which functions are available and dynamically creates the needed classes to wrap them in the ecosystem. -
@backtrader not sure I understand your response.
Here is what I see:
ipdb> print(bt.talib.LINEARREG_SLOPE.__doc__) LINEARREG_SLOPE([input_arrays], [timeperiod=14]) Linear Regression Slope (Statistic Functions) Inputs: price: (any ndarray) Parameters: timeperiod: 14 Outputs: real ipdb> self.foo = bt.talib.LINEARREG_SLOPE(self.data.close) *** KeyError: <module 'backtrader.talib' from '/home/randy/.virtualenvs/backtrader3/lib/python3.6/site-packages/backtrader/talib.py'> ipdb> self.foo = bt.talib.LINEARREG_SLOPE(self.data.close, timeperiod=14) *** KeyError: <module 'backtrader.talib' from '/home/randy/.virtualenvs/backtrader3/lib/python3.6/site-packages/backtrader/talib.py'>
-
The question was if you had tried the same with a simple moving average,
talib.SMA
.Don't know exactly if the messages from
ipdb
match exactly those from the standard python interpreter, but the interpretation fromKeyError: <module 'backtrader.talib'
would be that no such thing happens to be in
sys.modules
, hence theKeyError
. Of course that seems to defy the logic of being able to do:ipdb> print(bt.talib.LINEARREG_SLOPE.__doc__)
and obtaining a result, which seems to indicate the symbol does actually exist in the module and seems to correspond to the actual
talib
indicator.The only thing that seems to be missing in the aforementioned information is in which context the code is being executed.
-
Same results with the
talib.SMA
I am running the
development
branchipdb> self.xx = bt.talib.SMA(self.data.close) *** KeyError: <module 'backtrader.talib' from '/home/randy/.virtualenvs/backtrader3/lib/python3.6/site-packages/backtrader/talib.py'> ipdb> print(bt.talib.SMA.__doc__) SMA([input_arrays], [timeperiod=30]) Simple Moving Average (Overlap Studies) Inputs: price: (any ndarray) Parameters: timeperiod: 30 Outputs: real
-
@backtrader
It was easy enough to test this with master branch and it appears to be working fine there. So seems recent changes might have broken this. -
New changes have only uncovered a typo in the
ta-lib
integration by which auto-generated wrappers had the module itself in the__module__
attribute instead of the module name. Corrected in thedevelopment
branch