RSRS (Resistance Support Relative Strength), also known as Resistance Support Relative Strength, is another way of using resistance and support levels. It no longer treats resistance and support levels as fixed values, but as variables that reflect traders' expectations of the current market conditions. Everbright Securities published a research report on May 1, 2017, titled "Market Timing Based on Resistance Support Relative Strength (RSRS)", and many studies are currently based on this report.
1. Calculation Method of RSRS Indicator#
The RSRS indicator is actually the slope between the highest price and the lowest price, which is calculated mainly through regression. Like other common technical indicators, it also requires a certain amount of time series data. In general, we take the past 18 days' highest and lowest prices.
- Take the sequence of highest and lowest prices from the past N days. (N = 18)
- Perform OLS linear regression on the two sequences.
- Take the fitted β value as the daily RSRS slope indicator value.
The specific code is as follows (this code runs on the JoinQuant platform), and through the code below, we can obtain the time series of the RSRS indicator.
import statsmodels.api as sm
from pandas.stats.api import ols
prices = get_price('000300.XSHG', '2020-06-01', '2020-07-20', '1d', ['high', 'low'])
highs = prices.high
lows = prices.low
ans = []
N=18
for i in range(len(highs)[N:]):
data_high = highs.iloc[i-N+1+1]
data_low = lows.iloc[i-N+1+1]
X = sm.add_constant(data_low)
model = sm.OLS(data_high,X)
results = model.fit()
beta = model.fit().params[1]
ans.append(beta)
# Calculate r2
r2=model.fit().rsquared
ans_rightdev.append(r2)
It is important to note the writing style of the for loop in this code:
Start the loop from N (N=18) and then decrement. The code below may seem the same, but it will actually throw an error because when it reaches the last data segment, i+N will not be able to retrieve data.
for i in range(len(highs)):
data_high = highs.iloc[i+1+N+1]
data_low = lows.iloc[i+1+N+1]
X = sm.add_constant(data_low)
model = sm.OLS(data_high,X)
results = model.fit()
beta = model.fit().params[1]
ans.append(beta)
# Calculate r2
r2=model.fit().rsquared
ans_rightdev.append(r2)
Also, note that iloc is inclusive at the start and exclusive at the end, so it requires +1, i.e. i+1, to include the most recent data (although this will result in the first day not being included, it doesn't have a significant impact due to the early data).
2. Standardization of the RSRS Indicator#
Since the mean of the slope has significant fluctuations in different market periods, it is not appropriate to directly use the mean slope as a timing indicator. Standardization is performed based on the slope to obtain the standard score as the indicator value. The calculation method for the RSRS slope standard score indicator is as follows:
- Take the time series of RSRS slopes from the past M days. (M = 600)
- Calculate the standard score of the RSRS slope for the current day (RSRSstd).
Calculate the standardized RSRS indicator#
Calculate the mean sequence#
section = g.ans[-g.M:]
Calculate the mean sequence#
mu = np.mean(section)
Calculate the standardized RSRS indicator sequence#
sigma = np.std(section)
zscore = (section[-1]-mu)/sigma
3. Right Skewness Standard Score of the RSRS Indicator#
Before discussing the right skewness standard score, it is necessary to mention skewness distribution. Skewness distribution is the opposite of "normal distribution" and refers to the distribution of data that is asymmetric in shape, with unequal frequencies on the left and right sides of the distribution curve. It is a characteristic of the probability distribution of continuous random variables. Skewness can be measured by calculating kurtosis and skewness, which measure the degree of skewness. It can be divided into left skewness (also known as negative skewness) and right skewness (also known as positive skewness). Skewness is a characteristic that describes the degree of deviation from symmetry in the distribution. It is important to note that "deviation" is used here, not "bias". Therefore, left skewness means deviation from the left side, and right skewness means deviation from the right side. The former has a longer left tail and a shorter right tail, while the latter has a longer right tail and a shorter left tail.
After the right skewness standardization of RSRS, the probability of buying is reduced while the probability of selling is increased, making risk control more effective. The specific operation is to multiply the standardized slope by the coefficient of determination, which adjusts the standardized slope and then multiplies it by the slope (before standardization).
Calculate the right skewness RSRS standard score#
zscore_rightdev = zscore * r2 * beta
Based on the above calculations, we can obtain the final RSRS indicator. Based on this indicator, a trading strategy can be formulated to buy when the RSRS indicator is greater than 0.7 and sell when it is less than -0.7.
References:
20170501 - 光大证券 - 基于阻力支撑相对强度的市场择时 Download
20191117 - 光大证券 - RSRS 择时回顾与改进 Download
https://www.joinquant.com/view/community/detail/bec17e308647a2160ee1aeeac3a0c40c?type=1
https://www.joinquant.com/view/community/detail/28dc6d6605ce7f7471ff05904ccf046f?type=1
https://www.joinquant.com/view/community/detail/713a60a2a1daaac2276dab73eb322ddc?type=1
https://blog.csdn.net/weixin_43787229/article/details/86735503