Hello, I have a code that backtests for a portfolio of stocks. Some of the stocks that my code buys later get delisted before the sell signal, which leads to a problem where the delisted stock is kept in the portfolio until the end of the backtest. The question is if it is possible to write a code that sells a stock if it gets delisted (i.e. there is no more data) at buy price?
I would greatly appreciate your help with this matter.