Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Your algorithm v/s buy and hold strategy

Sometimes we get good results on an algorithm because of unknowingly choosing a stock that outperforms S&P during the backtesting period. Thus the algo misleadingly will show good results compared to the benchmark (S&P 500).

To actually measure the algo's performance,I usually plot my algo's performance against returns of a buy-and-hold strategy. If the algo doesn't outperform a buy and hold strategy, then I consider its performance is sub-par

As you can see in the below example, the algo outperforms S&P. But in the custom graph, you can clearly see that it doesn't match up to a buy-and-hold strategy

Here is the code for the same. It can be extended for all the stocks that we trade in. This also shows areas of improvement for the algo. For example, the example algo doesn't buy when the stocks are skyrocketing (Jan-Apr 2012) and thus shows that is is not able to take advantage of bull runs.

Note that the buy-and-hold returns could be made more accurate by buying additional stocks on dividend payments. I leave that as an exercise for the reader ;)

(feel free to correct anything)

7 responses

Great point Ajay! This is often gets glazed over with new algorithms. In the future we hope to allow custom benchmarks on Quantopian. Then you'll be able to set any benchmark for your algorithm, including a buy-and-hold strategy.

This will help to see if you're truly found the golden egg or chose a lucky stock.

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.

I guess benchmarking with buy and hold strategy can be as much misleading as any other index. For example, utilizing buy and hold for apple shares before 2013 would have given far higher returns than the same strategy for Microsoft shares. So it brings us to full circle where algorithm performance against a benchmark depends on the stock and testing period one selects. I guess backtesting using more volatile shares give us better picture of how our algo. may perform in a live market.

I believe a buy and hold benchmark is a good test case, but it really depends on what the overall goal of the strategy is. It also only makes sense to use the same portfolio that the algo is managing. It obviously makes no sense to trade DuPont and MMM and use Apple as a buy and hold benchmark.

It comes down to the goals. If maximum return is the goal, it should beat a buy and hold, however, if you aim to reduce volatility, then it might not be. I personally do repeat tests in a buy and hold algo with the same securities just as another comparison. I think the more angles you look at something from the better.

This is a good benchmark, but as Syed points out, when you buy the stock to hold will change your results. For a better evaluation, the algorithm should be compared against the benchmark over starting from random dates for a particular equity. If your trading strategy consistently yields better results, then you've got something.

Sorry, Could someome could kindly help to modify the BuyAndHold grpah calculate code that when the strategy have multiple assets?

Another option is to have a dedicated buy and hold algorithm, then run it with the same portfolio/dates as another algorithm. You cant see the graphs in the same test but can compare them in 2 browser windows. Its easier to do and you can see all the risk metrics of the buy and hold separately.

This one evenly weights itself and waits until it has the cash to buy one of each stock before reinvesting.

Thanks your kindly suggestion!