找回密码
 注册
搜索
查看: 1799|回复: 11

[知识] RSI 计算请教

[复制链接]
发表于 2009-1-1 04:37 PM | 显示全部楼层 |阅读模式


首先祝各位胡同同仁新年快乐!

我有一个关于RSI的计算问题请教大家。

symbol: BGU, Interval: 5, I got following data (for close)
12/22/2008 14:45:00 32.55
12/22/2008 14:50:00 32.354
12/22/2008 14:55:00 31.94
12/22/2008 15:00:00 31.82
12/22/2008 15:05:00 31.8401
12/22/2008 15:10:00 31.88
12/22/2008 15:15:00 31.71
12/22/2008 15:20:00 31.76
12/22/2008 15:25:00 31.40
12/22/2008 15:30:00 31.48
12/22/2008 15:35:00 32.08
12/22/2008 15:40:00 32.0078
12/22/2008 15:45:00 32.06
12/22/2008 15:50:00 32.4419
12/22/2008 15:55:00 32.9109
And I got RSI(14) from a tool as 12/22/2008 15:55:00 as 61.45.

 However I calculated the RSI(14) manually by myself

12/22/2008 14:45:00 32.55    
12/22/2008 14:50:00 32.354     -0.196
12/22/2008 14:55:00 31.94       -0.414
12/22/2008 15:00:00 31.82       -0.12
12/22/2008 15:05:00 31.8401     0.0201
12/22/2008 15:10:00 31.88        0.0399
12/22/2008 15:15:00 31.71       -0.17
12/22/2008 15:20:00 31.76       0.05
12/22/2008 15:25:00 31.40      -0.36
12/22/2008 15:30:00 31.48       0.08
12/22/2008 15:35:00 32.08       0.6
12/22/2008 15:40:00 32.0078  -0.0722
12/22/2008 15:45:00 32.06       0.0522
12/22/2008 15:50:00 32.4419    0.3819
12/22/2008 15:55:00 32.9109    0.469

Sum of Up day: 0.0201+0.0399+0.05+0.08+0.6+0.0522+0.3819+0.469=1.6931
Sum of Down day: 0.196+0.414+0.12+0.17+0.36+0.0722=1.3322
So: RS=1.6931/1.3322=1.270905

Hence: RSI=100-100/(1+RS)=55.96.  That is not equal to 61.45.

大家知道我哪里错了吗?谢谢!
rsi.JPG
发表于 2009-1-1 04:54 PM | 显示全部楼层
注意RSI有不同的计算方法。你比较一下不同的画图软件对SPX的RSI(14)结果也是不同的。另外,RSI也有RSI_EMA和RSI_Wilder之分。不用深究,感觉自己的算法对就可以了。
回复 鲜花 鸡蛋

使用道具 举报

发表于 2009-1-1 05:02 PM | 显示全部楼层

原帖由 flyingatom 于 2009-1-1 16:37 发表 首先祝各位胡同同仁新年快乐! 我有一个关于RSI的计算问题请教大家。symbol: BGU, Interval: 5, I got following data (for close)12/22/2008 14:45:00 32.5512/22/2008 14:50:00 32.35412/22/2008 14:55:00 31.9412 ...

没时间看你的问题了,下面是俺算RSI的程序,可能跟第一个数值需要250天的平均有关,记得写这段的时候也是怎么凑都不对,好像挺trick,最后对了,但现在记不得哪个地方trick了。

 

/// <summary>

/// Returns RSI starting from "daysAgo" for "countDays".

/// RSI Formular:

/// RSI = 100 - 100 / ( 1 + RS )

/// RS = Average Gains / Average Loss

/// Average Gain = [(previous Average Gain) x (n - 1) + current Gain] / n

/// First Average Gain = Total of Gains during past m periods / m

/// Average Loss = [(previous Average Loss) x (n - 1) + current Loss] / n

/// First Average Loss = Total of Losses during past m periods / m

/// </summary>

public decimal RSI(int daysAgo, int countDays)

{

decimal averageGain, averageLoss;

return RSI(daysAgo, countDays, out averageGain, out averageLoss);

}

