Algotrading Journal 2022/1 Algotrading: RSTrend Model on ITS4.SA Bruno Weber Maurer Insper São Paulo Abstract — The RSTrend algorithmic is a trading model that uses a different mix of technical indicators, such as RSI, moving average, z - scores, RSI differences between the chosen asset and its benchmark and a sum signal for upward and downward trends bigger than seven days . As so, this model will be tested on ITS4.SA (Itaúsa), with Ibovespa as the benchmark. Keywords — Algotrading, RSI, Moving Average, Ibovespa. I. I NTRODUCTION Algorithmic trading is a method of executing orders using automated pre - programmed instructions regarding the referent asset, this can be done utilizing price, volume, and time data. Although, it is important to mention that the more well - built algorithm is, that is: accounting risk possibilities, type of order sent to the market and eff iciency of indicators used; then, the higher capability of the algorithm working efficiently. So, it is by these mechanisms that a model of algo - trading will be buil t and simulated in a chosen asset in a period of 10 years, with daily data. Beyond that, th e model will give us the type of order to be sent, specifically: buy, sell, or hold. Everything mentioned has a single objective: testing the efficiency of the created model, arbitrary to its own mechanisms, so that, at least, we get to a profitable strate gy, even though it may or may no t beat its benchmark which is the IBOVESPA in this cas e. The created model ( RSTrend ) is configured to capture short term mean reversions with basis on indicators of trend exhaustion. As so, this model has 4 technical indicat ors: • RSI (5 weeks); • Sum of consecutive days falling/rising (run s ); • Difference between RSI (14 days) of the asset and its benchmark; • Z - score of 13 weeks ; Now, the indicators and its parameters will be specified separately, in a way that the reader can under stand what their objectives and usages are. II. M ETHODOLOGY A. RSI The Relative Strength Index (R SI) is a momentum indicator used in technical analysis that measures the magnitude of recent price changes to evaluate overbought or oversold conditions in the price of a stock or other asset. The RSI is displayed as an oscillator (a line graph that moves between two extremes) and can have a reading from 0 to 100. The indicator was originally developed by J. Welles Wilder Jr. and introduced in his seminal 1978 book, “ New Concepts in Technical Trading Systems”. This indicator will give us an indication of short term mean reversion, and its parameters and frequency were calibrated in backtests; Values: 𝑖𝑓 𝑅𝑆𝐼 5 𝑊 ≥ 70 → − 1 𝑖𝑓 𝑅𝑆𝐼 5 𝑊 ≤ 30 → + 1 B. “Runs” This indicator measures the total number of days that a chose n asset had its price rising or falling, even throughout a running trading floor. If he runs in the same direction for a lot of days, it is expected that the trend reverts in the short term. Each positive day had a signal of + 1 which would be turned into z ero if the following day had a short fall, as so, the sum of 7 consecutive days was calculated, positive returns had a signal of + 1 , and negative returns a signal of − 1 If 7 days had a short or upward trend, the final signal would be sent to the model. 𝑖 𝑓 𝑅𝑢𝑛 ≥ 7 → − 1 𝑖𝑓 𝑅𝑢𝑛 ≤ − 7 → + 1 C. RSI Difference This indicator measures the d ifference between the stock RSI (14 days) and the Ibovespa RSI (14 days), the hypothesis is based on that if the RSI of the stock distances himself too much from the mean (Ibovespa) we should expect a short - term convergence. This way, the relevant differences considered were + 25 𝑎𝑛𝑑 − 25 𝑖𝑓 𝑅𝑆𝐼 𝑑𝑖𝑓𝑓 ≥ 25 → − 1 𝑖𝑓 𝑅𝑆𝐼 𝑑𝑖𝑓𝑓 ≤ − 25 → + 1 D. Z - Score The z - score indicator m easures how much the current price distances itself from the historic mean, in standard deviation terms. Considering that high z - scores are signs of short - term mean reversion. The timeframe which the backtests were calibrated is of 13 weeks; and the significant standard deviation value was calibrated to that of 1.25: 𝑖𝑓 𝑧 − 𝑠𝑐𝑜𝑟𝑒 > 1 25 → − 1 𝑖𝑓 𝑧 − 𝑠𝑐𝑜𝑟𝑒 < 1 25 → + 1 E. Moving Average The moving average indicator i s the average of the asset price over asset number of days. The term “moving” is used because the group of data moves forward with each new trading day. For each new day, we include the price of that day and exclude the price of the first day in the data sequence. In th is case, only one moving average of 250 days was used When the current price crosses above the average, the price is considered to be on a n upward trend, while if it crosses below the average it is considered to be on a downward trend. 𝑖𝑓 𝑝𝑟𝑖𝑐𝑒 > 𝑎𝑣𝑒𝑟 𝑎 𝑔𝑒 → 𝑢𝑝𝑤𝑎𝑟𝑑 𝑡𝑟𝑒𝑛𝑑 𝑖𝑓 𝑝𝑟𝑖𝑐𝑒 < 𝑎𝑣𝑒𝑟𝑎𝑔𝑒 → 𝑑𝑜𝑤𝑛𝑤𝑎𝑟𝑑 𝑡𝑟𝑒𝑛𝑑 Then, this interpretation could be used to estimate the portfolio allocation on the chosen asset, for example if the stock is on a downward trend, and the model send b uy signals, the weight of the buy order should be lower than it would be if there was an upward trend instead. III. S CORE OF THE SIGNALS The final score used i s the sum of all the signals created through the model, with the maximum score of +4, and the minimum of - 4. Considering the nature of the indicators, the following calibration was utilized: • Weak signal → +2 / - 2 • Moderate signal → +3 / - 3 • Strong signal → +4 / - 4 As so, it is observed empirically that processes of mean reversion, with markets following a trend, tend to be short - term. This way, the relevant horizon of investment used was that of, at maximum, 15 days This model can be used and recalibrated for different classes of assets and relevant markets. Markets that are on “range” (moving horizontally), at long - term, tend to make the model less useful for them. IV. R ESULTS The results and signals obtained were calculated through an Excel spreadsheet, with the amount of 26 buy and 46 sell signals through 10 years of utilized data, that is , 72 tra des only on ITSA4.SA. TABLE I. S IGNALS RESULTS Buy Signals Sell Signals Following Trend 19 18 Not F ollowing T rend 5 28 a. Created by the author. TABLE II. T RADING RESULTS S ELLING RETURNS BUYING RETURNS M EAN (%) 1.56% 3.42% M AX PROFIT (%) 38.83% 27.49% M AX DRAWDOWN (%) 11.58% 20.58% a. Created by the author. As seen above, sell signals have a proportion of, basically, 3:1 between its max profit and drawdown, while buying returns have a 1.3:1 proportion. Although the mean returns of a buying signal are two times bigger than a sell sign. V. C ONCLUSION Although the results were a cceptable, the system of trading could be built taking other factors into consideration, not only the price, but volume as well, with an indicator of the divergence between volume and volatility (vol/vol), for example. Beyond that, even though technical ind icators are somewhat useful, is their mix of parameters that can give us a reasonable trading strategy, so multiple parameters and combinations should be tested too, using different time periods, assets and criteria . For example, testing between common st ocks of different sectors, testing commodities, indexes, etc. So, algo - trading keeps being a difficult tool to master, a good strategy and set of rules can fuel our hands with the much - appreciated money our society keeps chasing, but, just as the “holy gra il” searched in the old fabulas, it is necessary for testing, data searching and useful information for it to be achieved. With no effective bonds to the strategies we made, the search and construction of algo - trading mechanisms is continuous , with rights a nd wrongs along the road, the only certainty we have is what we’ll learn, be it the market microstructure, be it the knowledge of what works or does not work. The next steps of the algorithmic could be generalizing the indicators utilized here to a bigger gamma of assets . Such as the entire Ibovespa, for example. This way, we could interact and trade using multiple assets, since most of the time ITSA4.SA had no trading signals at all, while other stocks probably had some, if the data was being analyzed.