Trading Stocks in the S&P 500 to Beat the S&P 500

Trading Stocks in the S&P 500 to Beat the S&P 500

Trading Stocks in the S&P 500 to Beat the S&P 500 : 1. Introduction

Constructed of the largest public companies, the Standard & Poor’s 500 Index (S&P 500) is a great indicator of the U.S. economy and of the performance of large-cap equities (Investopedia, n.d.). It is therefore one of the most commonly followed indices, and the subject of study in this report.

This report discusses two strategies that build portfolios with selected S&P 500 components and aim to outperform the index. The strategies are based on the concept of Momentum Trading: to long stocks at certain points on their upward price trends, and to sell them when stock prices are close to their peaks (Investopedia, n.d.).

In the first strategy of this report, the entry points are selected by calculating the exponential moving averages for each underlying stock of the index and fitting an exponential regression model. In the second method, the efficiency ratio is added into consideration when selecting stocks to long.

All S&P 500 components are ranked on a daily basis in both methods. The top 100 stocks in the ranked lists are then used to update the portfolio once a week (or once per day).

This report also introduces the backtesting results and the risk analysis for both models, in order to compare the effectiveness of the two.

2. Data Input

To develop and test the trading strategies, stock data of the S&P 500 components from 2010 to 2018 have been used in this report. Within a list of all the historical tickers in the S&P 500 (Quandl, n.d.), the ones that were removed before 2010 or added after 2018 were filtered out, leaving all the companies that could be traded during this time period for model testing[1]. The daily stock prices and trading volumes were obtained from Quandl and Yahoo Finance and processed in Python (Appendix 1).

3. Strategy Construction and Implementation

  1. Exponential Moving Average and Exponential regression

For the first momentum strategy, we use exponential moving average and exponential regression. The assumption is that the stocks follow exponential growth. The basic concept is too long stocks with upward-trending prices. 

We first calculate the 100-day exponential moving average for each stock within the S&P 500. Then for each stock, we compare the moving average with the current price and assign signals (A). If the current price is higher than the moving average, the stock is upward-trending and will be assigned. If it’s the opposite, it will be assigned 0.

Next, we fit a 90-day exponential regression model with rolling calculation to the stocks. We will obtain the slope and R-squared value. We then annualize the slope and multiply it by the R-squared value to get a different set of signals (B). 

In the end, we multiply signal A by signal B to get another set of values. We rank the values from the highest to the lowest and select the top 100 stocks into the portfolio. The portfolio will be adjusted weekly on each Wednesday and every stock will be invested with equal weight. 

  1. Efficiency Ratio (ER) and Tri Cross EMA Strategy

The efficiency ratio is a concept presented by American Trader Perry Kaufman in his book Smarter Trading in 1995. A higher efficiency ratio means the stock is more successful in generating income. We calculate the efficiency ratio based on the price of the past 60 days. Below is the efficiency ratio calculation formula:

Direction/Volatility = ABS (Close – Close[n])/n ∑ (ABS(Close – Close[1]))

In addition to the ER, a cross EMA signal is calculated with 50, 100, and 200 days moving average for each day. Ideally, we expect the moving average to have an EMA(50) > EMA (100) > EMA(200), which indicates that the stock has an upward trend. 

Then we combine the EMA signal matrix with the ER matrix to generate a set of signals of each stock every day. As a higher signal indicates a higher potential for the stock price to increase, we will long the top 100 stocks with the highest signal value. The portfolio is updated daily and stocks are invested equally with 1% of the total portfolio value (each weight of the stock is 0.01). 

4. Backtesting

Backtesting assesses the viability of the trading strategies and helps analysts know what to expect when applying strategies to real-world markets.

This section mainly focuses on the backtesting process of the two strategies – the exponential moving average model and the efficiency ratio model. The benchmark is the performance of the S&P 500. We assume that we buy at the open price and sell at the close price, with transaction cost being 0.02% and slippage being 0.01%. The initial investment is $100,000. 

