LoslegenKostenlos loslegen

Build and backtest a trend-following strategy

Previously, you constructed a signal using two EMA indicators. When the shorter-term EMA is larger than the longer-term EMA, the signal is 1 for entering long positions in the market. Vice versa, when the shorter-term EMA is smaller than the longer-term EMA, the signal is -1 for entering short positions. Now you will implement a trend-following strategy with your signal and perform a backtest using the Google stock.

The historical price data of the Google stock has been preloaded in price_data. The bt package has been imported for you. In addition, signal from the previous exercise is available to use.

Diese Übung ist Teil des Kurses

Financial Trading in Python

Kurs anzeigen

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Define the strategy
bt_strategy = bt.Strategy('EMA_crossover', 
                          [____,
                           bt.algos.Rebalance()])
Code bearbeiten und ausführen