Tutorials

Basic RSI strategy

Backtest a complete RSI strategy from signals to performance

One of the main strengths of VBT (PRO) is its ability to quickly create and backtest multiple strategy configurations. In this introductory example, we will explore the profitability of the following RSI strategy, which is commonly used by beginners:

If the RSI is below 30, it suggests that a stock is reaching oversold conditions and may soon experience a trend reversal or a bounce back to a higher share price. Once the reversal is confirmed, a buy trade is executed. Conversely, if the RSI is above 70, it indicates that a stock is reaching overbought conditions and may experience a trend reversal or a pullback in price. After the reversal is confirmed, a sell trade is executed.

As a bonus, we will gradually expand the analysis to include multiple parameter combinations. Sound interesting? Let's get started.

Single backtest

First, let's handle the data. With a simple one-liner, we can download all available daily data for the BTC/USDT pair from Binance:

from vectorbtpro import *  

data = vbt.BinanceData.pull('BTCUSDT', end='2022-08-04 UTC')
data
<vectorbtpro.data.custom.binance.BinanceData at 0x7f9c40c59550>
100%

The returned object is of type BinanceData, which extends Data to interact with the Binance API. The Data class is VBT's built-in container for retrieving, storing, and managing data. When a DataFrame is received, it is post-processed and stored inside the dictionary Data.data, keyed by pair (also known as a "symbol" in VBT). You can access your DataFrame either from this dictionary or by using the convenient Data.get method, which lets you specify one or more columns instead of returning the entire DataFrame.

Let's plot the data using Data.plot:

data.plot().show()  

Another way to describe the data is by using Pandas' info method. The tabular format is very helpful for counting null values (it looks like our data does not have any—great!)

data.data['BTCUSDT'].info()
<class 'pandas.DataFrame'>
DatetimeIndex: 1813 entries, 2017-08-17 00:00:00+00:00 to 2022-08-03 00:00:00+00:00
Freq: D
Data columns (total 9 columns):
 #   Column              Non-Null Count  Dtype
---  ------              --------------  -----
 0   Open                1813 non-null   float64
 1   High                1813 non-null   float64
 2   Low                 1813 non-null   float64
 3   Close               1813 non-null   float64
 4   Volume              1813 non-null   float64
 5   Quote volume        1813 non-null   float64
 6   Trade count         1813 non-null   int64
 7   Taker base volume   1813 non-null   float64
 8   Taker quote volume  1813 non-null   float64
dtypes: float64(8), int64(1)
memory usage: 141.6 KB

In our example, we will generate signals based on the opening price and execute them using the closing price. We could also place orders as soon as the signal is generated, or at a later time, but here we will show how to separate the generation of signals from their execution.

open_price = data.get('Open')
close_price = data.get('Close')  

Now it is time to run the indicator!

VBT supports five different RSI implementations: one written using Numba, and four more ported from three different technical analysis libraries. Each indicator is wrapped with the versatile IndicatorFactory. 🦾

To list all available indicators or search for a specific one, use IndicatorFactory.list_indicators:

vbt.IF.list_indicators("RSI*")
['vbt:RSI', 'talib:RSI', 'pandas_ta:RSI', 'ta:RSIIndicator', 'technical:RSI']

You can retrieve the actual indicator class like this:

vbt.indicator("talib:RSI")
vectorbtpro.indicators.factory.talib.RSI

Or manually:

vbt.RSI  
vectorbtpro.indicators.custom.rsi.RSI
vbt.talib('RSI')  
vectorbtpro.indicators.factory.talib.RSI
vbt.ta('RSIIndicator')  
vectorbtpro.indicators.factory.ta.RSIIndicator
vbt.pandas_ta('RSI')  
vectorbtpro.indicators.factory.pandas_ta.RSI
vbt.technical('RSI')  
vectorbtpro.indicators.factory.technical.RSI

Here is a general rule for choosing an implementation:

✅ Learn the essentials of VBT by backtesting a basic RSI strategy.

Copyright © 2021–2026 Oleg Polakow. All rights reserved.

Site content and documentation are provided for using and evaluating VectorBT PRO and for educational purposes. Any other use, including building or supporting competing products or services, requires prior written consent.