Metrics used in the backtesting process are performance metrics. The first metric is the Sharpe ratio, which helps investors understand the return of the investment compared to its risk.

A high Sharpe ratio is considered good when compared to similar portfolios or funds with lower returns. The other metric used is the annualized return, which is the geometric average amount of money earned by the investment each year.

To examine the performance of the two strategies, the benchmark performance is calculated. The annual return of the S&P 500 from 2010 – 2018 is 9.4% and the Sharpe ratio is 0.7.

The results of the backtesting are as follows: 

1) Exponential Moving Average Model

The exponential moving average model has an annualized return of -3.7% and a Sharpe ratio of -0.23. Compared to the benchmark, this strategy has a lower return after 2012 with a negative Sharpe ratio. Appendix 2 attached below shows the difference of return between the moving average model and the S&P 500.

2) Efficiency Ratio Model

The efficiency ratio model has an annualized return of 23%, with a positive Sharpe ratio of 1.81. Compared to the benchmark, this strategy has a higher return with a higher Sharpe ratio. Appendix 5 shown below shows the difference of return between the moving average model and the S&P 500. If $10,000 is invested in 2010, the return in 2019 will be $60,000 to $70,000.

5. Model Evaluation

To further evaluate the performance of the portfolios chosen by the two strategies, risk analysis has been conducted on both of the chosen two stock portfolios and the benchmark S&P 500 index. Several risk parameters are calculated: annual volatility, alpha, max drawdown, and value at risk (VaR).

The values of annual volatility, alpha, and max drawdown for the stock portfolios and benchmark were obtained during the back-testing stage using the python library (see table below).

PortfoliosAnnual VolatilityMax DrawdownAlpha
S&P 50014.3%-19.6%
Strategy 112.7%-42.2%-0.03
Strategy 211.8%-13.1%0.24

Value at Risk (VaR) is a measure of calculating the maximum potential loss for an instrument over some time period T, given a specific probability P%. In the calculation, the confidence level is chosen to be 90%, and VaR is calculated using the historical method which assumes that the historical distribution of the market changes is the same as today’s distribution of market changes. A starting value of $100,000 is given to each portfolio to help normalize the data.

Trading Stocks in the S&P 500 to Beat the S&P 500

Then the daily percent change of the portfolio values is calculated, and the daily loss is calculated as the starting value of $100,000 multiplied by the daily percent change. A list consisting of the daily loss across the 9-year data frame is then generated. By sorting the list in descending order, 90% VaR equals the 10% quantile worst loss. The values of VaR for the two portfolios and the S&P 500 index are compared by plotting the VaR values against time (see figure below).

Figure 1 The graph shows the VaR comparison between the two portfolios chosen by the strategies and S&P 500 index.

From the results of annual volatility, alpha, and max drawdown, the portfolio that was chosen by the second strategy gave the fewest oscillations, which means it is the least risky compared to the other two. From the results of the VaR calculation, S&P 500 showed the highest VaR value, and the portfolio chosen by strategy 2 (the efficient ratio strategy) showed the lowest values, agreeing with the conclusion from other risk measures mentioned above.

6. Conclusion

The portfolio chosen by the efficiency ratio strategy shows higher annual return and lower oscillation compared to the one chosen by the exponential moving average and exponential regression strategy; thus, the efficiency ratio strategy performs better for the data frame chosen.

Appendix 1. Processed Data Structure

Appendix 2: Cumulative returns of the S&P 500 and the Exponential Moving Average Model

Appendix 3: Sharpe Ratio of the S&P 500 and the Exponential Moving Average Model

Appendix 4: Backtesting Results of the Exponential Moving Average Model

Appendix 5: Cumulative returns of the S&P 500 and the Efficiency Ratio Model

Trading Stocks in the S&P 500 to Beat the S&P 500

Written by Wenjing Chen, Qinyi Li, Wenxin Mu, Amanda Song & Mengqing Xiao

Trading Stocks in the S&P 500 to Beat the S&P 500

Edited by Alexander Fleiss

Leading Artificial Intelligence and Financial Advisor – Rebellion Research