Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Momentum Algorithm, too many positions developing.

Hi,

I'm very new to quantopian and algorithm programming. To get started I wanted to create a simple Long/Short Momentum Algorithm.

Basically, it should do the following:
1) Rebelance every month.
2) Take the returns from the past month of each security in the trading universe.
3) Close postions that neighter warrant a long nor short postion anymore.
4) Go long the 100 best performers.
5) Go short the 100 worst performers.
6) All open positions should be equally weighted (1/200)

The issue I am having with my algorithm is that at the beginning it starts with 199 open positions as it should, however, position size of the Portfolio keeps increasing with time, e.g. rises from 200 at the beginning towards 255 after two years. Hence, there is something wrong with the algorithm, I assume that postions are not closed properly.

//There is some code from a previous test in the algorithm, just ignore the SMA stuff and the stop_loss_handler . That was something different.

Maybe someone with more expertise could have a look at my code? I think it's just a small mistake.

Thank you & Best regards,
Mario