这是RSI图的两张图片。他们俩都需要8天。我使用的公式(取自stackoverflow的另一个问题):
public static double CalculateRsi(List<Double> closePrices)
{
double sumGain = 0;
double sumLoss = 0;
for (int i = 1; i < closePrices.size(); i++)
{
double difference = closePrices.get(i) - closePrices.get(i-1);
if (difference >= 0)
{
sumGain += difference;
}
else
{
sumLoss -= difference;
}
}
if (sumGain == 0) return 0;
double relativeStrength = sumGain / sumLoss;
return 100.0 - (100.0 / (1 + relativeStrength));
}
为什么我的程序显示的结果略有不同?