Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How many shares do I currently own?

This seems like a pretty basic question but I'm new to this and cannot for the life of me figure out how many shares of a specific stock are currently in my portfolio.

My first algorithm (which traded just aapl) would only create a sell order if context.portfolio.positions_value > 0 evaluated to true. Now I'm working with a pool of twenty stocks and just because context.portfolio.positions_value > 0 is true doesn't mean I actually hold every stock that meets my criteria for selling. I'd like to only issue sell orders for stocks that are currently in my portfolio.

If one of you glorious geniuses could point me in the right direction I would be very grateful.

2 responses

Daniel,
Try context.portfolio.positions[put the stock here].amount
This will give you the number of shares for whatever stock you have between the brackets.

Thank you so very much, Mr. Hobbes. This is exactly what I needed and your name is pretty awesome, too.

Thanks again.