RSI与Wilder的RSI计算问题 [英] RSI vs Wilder's RSI Calculation Problems

查看:210
本文介绍了RSI与Wilder的RSI计算问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法获得平滑的RSI。下图来自freestockcharts.com。计算使用此代码。

 公共静态double CalculateRsi(IEnumerable< double&close; closePrices)
{
var price = closePrices为double []? closePrices.ToArray();

double sumGain = 0;
double sumLoss = 0;
for(int i = 1; i< prices.Length; i ++)
{
var差= prices [i] -prices [i-1];
if(差异> = 0)
{
sumGain + =差异;
}
其他
{
sumLoss-=差;
}
}

如果(sumGain == 0)返回0;
如果(Math.Abs​​(sumLoss)< Tolerance)返回100;

var relativeStrength = sumGain / sumLoss;

返回100.0-(100.0 /(1 + relativeStrength));
}

解决方案

为了计算RSI,您需要一个句点来进行计算。 如Wikipedia所述,经常使用14。



因此计算步骤如下:



时期1-13,RSI = 0



时段14:

  AverageGain = TotalGain / PeriodCount; 
AverageLoss = TotalLoss / PeriodCount;
RS =平均收益/平均亏损;
RSI = 100-100 /(1 + RS);

期间15-到(N):

 如果(期间(N)更改> 0 
AverageGain(N)=(((AverageGain(N-1)*(PeriodCount-1)))+期间(N )Change)/ PeriodCount;
else
AverageGain(N)=(AverageGain(N-1)*(PeriodCount-1))/ PeriodCount;

if(this.Change < 0)
AverageLoss(N)=(((AverageLoss(N-1)*(PeriodCount-1))+ Math.Abs​​(Period(N)Change))/ PeriodCount;
其他
AverageLoss(N)=(AverageLoss(N-1)*(PeriodCount-1))/ PeriodCount;

RS = AverageGain / AverageLoss;
RSI = 100-(100 /( 1 + RS));


I am having trouble getting a smoothed RSI. The below picture is from freestockcharts.com. The calculation uses this code.

public static double CalculateRsi(IEnumerable<double> closePrices)
{
    var prices = closePrices as double[] ?? closePrices.ToArray();

    double sumGain = 0;
    double sumLoss = 0;
    for (int i = 1; i < prices.Length; i++)
    {
        var difference = prices[i] - prices[i - 1];
        if (difference >= 0)
        {
            sumGain += difference;
        }
        else
        {
            sumLoss -= difference;
        }
    }

    if (sumGain == 0) return 0;
    if (Math.Abs(sumLoss) < Tolerance) return 100;

    var relativeStrength = sumGain / sumLoss;

    return 100.0 - (100.0 / (1 + relativeStrength));
}

https://stackoverflow.com/questions/...th-index-using-some-programming-language-js-c

This seems to be the pure RSI with no smoothing. How does a smoothed RSI get calculated? I have tried changing it to fit the definitions of the these two sites however the output was not correct. It was barely smoothed.

(I don't have enough rep to post links)

tc2000 -> Indicators -> RSI_and_Wilder_s_RSI (Wilder's smoothing = Previous MA value + (1/n periods * (Close - Previous MA)))

priceactionlab -> wilders-cutlers-and-harris-relative-strength-index (RS = EMA(Gain(n), n)/EMA(Loss(n), n))

Can someone actually do the calculation with some sample data?

Wilder's RSI vs RSI

解决方案

In order to calculate the RSI, you need a period to calculate it with. As noted on Wikipedia, 14 is used quite often.

So the calculation steps would be as follows:

Period 1 - 13, RSI = 0

Period 14:

AverageGain = TotalGain / PeriodCount;
AverageLoss = TotalLoss / PeriodCount;
RS = AverageGain / AverageLoss;
RSI = 100 - 100 / (1 + RS);

Period 15 - to period (N):

if (Period(N)Change > 0
  AverageGain(N) = ((AverageGain(N - 1) * (PeriodCount - 1)) + Period(N)Change) / PeriodCount;
else
  AverageGain(N) = (AverageGain(N - 1) * (PeriodCount - 1)) / PeriodCount;

if (this.Change < 0)
  AverageLoss(N) = ((AverageLoss(N - 1) * (PeriodCount - 1)) + Math.Abs(Period(N)Change)) / PeriodCount;
else
  AverageLoss(N) = (AverageLoss(N - 1) * (PeriodCount - 1)) / PeriodCount;

RS = AverageGain / AverageLoss;
RSI = 100 - (100 / (1 + RS));

这篇关于RSI与Wilder的RSI计算问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