CommencerCommencer gratuitement

Build an SMA-based signal strategy

It's time to build and backtest your first signal-based strategy. Although simple, these types of strategies can be effective, and also lay the groundwork for more complex strategies consisting of additional signals and information.

Implementing a price-comparison-based signal with bt is a straightforward process. You will first download some historical price data of the stock, calculate its SMA (simple moving average), implement an SMA-based signal strategy, and then backtest it with the stock price data.

The bt package has been imported for you. The historical price data of the Apple stock has been preloaded in price_data.

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.

# Calculate the SMA
sma = price_data.____
Modifier et exécuter le code