def RSI(df, n):
i = 0
UpI = [0]
DoI = [0]
while i + 1 <= df.index[-1]:
UpMove = df.get_value(i + 1, 'High') - df.get_value(i, 'High')
DoMove = df.get_value(i, 'Low') - df.get_value(i + 1, 'Low')
if UpMove > DoMove and UpMove > 0:
UpD = UpMove
else: UpD = 0
UpI.append(UpD)
if DoMove > UpMove and DoMove > 0:
DoD = DoMove
else: DoD = 0
DoI.append(DoD)
i = i + 1
UpI = pd.Series(UpI)
DoI = pd.Series(DoI)
PosDI = pd.Series(pd.ewma(UpI, span = n, min_periods = n - 1))
NegDI = pd.Series(pd.ewma(DoI, span = n, min_periods = n - 1))
RSI = pd.Series(PosDI / (PosDI + NegDI), name = 'RSI_' + str(n))
df = df.join(RSI)
return df
#True Strength Index
moreIndicators.py 文件源码
python
阅读 33
收藏 0
点赞 0
评论 0
评论列表
文章目录