我正在尝试使用 Pandas 计算相对强度指数 (RSI),但似乎无法正确调整此处提供的解决方案。为什么这不返回 RSI 系列?
import pandas_datareader.data as web
import datetime
start = datetime.datetime(2018, 2, 8)
end = datetime.datetime(2019, 2, 8)
stock = 'TNA'
price = web.DataReader(stock,'yahoo', start, end)
n = 14
def RSI(series):
delta = series.diff()
u = delta * 0
d = u.copy()
i_pos = delta > 0
i_neg = delta < 0
u[i_pos] = delta[i_pos]
d[i_neg] = delta[i_neg]
rs = moments.ewma(u, span=27) / moments.ewma(d, span=27)
return 100 - 100 / (1 + rs)
print(rsi(price, n))
慕哥6287543
相关分类