Created
September 6, 2019 04:52
-
-
Save jsrimr/7d0734704a6472671332d345ac207e85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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