Docs
Open Studio

US examples

Technical indicator selection

On this page4

RSI (Relative Strength Index) measures the size of recent price changes to flag overbought or oversold stocks. This strategy buys the 20 US stocks with the highest RSI each week, so it chases momentum: it suits investors who expect strong stocks to keep rising.

Strategy logic

  • Compute the 20-day RSI of every stock with data.indicator('RSI', timeperiod=20).
  • Hold the 20 stocks with the highest RSI (is_largest(20)).
  • Rebalance once a week.

Drag the RSI window and the number of stocks held, then press Play to watch the weekly RSI leaderboard pick:

Interactive level

RSI leaderboard: hold the strongest each week

Mission 1 of 3 Drag “Stocks held” all the way left: Top 1

rsi = data.indicator('RSI', timeperiod=20)
position = rsi.is_largest(3)
report = sim(position, resample='W')
2 AAPL 56
3 MSFT 53
6 NVDA 39
5 AMZN 41
8 GOOGL 27
7 META 39
4 JPM 49
1 KO 62

Ranked at the close of 2026/10/30: the top 3 are held next week

Your strategyAhead +116%
Hold all 8 +110%
Buys 118

Real closes of 8 large caps since January 2024 (RSI from split-adjusted closes). The page's strategy takes the top 20 of the whole market; this one ranks 8. A simplified backtest: equal weights, no fees.

Code

strategy.py
from finlab import data
from finlab.backtest import sim
from finlab.markets.us 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()

How to adjust it

  • timeperiod=20: the RSI lookback window. A 20-day RSI smooths out short-term noise compared with the more common 14-day RSI, while still capturing recent momentum.
  • is_largest(20): how many stocks to hold. High-RSI stocks are the ones showing strong upward momentum.
  • resample='W': rebalances once a week, balancing how quickly the portfolio follows momentum shifts against trading costs. Weekly rebalancing captures medium-term momentum while limiting turnover.
  • fee_ratio=0.001: a 0.1% commission, a reasonable estimate for US brokerage fees.
  • tax_ratio=0: US stock trades carry no transaction tax. Capital gains tax is handled separately and is not modeled in the backtest.

To rank by a different indicator, swap the data.indicator() call; the technical indicators page lists what is available.

↑↓ Move Enter Open Esc Close