I'm getting some new 'KeyError' lately... I was working on a custom asset allocation algo, so I thought it was probably my code, but this morning I got a 6-months+ running algo disqualified by the same error. It seems to happen when I order a 0% target on a stock that is no longer in the current universe.
I often use this code on top of my strategies for safety. It used to work fine until now...
for stock in context.portfolio.positions:
if stock not in data:
order_target_percent(stock, 0)
Anyone else with the same problem? Or am I doing this wrong?
Thanks!