

For this particular implementation I have used the following libraries:
INDICATOR FOR EMA STOCK CROSSOVER CODE
Make sure to follow the previous tutorial here, which describes how the initial object hierarchy for the backtester is constructed, otherwise the code below will not work. Thus if we wish to implement our own backtester we need to ensure that it matches the results in zipline, as a basic means of validation. This is the example provided by the zipline algorithmic trading library. (AAPL) as the time series, with a short lookback of 100 days and a long lookback of 400 days. The strategy works well when a time series enters a period of strong trend and then slowly reverses the trend.įor this example, I have chosen Apple, Inc. If the longer average subsequently exceeds the shorter average, the asset is sold back. Signals to purchase the asset occur when the shorter lookback moving average exceeds the longer lookback moving average. Two separate simple moving average filters are created, with varying lookback periods, of a particular time series. The strategy as outlined here is long-only. It is often considered the "Hello World" example for quantitative trading. The Moving Average Crossover technique is an extremely well-known simplistic momentum strategy. In this article we will make use of the machinery we introduced to carry out research on an actual strategy, namely the Moving Average Crossover on AAPL.

In the previous article on Research Backtesting Environments In Python With Pandas we created an object-oriented research-based backtesting environment and tested it on a random forecasting strategy.
