Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
len(Context.portfolio.position) keeps increasing indefinitely

Hello

In the attached algo, its context.portfolio.position keeps accumulating positions of stocks it once had a position in, but have 0 positions now.

Can anyone have a look if the attached code incorrectly causing len(context.portfolio.position) to increase indefinitely and causing the backtest to run out of memory

The backtest log records number of positions at market close, and prints len(context.portfolio.position) daily.

1 response

Sounds like the bug reported by Jamie ( https://www.quantopian.com/posts/retrieving-data-history-on-current-positions ):

...there's a bug with context.portfolio.positions. It's supposed to get rid of all zero-amount entries in the dict at the end of each day. This is something that we were recently made aware of and our engineers are looking into it.