So when I give the optimize target weights a pandas series of assets, I would expect it to only order the assets with non-zero weights.
In the attached algorithm, I pass target weights 100 longs and 100 shorts and I set all of the remaining assets to zero. I noticed that the first call to order_optimal_portfolio did what I expected, however, each call after that actually increases the number of open positions instead of only staying at 200. The log.info on line 103 shows that the pandas series passed to the target weights has 100 long, 100 short and all others zero, but the number of open positions grows from 200 to over 1000 within a handful of calls.
Am I using the optimize target weights correctly or do I have a misunderstanding of how it works?
Any help is appreciated.
Thanks.