CommencerCommencer gratuitement

Construct an RSI based signal

It's time to implement your first mean-reversion strategy. Mean reversion trading uses signals to detect market imbalance, and takes long positions in an oversold market and short positions in an overbought market.

First, you will use the RSI indicator to gauge market conditions and construct the signal. If the RSI value drops below 30, you will enter long positions. If the RSI value rises above 70, you will enter short positions. If the RSI value is in between 30 and 70, you will take no positions.

The RSI indicator has been pre-calculated and saved in stock_rsi. The historical price data of the Google stock has been preloaded in price_data. In addition, the bt package has been imported for you.

Cet exercice fait partie du cours

Financial Trading in Python

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Construct the signal
signal[____ > ____] = -1
signal[____ < ____] = 1
signal[(____ <= ____) & (____ >= ____)] = 0
Modifier et exécuter le code