Path: blob/master/Analysis/04 EMA Cross Strategy Based on VXX.ipynb
1001 views

Refer to this page for documentation https://www.quantconnect.com/docs#Introduction-to-Jupyter
Contribute to this file https://github.com/QuantConnect/Research/tree/master/Notebooks
EMA Cross Strategy
In this research we will demonstrate a simple EMA cross strategy and how to generate the equity curve for this strategy.
Check the algorithm implementation on LEAN
Here we ignore the fees when we generate the profit curve so the statistics result might be slightly different from the LEAN implementation.
Step 0:
First we define some functions that we need to generate the equity curve.
Step 1:
First, we develop a simple strategy using VXX indicator and generate the trading signals. The strategy is as follows:
Go long the ETFs in the portfolio when the 30-day exponential moving average (EMA) of VXX cross the close from the top, short the ETFs when the 30-day EMA of VXX cross the close from the bottom. The portfolio includes five index ETFs.
Step 2:
Store the price, signal and holding shares quantity in a dictionary keyed by symbols. The quantity is calculated using our function by setting the initial cash and inputting the signal and price.
Step 3:
Calculate the net profit for the strategy and plot the equity curve. Use "SPY" as the benchmark.
Step 4:
Calculatet the statistics to evaluate the performance of the strategy. How to calculate the strategy statistics?
GetPortfolioStatistics(PyObject dataFrame)
GetPortfolioStatistics API gets portfolio Statistics from a pandas.DataFrame with equity and benchmark values. The columns are 'benchmark' and 'equity'. The value is the cumulative profit of the strategy and the benchmark(buy and hold the benchmark equity strategy).
Refer to the QuantBook on Github for details: https://github.com/QuantConnect/Lean/blob/cc46cd367f5a0c415e6ac2462b903a27a86eedcb/Jupyter/QuantBook.cs#L505