D******4 发帖数: 47 | 1 初次接触RSI,对于two period RSI 有点疑惑。
RSI = 100 - 100/(1+RS)
RS = Average Gain(in N period)/Average Loss(in N period)
对于2 period RSI, RS 中的N取2。
由于只有两个period,那么一定是要么gain,要么loss.
即P[1]<=P[2]时,为gain。loss为0。这时定义RSI=100.
P[1]>P[2]时,为loss.gain为0,这时RSI=0.
也就是说,2 period RSI只能取0和100两个值吗?
多谢 | A***l 发帖数: 302 | 2 No. You made two two mistakes in the calculation:
1. RSI(2) uses two days' gains or losses, P(1)-P(0) and P(2)-P(1).
2. mean gain and mean loss are exponentional moving average,not simple movin
g average.
RSI(2) to RSI(4) are popular short-term mean reversion signals in some stats
tical arbitrage strategies.
【在 D******4 的大作中提到】 : 初次接触RSI,对于two period RSI 有点疑惑。 : RSI = 100 - 100/(1+RS) : RS = Average Gain(in N period)/Average Loss(in N period) : 对于2 period RSI, RS 中的N取2。 : 由于只有两个period,那么一定是要么gain,要么loss. : 即P[1]<=P[2]时,为gain。loss为0。这时定义RSI=100. : P[1]>P[2]时,为loss.gain为0,这时RSI=0. : 也就是说,2 period RSI只能取0和100两个值吗? : 多谢
| D******4 发帖数: 47 | 3 thanks so much.~
This calculation makes sense. About MS, do I have to use EMA to calculate
RSI(2)? I tested RSI(2) in MATLAB, its own function to calculate seeme to
use Simple MA.
btw, do you know how to tackle with time series data in C++?
movin
stats
【在 A***l 的大作中提到】 : No. You made two two mistakes in the calculation: : 1. RSI(2) uses two days' gains or losses, P(1)-P(0) and P(2)-P(1). : 2. mean gain and mean loss are exponentional moving average,not simple movin : g average. : RSI(2) to RSI(4) are popular short-term mean reversion signals in some stats : tical arbitrage strategies.
| f*******y 发帖数: 988 | 4 已经不灵光了,现在的market vol太低了
movin
stats
【在 A***l 的大作中提到】 : No. You made two two mistakes in the calculation: : 1. RSI(2) uses two days' gains or losses, P(1)-P(0) and P(2)-P(1). : 2. mean gain and mean loss are exponentional moving average,not simple movin : g average. : RSI(2) to RSI(4) are popular short-term mean reversion signals in some stats : tical arbitrage strategies.
| A***l 发帖数: 302 | 5 We don't use C++. My guess is a vector of maps or a dictionary data structur
e will do.
People don't use or interpret tehnical signals in the same way. For example,
in exponential moving average, some signals use 1/N as the decay factor; ma
ny others use 1/(2N+1).
The following is a Matlab funciton that I use to calculate RSI.
function RSI = rsi(data, nPeriod, type)
% PURPOSE: calculates the relative strength indicator for data
%--------------------------------------------------------------------------
% USAGE: RSI = rsi(data, nPeriod, type)
% where: data = a vector or a matrix (RSI is calculated column by column)
% nPeriod = RSI(nPeriod)
% type = 'e' (default), calculate the first data point using simple
% moving average and then use exponential moving average with
% decay factor 1/nPeriod to update the RSI.
% 's', calculate all data points using simple moving average
% of up moves and down moves.
%--------------------------------------------------------------------------
% RETURNS: a vector or a matrix the same size as x with the first
% nPeriod-1 rows being NaN
% -------------------------------------------------------------------------
if nargin == 1
nPeriod = 14;
type = 'e';
elseif nargin == 2
type = 'e';
end
[m n] = size(data);
deltaData = data(2:m, :) - data(1:m-1,:);
positiveDelta = deltaData .* (deltaData > 0);
negativeDelta = -deltaData .* (deltaData < 0);
if type == 's'
smaPositiveDelta = sma(positiveDelta, nPeriod);
smaNegativeDelta = sma(negativeDelta, nPeriod);
RSI = smaPositiveDelta./(smaPositiveDelta + smaNegativeDelta)*100;
RSI = [nan(nPeriod,n); RSI(nPeriod:end, :)];
else
seedPositiveDelta = mean(positiveDelta(1:nPeriod, :));
positiveDelta(1:nPeriod, :) = seedPositiveDelta(ones(nPeriod,1), 1:n);
seedNegativeDelta = mean(negativeDelta(1:nPeriod, :));
negativeDelta(1:nPeriod, :) = seedNegativeDelta(ones(nPeriod,1), 1:n);
alpha = 1/nPeriod;
emaPositiveDelta = ema(positiveDelta, alpha);
emaNegativeDelta = ema(negativeDelta, alpha);
RSI = emaPositiveDelta./(emaPositiveDelta + emaNegativeDelta)*100;
RSI = [nan(nPeriod,n); RSI(nPeriod:end, :)];
end
【在 D******4 的大作中提到】 : thanks so much.~ : This calculation makes sense. About MS, do I have to use EMA to calculate : RSI(2)? I tested RSI(2) in MATLAB, its own function to calculate seeme to : use Simple MA. : btw, do you know how to tackle with time series data in C++? : : movin : stats
| D******4 发帖数: 47 | 6 Thanks a lot.
I was given the assignment to implement a "test trading strategy" in
C++. Since this is my first try, I plan to write the code in MATLAB
first, then think about how to design the class in C++.
I've also written the function to calculate RSI, but not good as yours.
structur
example,
factor; ma
【在 A***l 的大作中提到】 : We don't use C++. My guess is a vector of maps or a dictionary data structur : e will do. : People don't use or interpret tehnical signals in the same way. For example, : in exponential moving average, some signals use 1/N as the decay factor; ma : ny others use 1/(2N+1). : The following is a Matlab funciton that I use to calculate RSI. : function RSI = rsi(data, nPeriod, type) : % PURPOSE: calculates the relative strength indicator for data : %-------------------------------------------------------------------------- : % USAGE: RSI = rsi(data, nPeriod, type)
| l*********o 发帖数: 3091 | |
|