-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Description
In your documentation you say:
If you wonder why STOCHRSI gives you different results than you expect, probably you want STOCH applied to RSI, which is a little different than the STOCHRSI which is STOCHF applied to RSI:
>>> import talib
>>> import numpy as np
>>> c = np.random.randn(100)
# this is the library function
>>> k, d = talib.STOCHRSI(c)
# this produces the same result, calling STOCHF
>>> rsi = talib.RSI(c)
>>> k, d = talib.STOCHF(rsi, rsi, rsi)
# you might want this instead, calling STOCH
>>> rsi = talib.RSI(c)
>>> k, d = talib.STOCH(rsi, rsi, rsi)
I happened to be that guy in the description, unfortunately. This is a little confusing to me, what are k
and d
!? Why do you give rsi 3 times to STOCH
? You can safely ignore the comments, but I mentioned them, if you're curious what my intentions are for calculation of this indicator.
Here's how I used your library in my app:
import talib as ta
def stoch_rsi(series, stoch_length=14, rsi_length=14, smooth_k=3, smooth_d=3):
# rsi_serie = rsi(series, rsi_length)
# stochrsi = (rsi_serie - rsi_serie.rolling(stoch_length).min()) / (
# rsi_serie.rolling(stoch_length).max() - rsi_serie.rolling(stoch_length).min()
# )
# stochrsi_K = stochrsi.rolling(smooth_k).mean()
# stochrsi_D = stochrsi_K.rolling(smooth_d).mean()
# return stochrsi * 100, stochrsi_K * 100, stochrsi_D * 100
if isinstance(series, pd.Series):
series = series.to_numpy()
return ta.STOCHRSI(
series,
timeperiod=stoch_length,
fastk_period=smooth_k,
fastd_period=smooth_d,
)
Metadata
Metadata
Assignees
Labels
No labels