[Weekly research report] Market timing based on the relative strength of resistance support (RSRS)

The 106th original article focuses on "personal growth and wealth freedom, the logic of world operation, AI quantitative investment".

The research report to be reproduced today is: "Everbright Securities_Financial Engineering Depth: Market Timing Based on the Relative Strength of Resistance Support (RSRS) - One of the Technical Timing Series Reports".

The core of the research report is to propose an indicator and build a strategy based on it. This indicator is RSRS (Relative Strength of Resistance Support). We have implemented this indicator based on backtrader. You can refer to the previous article: Momentum rotation and the implementation of Everbright RSRS indicators in backtrader

Resistance Support Index RSRS Strategy: Everbright Securities Research Reappears

RSRS indicator, the realization of relative resistance support indicator, qlib expands its own characteristic expression

Our current framework extracts the code of qlib's factor expression, uses its own hdf5 storage, and does not use the data format that comes with qlib.

So a little more introduction is needed.

class RSRS(PairOperator):
    def __init__(self, feature_left, feature_right, N, M):
        self.N = N
        self.M = M
        super(RSRS, self).__init__(feature_left, feature_right)

    def _load_internal(self, instrument):
        series_left = self.feature_left.load(instrument)
        series_right = self.feature_right.load(instrument)

        slope = []
        R2 = []
        # Calculate the slope value
        n = self.N
        for i in range(len(series_left)):
            if i < (self.N - 1):
                slope.append(pd.NA)
                R2.append(pd.NA)
            else:
                x = series_right[i - n + 1:i + 1]
                # iloc close left and open right
                x = sm.add_constant(x)
                y = series_left.iloc[i - n + 1:i + 1]
                regr = sm.OLS(y, x)
                res = regr.fit()
                beta = round(res.params[1], 2) # slope indicator
                slope.append(beta)
                R2.append(res.rsquared)

        betas = pd.Series(slope, index=series_left.index)
        betas.name = 'betas'
        r2 = pd.Series(R2, index=series_left.index)
        r2.name = 'r2'
        return betas, r2

It is helpless to use numpy in a circular manner. I have not found a method for rolling two sequences of calculations . If anyone has a method, please let me know.

The indicators are calculated and the strategy is quickly written. This is the benefit of our "building block" strategy development!

e = BacktraderEngine(init_cash=100000, start=datetime(2005, 1, 1), end=datetime(2017, 4, 30))

# 1. Add a data set, the asset candidate set
symbols = ['000300.SH']
for s in symbols:
    e.add_data(s)

# 2. Feature engineering
from engine.datafeed.dataloader import Dataloader

names = []
fields = []

fields += ["RSRS($high,$low,18,600)"]
names += ['RSRS']

fields += ["Ref($close,-1)/$close - 1"]
names += ['label']

names += ['buy',
          'sell']
fields += ['$RSRS_betas>1',
           '$RSRS_betas<0.8']

D = Dataloader()
data = D.load_one_df(symbols, names, fields)
print(data)

# 3. "Building Block Strategy"
from engine.strategy.strategy_base import StratgeyAlgoBase
from engine.strategy.algos import SelectBySignal, WeightEqually

e.cerebro.addstrategy(StrateyAlgoBase, algo_list=[
    SelectBySignal(features=data),
    WeightEqually()
])

e.run()
e.analysis()

The annualized rate is 19.1%, and the maximum retracement is 50.6%, which is similar to the results of the research report (excluding transaction costs).

summary:

Today, we mainly re-developed the RSRS indicator on our own AI quantification platform. A few optimization points:

1. The latter factor is now supported, and the calculation result of the former column is used. For example, mom_20 is calculated in the front, and $mom_20 can be used to refer directly later—this is not possible in the qlib framework.

2. Support returning multiple series, such as RSRS_betas, RSRS_r2, or Bollinger Bands, which can return the upper and lower tracks at a time, without writing twice. The factor expression of this qlib is also not supported.

The reappeared results are similar to the research report, and interested students can continue to make standard scores and revised standard scores.

In addition, the RSRS indicator does not seem to be working well in recent years, and the official follow-up research report also confirmed this. But the idea in the research report is still good, and it is worth learning.

For the complete code and data, please go to the planet-quantification column to download.

A research report is reproduced every week. In addition, if you have any questions, please ask questions in the planet, or the exclusive planet group.

おすすめ

転載: blog.csdn.net/weixin_38175458/article/details/127886287