DIY Quant Strategies on Quantopian

24

description

An introduction to implementing 5 basic quant strategies on Quantopian. Presented to the Bay Area Algorithmic Trading Group and the Bay Area Trading Signals meetup groups at the Hacker Dojo Feb 6th, 2014 by Jess Stauth

Transcript of DIY Quant Strategies on Quantopian

Page 1: DIY Quant Strategies on Quantopian
Page 2: DIY Quant Strategies on Quantopian

DIY Quant strategies: Is it possible to roll your own?

Jess Stauth, PhDVP Quant Strategy

Bay Area Algorithmic Trading MeetupHacker Dojo * February 6, 2014

Page 3: DIY Quant Strategies on Quantopian

What makes a good equity quant strategy?

Intuition. If you can’t explain why it works, it doesn’t work.

Reproducibility. If you can’t backtest it, it doesn’t work (note the inverse does not necessarily hold).

Access to data. If you can’t get the signal (or get it in time) you can’t trade it. ($$$)

Capacity/Execution You can’t push a camel through the eye of a needle. (1/$$$)

Page 4: DIY Quant Strategies on Quantopian

5 Basic Quant Strategies1. Mean Reversion – What goes up… (special case: Pairs

Trade)

2. Momentum – The trend is your friend.

3. Valuation – Buy low, sell high.

4. Sentiment – Buy the rumor, sell the news.

5. Seasonality – Sell in May and go away.

Out of scope for today’s talk: Acronym soup (e.g. ML, OLMAR, PCA, ICA, OLS, etc.)Portfolio construction, risk optimization, etc. Asset clases

Page 5: DIY Quant Strategies on Quantopian

Pairs Trading Intuition: Find two assets linked to a single underlying

‘value’ and exploit transient mispricing between them.

Reproducibility: The phenomenon is well documented1,2.

Data: For basic strategies all you need is pricing.

Capacity: Can be quite small depending on the instruments.

Common pitfalls:

Ignore the intuition requirement at your own peril! Cointegration works great, until it doesn’t.

Market neutral or ‘hedged’ strategy, so you are forgoing any upward drift in the longer term.

1. Pairs Trading, Vidyamurthy 20042. Quantitative Trading, Chan 2009

Page 6: DIY Quant Strategies on Quantopian

Simplistic Intuition (cont’d): If you assume the spread between stock 1 and stock 2 is ‘stationary’ and ‘normally distributed’, then statistically you should be able to make money by ‘buying’ or ‘selling’ the spread when it takes on extreme tail values.

Zx = (Price Stock1 – Price Stock2)/ Price Stock1

Pairs Trading

Page 7: DIY Quant Strategies on Quantopian

Pairs Trading: EWA/EWC Pair

6/06 – 6/12 Huapu Pan (NYC Algo Trading meetup member) Posted 12/19/13“Ernie Chan’s EWA/EWC Pair Trading”https://www.quantopian.com/posts/ernie-chans-ewa-slash-ewc-pair-trading

Page 8: DIY Quant Strategies on Quantopian

1. Jegadeesh and Titman, Returns to Buying Winners and Selling Losers: Implications for Stock Market Efficiency. Journal of Finance March 19932. Faber, A Quantitative Approach to Tactical Asset Allocation. Journal of Wealth Management 2013

Intuition: Comes in many flavors (stock level, sector level, asset class level) but comes back to the behavioral bias of ‘herding’.

Reproducibility: The phenomenon is well documented1.

Data: For basic strategies all you need is pricing.

Capacity: Can be quite small depending on the instruments.

Common pitfalls: The trend is your friend, until it isn’t. Reversals can be devastating, especially

when using leverage.

Momentum Trading

Page 9: DIY Quant Strategies on Quantopian

Simple rules based approach Rank 1 > N stocks (sectors) by : [r20 – r200] Buy top K stocks (sectors) where absolute

momentum (20 vs. 200 day MA) > some threshold.

