Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Stock Splits throwing off algorithm

Some of my recent algorithms have been losing massively on 10/5/2015-10/6/2015 even though I'm diversified and leverage <= 1.

I've traced it back to my algorithms buying MSGN (which appears to be around a stock split) on 10/5/2015 at a price of ~$170 per share even though all days before and after that time are ~$20 per share. To make matters worse, even though I order every day using below logic, my portfolio somehow gets 35% concentration in MSGN.

I'm fairly new to this. Can somebody please guide me as to how to prevent this from happening? Is there a way to ignore opening positions in stocks that are about to have a stock split (using the free data)? How can I change my below code so that at least it only orders the target percent instead of going nuts and ordering 35% of portfolio in MSGN? Thanks!

target_percent = min(0.05,0.99/len(context.stocks_to_long))
for stock in context.stocks_to_long:
order_target_percent(stock,target_percent)