Back to Posts
Listen to Thread

This is a synthesis of two methods

Relative Strength Strategies for Investing
Asset Class Momentum - Rotational System

A Quantitative Approach to Tactical Asset Allocation
Asset Class Trend Following
Mebane Faber's MA Rule

I think it's pretty common and Mebane probably has published this somewhere.

  1. Measure the M-month trailing returns of a basket of stocks
  2. Rank the stocks and buy the top-K if monthly price > 10-month SMA.
  3. Else, hold cash

It reduces the drawdown of the relative strength approach.

Clone Algorithm
Backtest from to with initial capital ( data)
Cumulative performance:
Algorithm Benchmark
Custom data:
Total Returns
Information Ratio
Benchmark Returns
Max Drawdown
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
Information Ratio 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
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.

That's a very nifty example of the batch transform, too. I have to look more into this one! Thanks.

The idiom of placing orders to close the gap between the current portfolio and the target portfolio is a great one as well.

Oh, you guys



I need to verify the numbers tonight but I got a heatmap made of the short/long MA parameters of this system in zipline running on picloud. I don't recall the exact start/stop dates and whatnot, but it's interesting (to me) that the bulk of the profitability is around the 180-200DMA, if these results are to be believed.

This system would likely also look better when dividends are taken into account. I am not sure of the details of that in Quantopian, vs possibly using "Adjusted Close" in the the zipline yahoo data.

That's really interesting, Simon. I wonder if the peak moves or if there have been any changes throughout the years. Probably I would expect to see something after Faber published the paper in 2009.

Also, I think I posted this to the wrong system -- those results were for the simple MA crossover, nothing to do with the relative strength. In any case, yeah, interesting stuff. I will do some more tests tonight to see how a (lower resolution) heatmap changes over rolling time periods to see if there was a measurable difference after publishing.

Simon, in the heat map, how is the color scale working? blue is better returns?

In this case red is better, I am going to double-check and do some more of these tonight...

I double checked the numbers and reimplemented a couple of different ways to be sure. Never got around to the rolling analysis, probably tomorrow.

Tried briefly to reproduce quantopian's risk numbers, but I posted a separate question about that!

As you expected, returns after 2009 are much different, but that's not to say its due to publication. Working on this with zipline brought up the issue of pre-populating data for long batch transforms -- specifically, in order to compare a system using 200MA and a system with 300MA, I decided to start the former system 100 days later, so that they started trading on the same day.

Nice. It seems like optimum has shifted to 50/100 (from 20/200)

Yeah -- also note that returns in 2006-2009 period were bad as well, it's just hard to tell because the color scale is changing from subplot to subplot. New ones I do will use a common coloring, but I had to go to bed before I got that working properly!

Hi - I just tried playing around with this and discovered that a recent performance optimization has caused a problem with np.log(datapanel['prices']). We are working on a fix!

Return / volatility ("sharpe" ratio), with a common color scale across all time periods for better visualization! Have a great long weekend everyone.

I simply "cloned" and then built it and am getting an error I can't understand:

AttributeError: log
... USER ALGORITHM:16, in trailing_return
pricedf = np.log(datapanel['price'])

Hi Dan,

We just found and fixed the issue, just working on getting the fix to production. What happened is that we did a performance optimization after this algo was shared. Our change inadvertently lost some of the type information for the data sent to the batch transform during simulation. Should be sorted very soon.


independent backtest (in python)

Thanks John, for sharing this alog. It's really well implemented, some great programming features. I almost feel a bit conscious now about my own version (see Simon's post above), that I've just coughed up quickly for a friend. What I found was that this strategy gives quite stable and consistent returns with a range of different securities and it really surprised me. In terms of slow moving strategies, this one of the better ones I've come across so far. Considering how slow it is, it wouldn't even require automated execution. The perfect superannuation strategy :-)
Because of the initial spec, In my code I used weeks rather than days as look-back periods which increased the complexity of the coding enormously. Any ideas on how to simplify that?

Hi John,
Thank you for sharing this algo. I like the way you implemented it, very compact and efficient. It does make it difficult for us newbies to understand but then efficiency is more important in my mind.

Can you implement a disaster stop loss in the system? Say if a stock drops more than 15% from its purchase value, it gets sold, and won't get bought unless another stock is bought first. This way, if the whole market is tanking, and that stock is still the leader, it will prevent the system from continuously buying and selling that stock.

Thank you,

Question for you all. Seeing this perform so well in back testing, what are your hesitations when actually taking this algo live?

The market is really efficient. Do you see the plethora of Sector Rotation Systems out there now? It means that the market will digest these strategies soon, if not already, and the advantages will diminish and/or go away. So, I think the return going forward will be less than the back test. You can already see some of the Sector Rotation systems plateauing out.

A classic example is the Opening Range Breakout (ORB) System. When it was first disclosed, it was doing great. Then the market absorbed it and the opening range was slowly expanded from 1/2 hour to an hour to sometimes till lunch time, depending on what system you were looking at. Once people get tired of the system and abandon them, they slowly regain their effectiveness again.

That is the reason why I want a stop loss built into this system so that if it collapses, we don't lose everything.

I hope we have some good discussion on your question.

Hi John:
I have just read the original paper - for a long time, I have been a Dollar Cost Average investor - basically been buying the same stock over 10 years and I have always stayed way above the SMA - have you come across any comparison between DCA and Relative Strength Strategy? I am very curious to know this before changing my strategy.

Log in to reply to this thread.
Not a member? Sign up!