Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
My first Algo on Quantopian - Handpicking stocks from various sectors and combining with 24 day portfolio rebalance

Hi there folks,

This is my very first algo on Quantopian, and it's about as basic as it gets, but I am still seeing some pretty good historic returns from it. I used a similar approach when I was hand-picking and trading stocks in the UK, and it works well with the algo.

The philosophy I have followed with the algo is to handpick stocks in sectors that I like - Specifically Tech/Internet, Clean Energy, Entertainment and a little bit of manufacturing. (I tend to be an ethical investor). I then research the businesses for historic performance, look at their financials, P/E, margins, risks and the like, and also whether I understand their business.

I then weighted each security on how much I wanted in each one, contributing between 1 and 9% of my overall investment into each stock.

Typical stocks include: Tech - Google, Facebook, Microsoft, Apple
Retailers: Amazon, Ebay
Manufacturing: GE, Tesla, Toyota
Entertainment: Disney, Viacom, TimeWarner, LiveNation

So it's a reasonable risk-mix, some better established and some more recent upstarts.

The philosophy is simply to buy long and hold, rebalancing the portfolio every 24 days so no stock starts overwhelming and gathering too much risk.

This will form the first part of my overall trading algorithms, although as I dig deeper into Python, I am sure that I will find better ways to track buy and sell signals.

Any comments are gratefully received.

Paul.

9 responses

Hi Paul,

Impressive result for your first algo!

How do you avoid look-ahead bias during the hand-picking of stocks?

Aidan,
I'm applying the same philosophy to stock picking as I would it I were just holding them in a standard portfolio; so a combination of financials, understanding what the business does, going mainly with solidly established businesses and the like. Since my intent with this part of the strategy is to buy and hold over the medium to long term, I'm not so concerned with stock performance on a day-to-day, week-to-week or even month-to-month basis. In other words, I am not sure if I have avoided look-ahead bias, I'm just investing in stocks where I trust the business, where they have had historic good performance and where I believe that they will continue to grow over the medium to long term.

The intent is for this to be part of my overall strategy, although there are definitely tweaks that could be made to improve the algo!

Hi Paul,
to compare apples to apples I ran the backtest as buy and hold, it seems the alpha is coming from stock selection

The issue I see with the backtest is that the stocks are hand-picked based on information we have today. We know these companies performed well since 2013 so you are picking stocks based on information you would not have at the start of the backtest, which is essentially looking into the future. I guess you could avoid this issue by using the fundamental data from before 2013 to pick the stocks.

Is there an inherent issue with using algo trading but hand-picking stocks? I ask because I am (very) new to algo trading, but have a little bit of experience with manual, hand-picked investing, almost exclusively as 'buy and hold'.

Is the overall philosophy of algo trading to be stock-agnostic and to simply use a combination of various signals and mathematical decisions to drive automatic trade decisions? If that is the case, is there a point where the hand-picking of stocks based on performance, fundamentals and finance comes into that, or should I aim more at identifying signals and strategies and not look at the more traditional indications on whether specific stocks are good investments?

In other words, should the algo do all the heavy lifting, or do I allow my own opinion on what stocks would be good investments to play into that?

There is no issue with hand-picking stocks, seemed to work ok for Warren Buffett! The issue is that you introduce bias in the backtest by using information that would not have been known or available during the period being analysed. This can lead to a lot of overconfidence in future performance.

An alternative approach might be to look at the fundamental data from before the backtest period and pick stocks based on simple rules (P/E < x, EPS > x etc.) for your portfolio.

Aidan, that's a very fair point. I have attached a backtest for the three years previous (Jan 2010-Dec 2012), and it doesn't get quite the same bang for the buck, although it does still outperform the benchmark. The alternative approach that you suggest is worth looking into as well. One of the reasons that I prefer to hand-pick stocks is that I prefer ethical/socially responsible investing; I wonder if there is a way to lift data on socially responsible businesses and incorporate that into an algorithm - That could be worth another post...

Thanks for sharing Paul!

If anyone else wants to test rebalancing strategies with custom-stock portfolios, take a look at our new tool AlgoBuilder: https://www.quantopian.com/algobuilder

It allows you to choose a pre-selected basket of stocks or create your own portfolio from over 8,000 stocks and ETFs in our database. Assign customizable weights and see how the algo performed over the last 2 years. Backtest the strategy without writing a line of code!

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.

What you could do which would be interesting to see. You said you have been a buy hold investor for quite some time. I don't know if Quantopian software will let you do this but you could look at your trade history in your personal account as far as when you made certain buy decisions at what time etc. and implement those stocks that you made buy decisions for in the backtests during the time period in which you bought the equity in your real account. Then no bias because you can justify putting the equity in there because either way thats the equity you decided to buy at the time.