Back to Community
Long only value momentum strategy with filter - first algo

Have been on Quantopian for a while. Really enjoy the community. This is my first algo which is a momentum strategy (buy winners, and sell losers). I am trying to summarise my recent research here.

Some key items in this algo:
1. Ranking based on three factors: Size: market capital > $2B; Value: low ev_to_ebitda; Momentum: Past 2 to 12 month cumulative return
2. Trend filter: only open trade with SPY_current_price > SPY_mvag(200), if SPY_current_price < SPY_mvag(200) clean positions and switch to TLT(Treasury ETF)
3. Trade: Then long top 30 stocks in the ranking
4. Rebalance: monthly (first day of each month)
5. Weigh: equal weight

Other things factor, want to investigate:
1. Ranking logic (Tricky): Size(large, mid, small), value(book_to_market, evit_ev, P/E etc), momentum(trend signal, past 3 months modified log return slope(from Stock on the move), etc), other(low beta, low volatility, etc )
2. Weight: EW, VW, ERC, MVO
3. Rebalance frequency: weekly, monthly, quarterly? (monthly seams reasonable considering commission, and momentum continuous)

Ideas are from several literature(not limited):
1. Value and Momentum Everywhere, Clliford Asness ect 2013.
http://pages.stern.nyu.edu/~lpederse/papers/ValMomEverywhere.pdf
2. Stocks on the Move: Beating the Market with Hedge Fund Momentum Strategies, Andreas F. Clenow 2015
http://www.stocksonthemove.net/book-images/#prettyPhoto

Code implementation are based on several previous Quantopians post(not limited):
1. Equity Long-Short everywhere by Simon Thornington
https://www.quantopian.com/posts/equity-long-short
2. EV/EBITDA value, then momentum by Johnny Wu
https://www.quantopian.com/posts/ev-slash-ebitda-value-then-momentum
3. Risk Budgeting to impove performance
https://www.quantopian.com/posts/risk-budgeting-to-improve-performance

Will go through some backtests, and show some thoughts. Since this is my first algo, please advice if something goes wrong.

Clone Algorithm
193
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 55e262331fa5290de3ff9125
There was a runtime error.
9 responses

Have a initial look at performance of a momentum algo. (Just ran a random one)
Portfolio return is highly correlated with the Benchmark. It suffered in 2008-2009 crisis, in the middle of 2010, and 2011. Relative high return in the bull market, but low lost in the bear market compare to benchmark.

Clone Algorithm
6
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 55e26d6e366db80ddfc2bf53
There was a runtime error.

Investigate ranking logic and it is tricky. This is how hedge fund makes money, and want to keep it secret. Found an interesting paper about Cliff Asness (AQR)'s momentum fund, and show how they construct momentum fund. It also showed their logic in another Asness's paper (Value momentum everywhere). The value indicator they used is BE/ME ratio, and momentum indicator was past 2 to 12 months accumulative return.
http://fortune.com/2011/12/19/cliff-asness-a-hedge-fund-genius-goes-retail/

However, how to choose value indicator is tricky. Other ratios can also be used to compare and rank companies such as EBITDA/EV, EBIT/EV, PE ratio, etc are often used by this community to choose the stock universe.

Below one is based on market cap, and ebit/ev ratio to initial rank the stock, other rule such as momentum, weight are the same, but the algo performance are a little bit different.

Clone Algorithm
48
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 55e2a8c5979c090ddd5462af
There was a runtime error.

In previous backtest, the momentum is past 2 to 12 months cumulative return(skip the most recent month to avoid the 1 moth reversal in stock return), and it is standard in the momentum literature. However, other momentum are exist. In the book of Stock on the move, the idea momentum is adjusted regression slope (slope of past 3 months log return linear regression * R^2). This backtest shows this idea.

Clone Algorithm
48
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 55e2af594f57bd0ddcde6f20
There was a runtime error.

Other factors like rebalance frequency, weight criteria should also be considered. Since momentum strategy tends to hold relative large amount number of stocks, due to rebalancing, the commission fee is not low. AQR estimated that their commission fee could be about 0.7% of the portfolio per year.

All the backtest results show that the momentum strategy somehow mimic the performance of index. It had nightmare during 08, 09 crisis, and middle of 10, 11. Is there a way to prevent it? If some signal comes out, we can sell all the position, and hold cash or switch to relative low risky asset like treasury. This comes trend filter like a very popular one 200 day moving average(other crossover indicator may all work). Below backtest shows that if index(SPY) current price < mavg(200), then keep cash on hand.

However, the relative higher return doesn't mean it is better, the excess return came from it limited huge drawdown in previous mentioned period. No investor wants to give you the cash for sitting there. There comes the first backtest for switching to less riskier asset (bond fund) when bear market comes.

Clone Algorithm
48
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 55e2461d03d6a20de1e1656a
There was a runtime error.

Momentum strategy has been well investigated in the academic world. In a long run, it can generally beat the market. However, due to its mimic characteristics, it may suffer huge loss during distressed time. Sometime, it may fail to capture the trend.

Even in normal period, it is still tricky. Ranking logic, type of momentum, weighting may also effect the performance.

This research does not tend to find the best performance algo, but figure out its work flow, its limit, and ways to improve. More details can be investigated in future.

Cool, thanks for sharing. You clearly looked at a variety of different concepts. It's also good to see the impact of the different parts of the strategy in the individual back-tests.

May I make a suggestion for a slight improvement? Your algo's leverage keeps creeping up slowly over time. This is a notorious issue when working with the fundamentals data. We had a recent discussion about this, including code to solve the problem: https://www.quantopian.com/posts/value-template-long-only-w-slash-trend-filter. The algo isn't as fancy as yours, but I think the "ignore_obsolete" part in the code and garyha's code for tracking metrics could be useful

@Origin, thanks for your suggestion. I also noticed the leverage issue. It really help. Another issue is that my algo rebalances every first business day of a month, however, sometimes it didn't finish the rebalance on that day, it keeping buying or selling some shares in the couple of following days. In addition, some stocks include "_A", "_B" etc, but can't be filtered even though I set some rules to do the job. Any idea? Thanks.

Filtering the stock universe down to a clean, fully tradable set is surprisingly difficult. The A/_B issue can be solved by filtering on "fundamentals.share_class_reference.is_primary_share". I then usually prevent the delayed rebalance by first filtering stocks on dollar-volume, i.e. mean daily_volume * price * somefractional_constant >= planned purchase. Also, canceling all orders at the end of the trading day avoids stragglers in a brute-force way, but potentially leaves money sitting around.

Here is the original algorithm ran on a minute level backtest, I did change the # of securities to 50 so as not to hit the time out exception.

Clone Algorithm
47
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 55e4a8a5dc04c30de95d5899
There was a runtime error.
Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.