Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Tips for enhanced algorithm performance

This is the first algorithm I've made. I have a lot to learn and would appreciate someone's help.

My strategy is to long the worst performing stocks of the last five days, that also have a high combined factor. The combined factor is composed of factors measuring fundamentals data. I will also short the best performing stocks with the worst combined factors. I've included my code.

I thought this seemed like a sensible enough basic strategy, but it performs badly (nearly minus %30).

If anyone could explain where I'm going wrong, whether it is my idea or its implementation, please explain.

Thank you.

4 responses

Could you attach a backtest of your algo? It's much easier to help troubleshoot.

Have done, thanks.

No specific ideas for improving the results, but here are some thoughts.

I've personally not had good success with the stocktwits data set. There may be some alpha in the data but I haven't found it. Just using the 'bull_minus_bear' field hasn't yielded much in my experience. There may be some classes of stocks which this signal is more predictive. Perhaps large stocks or (for that matter) small stocks. I've also thought of using the price trend in conjunction with the stocktwit trend (eg both going up or both going down) as perhaps a better indicator. You may want to try some combinations of these. I ran your algo without the stocktwit factor (just backtested over a couple of years) and it seemed to do better than with it.

Another, idea is your use of 5 day returns. Your algo seems to bet on stocks reverting to some sort of 'mean'. Long stocks that have gone down and short stocks which have gone up. The problem with this simple approach is twofold. First, there is a whole other school of thought which says 'don't fight the trend'. Second, maybe use some other indicator to tell how a stock is moving. What I mean, perhaps the stock was already at a high and the reason it took a big dip (or jump) was that it was already reverting to a mean. A big jump in itself doesn't really say anything about if it's moving toward or away from a 'mean'. One simple thing to try is to choose stocks in the the top or bottom say 2% rather than 10%. These would be the very big movers and are usually over-reactions.

Finally, maybe consider grouping the ebit and roe values by sector before doing the zscore. Different sectors have very different expectations and averages of earnings and return on investment. I've always found it best to compare these within like companies.

I did try setting the commissions and slippage to zero and the results were about the same so high turnover (ie high commissions) doesn't seem to be an issue.

Good luck!

Hi Dan,

In regards to grouping by sectors with zscore, which of the below(or neither haha) would be the correct logic? What other options would you suggest to rank fundamentals by sectors? Thanks!

earnings = Fundamentals.earning_yield.latest.zscore(mask=base_universe)  
earnings_win = earnings.winsorize(min_percentile=0.05, max_percentile=0.95)  
earnings_yield = earnings_win.rank(ascending = False, mask=base_universe, groupby=sector).demean()
  • OR

    earnings = Fundamentals.earning_yield.latest(mask=base_universe)
    earning_zscore = earnings.zscore( mask=base_universe, groupby=sector)
    earnings_win = earnings_zscore.winsorize(min_percentile=0.05, max_percentile=0.95)
    earnings_yield = earnings_win.rank(ascending = False, mask=base_universe, groupby=sector).demean()