twopirllc / pandas-ta

Technical Analysis Indicators - Pandas TA is an easy to use Python 3 Pandas Extension with 150+ Indicators
https://twopirllc.github.io/pandas-ta/
MIT License
5.22k stars 1.02k forks source link

Fisher Transform does not produce correct results #518

Closed balioglum closed 2 years ago

balioglum commented 2 years ago

Which version are you running? The lastest version is on Github. Pip is for major releases.

import pandas_ta as ta
print(ta.version)

0.3.14b0

Do you have TA Lib also installed in your environment?

$ pip list

TA-Lib   0.4.22

Did you upgrade? Did the upgrade resolve the issue?

$ pip install -U git+https://github.com/twopirllc/pandas-ta

Upgrade did not resolve.

Describe the bug Fisher Transform does not produce correct results for cryptos which have multiple zeros after the decimal point. Some of these are:

['HOTUSDT','SHIBUSDT','XECUSDT','IOTXUSDT','JSTUSDT','WINUSDT','TROYUSDT','SUNUSDT','FUNUSDT','DENTUSDT','AKROUSDT','SPELLUSDT','SCUSDT','MFTUSDT','SKLUSDT','STPTUSDT','CKBUSDT']

To Reproduce

import pandas as pd
import pandas_ta as ta
import yfinance as yf

data = yf.download(tickers='SHIB-USD', start="2022-01-01", end="2022-03-30")
data.tail(5)
Screenshot 2022-04-16 at 20 16 51
data.ta.fisher(append=True)
data.tail(5)
Screenshot 2022-04-16 at 20 17 54

Expected behavior For some cryptocoins listed in Binance, pandas-ta Fisher transform indicator does not produce correct results. The common characteristic of these coins are that they have little multiple zeros after decimal point of their prices. For example, the close price of SHIBUST as of now is : 0.00002548

Thanks.

twopirllc commented 2 years ago

@balioglum,

Thank you! That's much more useful.

Sounds like a potential rounding issue.

Have you tried scaling the price, apply ta, and descale like:

import pandas as pd
import pandas_ta as ta
import yfinance as yf

scale = 1000 # Or whatever works best
_df = yf.download(tickers='SHIB-USD', start="2022-01-01", end="2022-03-30")

df = scale * _df.copy()
df.ta.fisher(append=True)
df /= scale

df.tail(5)

Unfortunately I do not have a time frame to address this, but I'll take another look at it when I get to converting it to numpy/numba. If you have a solution and would like to contribute, that would be great! 😎

Kind Regards, KJ

balioglum commented 2 years ago

Thank you Kevin.

twopirllc commented 2 years ago

@balioglum

Did you try the scaling code I posted in the last comment?

balioglum commented 2 years ago

Hi Kevin,

Scaling and descaling seems to be working. I've been using python-binance api and need to scale/descale only high, low and close values only.

klines = client.get_historical_klines("SHIBUSDT", Client.KLINE_INTERVAL_1DAY, "1 Jan, 2022")

data_df = pd.DataFrame(klines, columns=['timestamp', 'open', 'high', 'low', 'close',
                                        'volume', 'close_time', 'quote_av', 'trades', 'tb_base_av', 'tb_quote_av', 'ignore'])

scale = 10000
data_df['high'] = data_df['high'].astype(float) * scale
data_df['low'] = data_df['low'].astype(float) * scale
data_df['close'] = data_df['close'].astype(float) * scale
data_df.ta.fisher(append=True)
data_df['close'] /= scale
data_df['high'] /= scale
data_df['low'] /= scale

Thanks again for your help. I've learned the /= operator by the way as a bonus!

twopirllc commented 2 years ago

Hi @balioglum,

Scaling and descaling seems to be working.

Excellent!

... need to scale/descale only high, low and close values only.

True. Also you can consolidate the code a bit:

scale = 10000
ohlc = ['open', 'high', 'low', 'close']

data_df = # ohlcv et al
df = scale * data_df[ohlc].astype(float)
df.ta.fisher(append=True)
df /= scale
# then rejoin the DataFrames data_df, df

Thanks again for your help. I've learned the /= operator by the way as a bonus!

You're welcome! 😎