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
# calculating RSI (gives the same values as TradingView) | |
# https://stackoverflow.com/questions/20526414/relative-strength-index-in-python-pandas | |
def RSI(series, period=14): | |
delta = series.diff().dropna() | |
ups = delta * 0 | |
downs = ups.copy() | |
ups[delta > 0] = delta[delta > 0] | |
downs[delta < 0] = -delta[delta < 0] | |
ups[ups.index[period-1]] = np.mean( ups[:period] ) #first value is sum of avg gains |