Skip to content

Technical Indicator Stock Selection (US Market)

High RSI Strategy

RSI (Relative Strength Index) is a widely used technical analysis indicator that measures the magnitude of recent price changes to evaluate overbought or oversold conditions. This strategy selects the 20 US stocks with the highest RSI values and rebalances the portfolio weekly.

Using data.indicator('RSI', timeperiod=20) computes the 20-day RSI for all stocks, and is_largest(20) selects the top 20 stocks by RSI value.

from finlab import data
from finlab.backtest import sim
from finlab.market import USMarket

data.set_market('us')

close = data.get('price:adj_close')
close = close[close.index.dayofweek < 5]  # remove weekends

# Select top 20 stocks by RSI
rsi = data.indicator('RSI', timeperiod=20)
position = rsi.is_largest(20)

# Backtest with weekly (W) rebalancing
report = sim(position, resample='W', market=USMarket(), fee_ratio=0.001, tax_ratio=0)
report.display()

Key Parameters

  • timeperiod=20: The lookback window for the RSI calculation. A 20-day RSI smooths out short-term noise compared to the more common 14-day RSI, while still capturing recent momentum.
  • is_largest(20): Selects the 20 stocks with the highest RSI values. High RSI stocks are exhibiting strong upward momentum.
  • resample='W': Rebalances once per week. This balances responsiveness to momentum shifts against excessive trading costs.
  • fee_ratio=0.001: Commission rate of 0.1%, a reasonable estimate for US brokerage fees.
  • tax_ratio=0: No transaction tax on US stock trades (capital gains tax is handled separately and not modeled in the backtest).

Expected Behavior

This is a momentum-chasing strategy: it buys stocks that have been rising strongly. In trending markets, high-RSI stocks tend to continue their upward trajectory, generating excess returns. However, in choppy or mean-reverting markets, buying overbought stocks can lead to drawdowns as prices snap back. The weekly rebalancing frequency helps capture medium-term momentum while limiting turnover.