• Free Book
  • Store
    • Books
    • Free First Chapters
    • Free Newsletters
  • Recent Articles

TradingMarkets.com

Quantified Stock Market Trading Strategies & Systems

  • Home
  • New Trading Research
  • Education
    • Articles
      • Connors Research
      • ETFs
      • Options
      • Stocks
      • Volatility
    • Trading Lessons
    • Connors Research
    • Glossary
    • Interview Archive
    • Videos
  • Python
  • Quantamentals
    • Quantamentals: The Next Great Forefront of Trading and Investing
    • Quantamentals Resources
  • Courses
  • Store
    • New Book! The Alpha Formula
    • “Buy The Fear, Sell The Greed” – Best Seller!
    • Swing Trading College 2019
    • Trading Books and Guidebooks
    • Street Smarts
    • Online Trading Courses
    • Private Mentoring with Larry Connors
    • Customized Trading Research
    • Amibroker Strategy Add On Modules
You are here: Home / Connors Research / Connors Research Traders Journal (Volume 40): Using the Power of Python to Build and Test a High Performing Relative Momentum Stock Strategy

Connors Research Traders Journal (Volume 40): Using the Power of Python to Build and Test a High Performing Relative Momentum Stock Strategy

April 16, 2019 by Larry Connors and Chris Cain, CMT

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.

Strategy Rules

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.

In fact, in the webinar, we’ll show you how you can go from zero programming experience to building high performing trading strategies in only 5 weeks!

To attend our free webinar, please click here to register now.

 

Larry Connors and Chris Cain

Connors Research

Filed Under: Connors Research, Connors Research Newsletter, Connors Research Traders Journal, Python, Recent, SPY Tagged With: python, Trading Lessons, Trading Strategies

Buy The Fear, Sell The Greed

Buy The Fear, Sell The Greed

Swing Trading College

New Book From Larry Connors and Chris Cain, CMT – "The Alpha Formula; High Powered Strategies to Beat The Market With Less Risk"

We’re excited to announce the release of a new investment book written by Larry Connors and Chris Cain, CMT. The book, “The Alpha Formula; High Powered Strategies to Beat The Market With Less Risk “ combines… Hedge fund legend Ray Dalio’s brilliant insight into combining uncorrelated strategies… With new, minimally correlated, quantified, systematic strategies to trade… [Read More]

Buy The Alpha Formula Now

Connors Research Traders Journal (Volume 57): 7 Real-World Reasons Why Short Strategies Should Be Included In Your Portfolio

In our new book, The Alpha Formula – High Powered Strategies to Beat the Market with Less Risk, we show the benefits of including short-strategies in your portfolio. As a reminder, building portfolios should be based on First Principles – otherwise known as truths. These truths are: Markets Go Up Market Go Down Markets Go… [Read More]

Company Info

The Connors Group, Inc.
185 Hudson St., Suite 2500
Jersey City, NJ 07311
www.cg3.com

About Us

About
Careers
Contact Us
Link To Us

Company Resources

Help
Privacy Policy
Return Policy
Terms & Conditions

Properties

TradingMarkets
Connors Research

Connect with TradingMarkets

Contact

info@cg3.com
973-494-7311 ext. 628

Free Book

Short Term Trading Strategies That Work

© Copyright 2020 The Connors Group, Inc.

Copyright © 2023 · News Pro Theme on Genesis Framework · WordPress · Log in