Get startedGet started for free

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.

This exercise is part of the course

Financial Trading in Python

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Construct the signal
signal[____ > ____] = -1
signal[____ < ____] = 1
signal[(____ <= ____) & (____ >= ____)] = 0
Edit and Run Code