Else, hold cash.

Momentum Trading

Page 10: DIY Quant Strategies on Quantopian

Momentum Trading – Meb Faber RS Strategy

Backtest range: 11/04 – 2/13 John Chia Posted Feb 2013“Mebane Faber Relative Strength Strategy with MA Rule”https://www.quantopian.com/posts/mebane-faber-relative-strength-strategy-with-ma-rule

Page 11: DIY Quant Strategies on Quantopian

Valuation

Intuition: In a nutshell, bargain shopping. Use fundamental ratio analysis to identify stocks trading at a discount (or premium) and buy (or sell) them accordingly.

Reproducibility: The phenomenon is well documented.

Data: Requires good coverage (breadth and depth) of normalized corporate fundamental data.

Capacity: Small cap stocks can be riskier, and higher friction to trade.

Common pitfalls:

Some cheap stocks are cheap for a reason. “Catch a falling knife” adage.

Page 12: DIY Quant Strategies on Quantopian

Simple example: use price to earnings ratio as a proxy for ‘value’ where low P/E looks ‘cheap’ and high P/E looks ‘expensive’.

Rank universe 1-100 (or sector universe) on P/E Long only: buy the bottom (lowest P/E) decile Market neutral: buy the bottom decile, sell the top decile

In practice, a quant model would typically blend a number of backward looking ratios an forward looking estimates along with making sector specific adjustments and other bells, whistles.

Valuation

Page 13: DIY Quant Strategies on Quantopian

Valuation: Screen on corporate fundamentals

Backtest range 11/25/2009 – 10/10/2013Sam Lunt (11/4/2013) “Using Fetcher with Quandl”https://www.quantopian.com/posts/using-the-fetcher-with-quandl

Page 14: DIY Quant Strategies on Quantopian

Sentiment: Short sellers Intuition: Follow the (short) money. Short sellers are the ‘smart

money’, their trades are $ for $ higher conviction (to balance risk).

Reproducibility: The phenomenon is well documented.

Data: Bi-monthly (delayed) short interest can be scraped from NASDAQ. Borrow rates, real-time daily short interest data aggregated from brokers is available for $$$.

Capacity: Can be quite small depending on the instruments. Common pitfalls:

Beware the Short Squeeze! Crowded short trades can lead to a squeeze as short sellers rush to close positions .

Page 15: DIY Quant Strategies on Quantopian

Rank stocks 1 > N on Days To Cover ratio* Buy top 10%, short bottom 10% Rebalance periodically

*Days to cover =

The number of days of ‘average’ trading it would take to unwind the existing short positions.

Sentiment: Short sellers

Shares Held ShortAvg Daily Trade Share volume

Page 16: DIY Quant Strategies on Quantopian

Sentiment: Short sellers – Rank on Days to Cover

Backtest range: 3/15/12 – 3/15/13Fawce (April 2013)“Ranking and Trading on Days to Cover”https://www.quantopian.com/posts/ranking-and-trading-on-days-to-cover

Page 17: DIY Quant Strategies on Quantopian

Seasonality Intuition: Sometimes (calendar driven fund flows

e.g. month end).

Reproducibility: There’s healthy debate on this one.

Data: end of day pricing and a calendar.

Capacity: Depends on the instruments.

Common pitfalls: Overfitting / data mining is rampant in this type of analysis.

Page 18: DIY Quant Strategies on Quantopian

Simplest example is a simple 100% stock/bond annual rotation model.

Buy and hold equities (SPY) October thru April Buy and hold bonds (BSV) May thru Sept.

Seasonality

Page 19: DIY Quant Strategies on Quantopian

Seasonality: Sell in May

Backtest range: 10/1/09 – 12/31/12Jess(May 2013)“Sell in May and go away”https://www.quantopian.com/posts/time-to-sell-in-may-and-go-away

Page 20: DIY Quant Strategies on Quantopian

