Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Rules based sector rotation strategy based on Mebane Faber research

I came across this nice post on Mebane Faber's research page outlining a simple rules-based sector momentum model for long term investing.

The model makes binary (yes/no) decisions on whether to invest, or not, in each of the nine major US stock market sectors based on whether they are trading above or below their 10 month trailing average price. The portfolio is equal weighted across all sectors that are trading above their trailing moving average, and the sector exposures are capped at a maximum level of 25% exposure to any one sector.

This algo is designed to work in minute mode and to be compatible with paper trading and live trading, as implemented rebalance is triggered once per week. It's also a nice example for both the history API and one of the new order methods, the order_target_percent() method, which is an awesome time saver method if you find yourself rewriting or reusing your code for basic portfolio management. Also take a look at Dan's post on these new methods for some more context.

There are lots of easy knobs to turn with this one, from the selection of the sector ETFs to the rebalance frequency, the momentum horizon and even the rules themselves, so clone it and see if you can find a better version than this one!

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.

7 responses

This is great ! One of the first things I wanted to backtest was a strategy like this.
I'd not thought of basing it purely on the market sectors like this.

But I see that in the code that it makes the buy/sell decision purely based on the price being above or below the moving average. Is it really supposed to be this simple ?

I notice that it says

"The decisions are generated through a sophisticated analytical engine
that evaluates “true” sector trends while adjusting for market noise
and for changing levels of volatility in the market. The key model
inputs (driving the decision-making process of the algorithm) are data
on total return movements, volatility, and rate of change in
volatility for the subject equity sector."

Have you any idea what formula they might be using ? It sounds very vague and "hand wavey"

I'd expect some kind of channel with width based on recent candle widths would be a step in the right direction
http://www.dowce.com/~ZoZ
http://www.dowce.com/~ZoF

And I wonder if its beneficial to only go long when volatility is 'low'.

-Jason

Hi Jason,

The algo that I wrote is an implementation of the rules based system that Meb Faber outlines as:

"My guess was that a simple system, similar to many we have published in our white papers, would capture what F2 is trying to do. Below we examine 9 sectors, equal weighted if above 10sma. If less than 4 sectors then 25% in cash if 3, 50% cash if 2, 75% cash if 1."

I'm sure that the original F-squared logic is indeed more complex, though whether it generates better risk adjusted returns after fees is probably the more interesting question :)

I haven't done much work tweaking this strategy, but I'd love to see any improvements or modifications that you find to be interesting if you'd like to share them on this thread!

Best wishes, Jess

Aha please excuse my mistake, it was late when I read your post and I never got that far down before I looked at the code.. It seems like a reasonable first step. It would be interesting to zoom in on the entry and exit points on the 1920-2013 chart to see if (how badly) it gets chopped up at the crossing points. The chart they show just has cumulative returns. Not trade markers. It would be interesting to run this on sector data from the Japanese market. (a long term bear market) US data 1920 - 2013 is just a giant bull market. I'd prefer to know that any strategy was proven in less bullish conditions.
I spent a few hours tonight loking for Japanese data but I couldnt find anything except daily data. 25 years is about $2000 from the tokyo stock exchange (http://www.tse.or.jp/english/market/mkinfo/b7gje60000003u3q-att/english.pdf)

The quantopian data is only 5 years IIRC.. So we just bought some longer term historical data (15 years of 1 min data) from quantquote.com (just the Nasdaq100 initially) so we'll be trying to get this kind of strategy tested with stocks as well. I have some ideas for entering and exiting swing trade positions that I'd like to test as well. I may pay for their ETFs data if we make good progress with the stock data.. Our analysis will probably be in R (until I get through learning the wonderful world of Python - I was a C++/C# etc. developer for 13 years, my wife is a statistician)

Kind Regards,

Jason

Hi Jason,

Just to clarify on the data history, we actually have pricing back almost 12 years (start date is Jan 2002 - see the FAQ: https://www.quantopian.com/faq), I limited the time range of this backtest based on the availability of these particular instruments rather than the pricing data history.

If you have ideas you'd like coded up in Python that you are willing to share this community has a lot of technical expertise and could probably be helpful with the language conversion.

Best, Jess

Dear sir,

This is my first post in this community, I had clone this algorithm and do the backtest,
But I cannot got the same performance compare to Jess backtest,
Could someone kindly let me know what is wrong for me !

Kind Regards,
Ding

Hello Ding,

You are getting the same result as Jess i.e. the algo return is 26.5% and you have the same Sharpe/Sortino ratios and the same max. drawdown. The difference is that the benchmark is now performing better - see https://www.quantopian.com/posts/backtester-change-updated-benchmark

This means that every backtest run on Quantopian from Aug. 2012 to Jan. 2014 looked significantly better than it actually was since the benchmark return was too low. For 10 year backtests the benchmark is now 30%+ better performing.

P.

Hello Peter,

Thanks your kindly reply, now I see the benchmark have been changed.
How do you think the algorithm that why cannot got better performance than benchmark from 2012 bull market?

Regards, Ding