-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Use of talib indicators not producing the expected result. #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you provide a full traceback? Can you actually provide a full MWE to reproduce the issue?
backtesting.py/backtesting/_util.py Line 43 in 64bcda2
backtesting.py/backtesting/_util.py Line 88 in 64bcda2
|
The only proper way to use talib (or any indicator functions, really) is: self.ma1 = self.I(ta.SMA, self.data.Close, timeperiod=10) I.e. lazy evaluation. Just pass the function reference ( |
Thanks for your help. Please find the MWE. from backtesting import Backtest, Strategy
from backtesting.lib import *
from backtesting.test import *
from talib import abstract as ta
class SmaCross(Strategy):
def init(self):
# Precompute the two moving averages
self.sma1 = self.I(SMA, self.data.Close, 10)
self.sma2 = self.I(SMA, self.data.Close, 20)
# self.sma1 = self.I(ta.SMA, self.data.Close, timeperiod=10)
# self.sma2 = self.I(ta.SMA, self.data.Close, timeperiod=20)
def next(self):
# If sma1 crosses above sma2, close any existing
# short trades, and buy the asset
if crossover(self.sma1, self.sma2):
self.position.close()
self.buy()
# Else, if sma1 crosses below sma2, close any existing
# long trades, and sell the asset
elif crossover(self.sma2, self.sma1):
self.position.close()
self.sell()
bt = Backtest(GOOG, SmaCross,
cash=10000, commission=.002)
print(bt.run())
# bt.plot() Same code using TA Lib throws exception self.sma1 = self.I(ta.SMA, self.data.Close, timeperiod=10)
self.sma2 = self.I(ta.SMA, self.data.Close, timeperiod=20)
|
This is now a duplicate of issue #93, and a different error from the one quoted in original post? 😕
The workaround, besides using yet-unreleased git master, is to instead: import talib as ta |
Many thanks and workaround works. |
Uh oh!
There was an error while loading. Please reload this page.
TA lib indicators not producing expected results. Any help on this would be great.
And also I am using this function and getting the error
Expected Behavior
Actual Behavior
Use of TALib
TALib Produces NAN values.
The text was updated successfully, but these errors were encountered: