您好我写了这段代码来计算BTC过去14天价格的RSI,但我不确定这是否正确,如果有任何人可以提供我的代码
higher = []
lower = []
past14Days = [6971.73, 6937.08, 8218.05, 9251.27, 8870.82, 9114.72, 10226.86, 10107.26, 11233.95, 11767.74, 11459.71, 11104.2, 11175.87, 11429.02]
x = 0
for i in past14Days:
if len(past14Days)-1 >= x+1:
if past14Days[x+1] > past14Days[x]:
high = past14Days[x+1] - past14Days[x]
higher.append(high)
elif past14Days[x+1] < past14Days[x]:
low = past14Days[x] - past14Days[x+1]
lower.append(low)
x+=1
upwordAvg = sum(higher) / len(higher)
downwordAvg = sum(lower) / len(lower)
print(upwordAvg)
print(downwordAvg)
RS = upwordAvg / downwordAvg
RSI = 100 - (100/(1+RS))
print(RSI)
答案 0 :(得分:0)
显然,这里的问题是无法对照某些内容检查代码的输出。为了检查输出,我建议带一支铅笔和一张纸(或Excel)并手动到达图形。然后,将其与您的python代码提供的内容进行比较。只有到那时,您才知道python代码实现了您的意图。如果您不确定如何计算RSI,请查看this link(他们声称他们根据TradingView(交易中知名网站之一)计算RSI)。但是,其中没有python(而是java)。希望它可以帮助您从python代码中阐明您的要求。