Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def get_stochastic(df, n=15, m=5, t=3):
# highest price during n days
ndays_high = df.h.rolling(window=n, min_periods=1).max()
# lowest price during n days
ndays_low = df.l.rolling(window=n, min_periods=1).min()
# Fast%K
kdj_k = ((df.c - ndays_low) / (ndays_high - ndays_low))
# Fast%D (=Slow%K)
kdj_d = kdj_k.ewm(span=m).mean()
# Slow%D
kdj_j = kdj_d.ewm(span=t).mean()
return kdj_j.mean()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.