I’m using coarse/fine universe to screen for stocks, which get added to a watchlist (“self.invested_stocks”). When the universe changes, symbols are added/removed from this watchlist based on certain criteria. Then I’m iterating through the symbols in the watchlist and equally purchasing the stocks. Each time new stocks are added or removed from the portfolio, I’m also attempting to rebalance the portfolio to an equal weighting of all holdings. I’m doing this with “self.SetHoldings([PortfolioTarget… “ and have also tried “self.SetHoldings(security.Symbol…”

For some reason, both are failing to equal-weight the positions in the portfolio. In the log I’m printing the value of holdings for each stock, anytime there are changes to the portfolio, and values are showing to be quite different. I can’t figure out how to correct this.

Additionally the portfolio continues to hold more cash, above the 10% cash threshold I set. By the end of the backtest it's only 76% invested.

A second issue I’m having is that the stock PDLI keeps getting added to the portfolio, but there appears to be an error in the QC data or algorithm. Although there is a stock price for PDLI, QC incorrectly shows a price of $0. I’ve submitted a support ticket in the data issues section of the QC site, but haven’t heard back yet. In the meantime, how can I manually remove this stock from my watchlist? I’ve tried adding a condition “and security.Symbol.Value is not str("PDLI R735QTJ8XC9X”)” as a requirement before stocks are appended to my watchlist, but this doesn’t seem to work. Perhaps there's a more elegant way to do this.

Any help with these two issues would be hugely appreciated! Thanks in advance.

Author