Back to Community
Finding the largest stocks at a given time in history?

I am brand-new here. I'm hoping there is a way to figure out what the x largest stocks were at a given time, for example:
What were the 10 largest stocks by january first 2010?
The term 'largest' can be either based on fundamentals or based on value both is fine.

I hope someone can help me to figure out how to write a function that does the job above.

3 responses

Hello Benjamin -

Very doable. It is built into the Pipeline API, with something called .top(). For example, see:

https://www.quantopian.com/posts/contest-32-entries

I don't have time now to write a simple example, but if you dig around in the help docs/tutorials, you should be able to find some example of how to use the .top() thingy (by the way, there is no .bottom() as far as I know, but one can exclude the top N, giving the remaining bottom).

You may also want to look at the built in factors MarketCap or AverageDollarVolume depending upon if you want the largest capitalized companies or the largest average traded dollar volume respectively. Use them in conjuction with .top or .bottom as Grant mentioned to make a filter. (BTW there is a '.bottom' thingy) See the documentation under built in factors https://www.quantopian.com/help#built-in-factors .

@ Dan - Thanks for pointing out .bottom(). At one point, we only had .top() but now we have both. Seems we should also have a .middle() huh? : )

@ Benjamin - I'd also recommend, if you are looking to write algos for the Q fund, using the Q1500US base universe. It is "trade-able" and also filters out a lot of junk that is not appropriate for their fund. You might also ask "How about the S&P 500 or other common indices?" They are not available as part of the Q API.