In this Connors Research Traders Journal, we are going to show you how Python and Quantopian can take your trading and strategy testing abilities to the next level. We’ll share with you a strong performing, relative momentum strategy which trades individual US equities, dynamically choosing the strongest stocks from a 500 stock universe. This simple to follow strategy has achieved over a 1034% cumulative return since 2003 in testing, compared to 356% for the S&P 500.
Building Great Strategies That Trades Hundreds of Securities is a Large Challenge – Python Provides the Solution
Coding trading strategies involving hundreds of securities is a large technical challenge. How do we deal with delisted stocks or mergers? How do we adjust the data for splits and dividends as to accurately measure the strategies performance through time? How do we handle a constantly changing universe of stocks? How do we write coding logic which is then applied to literally hundreds of securities at once?
While many coders/traders can code strategies on individual securities, dealing with hundreds of securities in one trading strategy presents many practical problems. These problems can be solved using Python, the language of choice for the largest, most sophisticated quantitative hedge funds and trading desks in the world.
Stock Momentum Works – Decades of Research Support This
One of, if not the most, rigorously studied factors in modern finance is the momentum anomaly. Academics have clearly shown that securities that have done well in the past 3-12 months, both on an absolute and relative basis, tend to continue to do well in the future.
Coding and testing a strategy of systematically buying the strongest stocks, however, presents serious technical challenges. Fortunately for us, the Python coding language and the Quantopian platform solves many of these problems for us.
The general design of the strategy is to systematically buy the strongest US stocks on a trailing total return basis, but only when the overall trend of US equities is higher.
Our universe of stocks to choose from is Quantopian’s “Q500US” universe, which is the 500 most liquid US stocks as determined by highest trailing 200-day average dollar volume. The universe is determined on a monthly basis.
Here are the rules for the strategy:
1. Is the ETF “SPY” (S&P 500) above its 200-day moving average? If yes, buy the 20 US stocks, in equal weight, with the highest 5 month total return (105 trading days).
2. Sell any stock when it is no longer in the top 20.
3. If SPY’s price is below its 200-day MA, no new entries are taken.
4. This strategy only trades once a month, at the close of the month.
Note: This strategy sells long stock positions when they are no longer in the top 20 at the end of the month. We only take new entries if our trend filter is passed (SPY > 200-day moving average). As such, this strategy naturally “shuts itself off” when the index is trending lower, aka it doesn’t take new entries.
That’s it, a few simple rules designed to buy the strongest stocks in an overall uptrending market, with the ability to shut itself off if the market begins to decline.
What are the results over the last 16yrs+?
Taking a look at the performance, a few things jump out:
• The annual return over this 16yr+ period is significantly higher than SPY alone (16.1% vs 9.8%). Compounded over 16 years, this leads to a much higher cumulative return of 1,034% vs 356% for the benchmark.
• The max drawdown of the strategy is significantly less than SPY (-34.6% vs -54.9%), which is very impressive considering how much higher our returns were. This is the result of our strategy having the ability to dynamically reduce risk in bear markets.
Here is the cumulative equity curve for our relative momentum stocks strategy vs the S&P 500:
A nice thing about the design of this strategy is that, as mentioned before, it naturally shuts itself off by not taking new entries if the overall market is trending lower. In an environment like 2007/2008, that was extremely valuable!
Here is what this looked like during the Global Financial Crisis (GFC). This chart spans August 2007 to April 2009. Notice our strategy had a return of approximately 20% over this time period vs a -54% drawdown for the index!
Python Combined With The Free Quantopian Platform Allows You To Build Strategies Like This!
The challenge for many traders is to build high performing strategies using dozens, hundreds, and even thousands of securities.
Using Python on the free Quantopian platform allows you to build, test, and optimize strategies like this. The ability to apply your strategies to thousands of stocks at the same time is one of the many reasons why so many of the major institutional trading firms have moved a portion if not all of their testing and strategy development to Python.
You Too Can Build High Performing Trading Strategies In Python, Even If You Have No Programming Experience – Attend A Free Webinar To Learn How
In this 45 minute webinar, we’ll share with you why the majority of the top investment and trading firms have migrated to Python and how you can too.
To attend our free webinar, please click here to register now.
Larry Connors and Chris Cain