Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
A noobs first week on quantopian

Hello friends. I've been a member of the Quantopian gang for about a week now, and the Python crew not much longer than that. I am hoping to post a new algorithm as frequently as I can in the hopes they will all get picked apart by you, who are all much smarter than I am, and that I can get some constructive criticism on what I am doing wrong so I can correct it and learn :) Since I am new not only to this platform, but to Python as well, I am expecting there to be issues with my code; so please don't hold back I am really interested in learning from you guys and getting better!

I've attached my very first attempt at a simple algorithm. Basically it's a long only strategy (I think) that aims to invest in companies with a $2B + market cap, current ratios above 2, P/B within the range of 1 and 2.5, P/E of less than 15. The goal was to be evenly weighted in however many assets made it through the pipeline, and rebalance daily. I also thought I was managing leverage, but it still seems to be above 1 in some months.

I guess my first question is, is there something wrong with my code, or is my "value" idea I tried to use just that terrible? Any recommendations on how I can improve this either code wise or pipeline wise would be very much appreciated. I'm looking to make some alterations and post version 2 next week for anyone that wants to come along on the journey!

Thanks everyone, and I apologize in advance to anyone who looks at the code.

3 responses

You had a minor logic error. I've attached the corrected code.

The basic problem is that when you were looking to sell positions not in context.longs but in your portfolio, you were iterating through the stocks in context.longs rather than the stocks in your portfolio. The logic change was line 24.

For reference though, the algorithm won't be of much interest for a capital allocation from Q because it's not long-short.

Hey EL, that's pretty good for the first week into Quantopian as for me it felt like half a life time to get my journey going!

You are well on your way :o) as Quantopian is a treasure trove of research, tools, examples and a supportive community of diverse experiences and interests!

Have fun and good coding forward!

Hi Quant Trader, thanks so much for finding that. I figured something was off with the code but didn't know what. Honestly at this point in time I'm not really looking for an allocation, just want to learn for now before trying to enter the competition; I heard it's super hard to win anyways! Also, my strategy would have lost to a basic market index fund it looks like anyways lol.

Thanks for the words of encouragement Karl :) Your first algo looks really good I am excited to look at it more and see what you really did! I look forward to learning from everyone here!