public decimal RSI(int daysAgo, int countDays,

out decimal averageGain, out decimal averageLoss)

{

averageGain = 0M;

averageLoss = 0M;

if (countDays <= 0 || this.closes == null || this.closes.Length <= 0)

return 0M;

// Min 15 days data is required.

if (this.closes.Length - daysAgo < 15)

return 0M;

// Leave at least one day to calculate the RS.

int count = this.closes.Length - daysAgo - 1;

int i = 1;

int j = 0;

// For the first average gain 250 days of data is preferred.

if (count > 250)

count = 250;

// Calculate the first average gain.

for (; i <= count; i++, j++)

{

decimal gain = this.closes - this.closes[i - 1];

if (gain > 0M)

averageGain += gain;

else

averageLoss -= gain;

}

// Since the very first data is not counted.

averageGain /= j;

averageLoss /= j;

for (; i < this.closes.Length - daysAgo; i++)

{

decimal gain = this.closes - this.closes[i - 1];

if (gain > 0M)

{

averageGain = (averageGain * (countDays - 1) + gain) / countDays;

averageLoss = averageLoss * (countDays - 1) / countDays;

}

else

{

averageGain = averageGain * (countDays - 1) / countDays;

averageLoss = (averageLoss * (countDays - 1) - gain) / countDays;

}

}

if (averageLoss == 0M)

return 100M;

return (100M - 100M / (1M + averageGain / averageLoss));

}

回复 鲜花 鸡蛋

使用道具 举报

发表于 2009-1-1 05:10 PM | 显示全部楼层
I got 53.54 using TS RSI(Close,14).
回复 鲜花 鸡蛋

使用道具 举报

发表于 2009-1-1 11:00 PM | 显示全部楼层

原帖由 lite1067 于 2009-1-1 22:57 发表 wow. what language is this? looks like C++ or Java, but not exactly the same.

C#

回复 鲜花 鸡蛋

使用道具 举报

发表于 2009-1-1 11:02 PM | 显示全部楼层
原帖由 Cobra 于 2009-1-1 23:00 发表 C#


thanks. I just figured this out by google. 蛇老大真牛呀。。
回复 鲜花 鸡蛋

使用道具 举报

发表于 2009-1-2 09:08 AM | 显示全部楼层
原帖由 Cobra 于 2009-1-1 23:00 发表 C#

老大,你学什么专业的?
MBA,机械,计算机?
:(13):
回复 鲜花 鸡蛋

使用道具 举报

发表于 2009-1-2 09:37 AM | 显示全部楼层
不是MBA,机械猜对了,不过还有其他专业。
回复 鲜花 鸡蛋

使用道具 举报

发表于 2009-1-2 09:45 AM | 显示全部楼层
原帖由 Cobra 于 2009-1-2 09:37 发表 不是MBA,机械猜对了,不过还有其他专业。

你的C#用的很好,所以我猜你学过计算机软件。
你计算机的知识,能和计算机专业的人比美。

回复 鲜花 鸡蛋

使用道具 举报

发表于 2009-1-2 09:57 AM | 显示全部楼层

原帖由 百万宝贝 于 2009-1-2 09:45 发表 你的C#用的很好,所以我猜你学过计算机软件。你计算机的知识,能和计算机专业的人比美。

那,猜你应该是做IT的吧?

回复 鲜花 鸡蛋

使用道具 举报

发表于 2009-1-2 10:02 AM | 显示全部楼层
原帖由 Cobra 于 2009-1-2 09:57 发表 那,猜你应该是做IT的吧?

:(13):
回复 鲜花 鸡蛋

使用道具 举报

 楼主| 发表于 2009-1-2 06:53 PM | 显示全部楼层
谢谢各位老大指点。我后来直接给broker公司发信去问他们的算法了。 It uses an Exponential Moving Average (EMA) as part of the formula. This is difficult to compute by hand without Microsoft Excel, for example. The formula we use may be found at this link: http://en.wikipedia.org/wiki/Relative_strength_index 再次感谢各位老大!新年快乐!
回复 鲜花 鸡蛋

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|www.hutong9.net

GMT-5, 2025-6-23 01:34 PM , Processed in 0.048913 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表