Which of these strategies are most popular among the ‘retail’ or individual quants using Quantopian?

Mean Reversion Momentum Valuation Sentiment Seasonality Other

Page 21: DIY Quant Strategies on Quantopian

25 Top Shared Algorithms of All Time

Combo Rank Post Title Replies Views Clones1 Google Search Terms predict market movements 64 31913 8092 OLMAR implementation 64 26039 6973 Easy Volatility Investing by Tony Cooper @ Double-Digit Numerics 57 15117 8394 Global Minimum Variance Portfolio 28 10222 7005 discuss the sample algorithm 12 18348 28826 ML - Stochastic Gradient Descent Using Hinge Loss Function 10 20400 9727 Mebane Faber Relative Strength Strategy with MA Rule 22 11104 6178 OLMAR w/ NASDAQ 100 & dollar-volume 31 7760 6979 Bollinger Bands With Trading 18 8363 560

10 Brent/WTI Spread Fetcher Example 17 10821 32711 Ernie Chan's Pairs Trade 15 10387 32812 Ranking and Trading on Days to Cover 4 24906 37913 Using the CNN Fear & Greed Index as a trading signal 18 9212 31814 Determining price direction using exponential and log-normal distributions 9 9539 60615 Time to sell in may and go away? 27 8192 26116 Simple Mean Reversion Strategy 6 11794 27017 Neural Network that tests for mean-reversion or momentum trending 4 10062 40218 Using weather as a trading signal 6 11940 19919 Momentum Trade 5 8800 45520 Trading Strategy: Mean-reversion 13 8228 21321 Global market rotation strategy 53 7621 9422 trading earnings surprises with Estimize data 34 7496 12923 Turtle Trading Strategy 11 7815 29924 SPY & SH algorithm - please review 21 7443 19425 New Feature: Fetcher! 27 7507 108

TOTALS: 576 311,029 13,355

Page 22: DIY Quant Strategies on Quantopian

25 Top Shared Algorithms of All Time

Combo Rank Post Title Replies Views Clones1 Google Search Terms predict market movements 64 31913 8092 OLMAR implementation 64 26039 6973 Easy Volatility Investing by Tony Cooper @ Double-Digit Numerics 57 15117 8394 Global Minimum Variance Portfolio 28 10222 7005 discuss the sample algorithm 12 18348 28826 ML - Stochastic Gradient Descent Using Hinge Loss Function 10 20400 9727 Mebane Faber Relative Strength Strategy with MA Rule 22 11104 6178 OLMAR w/ NASDAQ 100 & dollar-volume 31 7760 6979 Bollinger Bands With Trading 18 8363 560

10 Brent/WTI Spread Fetcher Example 17 10821 32711 Ernie Chan's Pairs Trade 15 10387 32812 Ranking and Trading on Days to Cover 4 24906 37913 Using the CNN Fear & Greed Index as a trading signal 18 9212 31814 Determining price direction using exponential and log-normal distributions 9 9539 60615 Time to sell in may and go away? 27 8192 26116 Simple Mean Reversion Strategy 6 11794 27017 Neural Network that tests for mean-reversion or momentum trending 4 10062 40218 Using weather as a trading signal 6 11940 19919 Momentum Trade 5 8800 45520 Trading Strategy: Mean-reversion 13 8228 21321 Global market rotation strategy 53 7621 9422 trading earnings surprises with Estimize data 34 7496 12923 Turtle Trading Strategy 11 7815 29924 SPY & SH algorithm - please review 21 7443 19425 New Feature: Fetcher! 27 7507 108

Page 23: DIY Quant Strategies on Quantopian

Mean Reversion37%

Sentiment28%

Momentum18%

Portfolio Risk7%

Volatility5%

Technical3%

Seasonality3%

What’s missing from this picture??

Area ~ page views

25 Top Shared Algorithms of All Time

Categorized

Page 24: DIY Quant Strategies on Quantopian

Thank You.

Questions?