Hi fellow quants! 🚀

Does anyone know how I can make sure that when my options expire ITM, I'm not automatically assigned the shares of the underlying, but instead I just close the trade? I'm getting a lot of margin calls in my backtests and I want to avoid them. 

PS: just liquidating the options 5 minutes before the closing bell during their last day of trading is not a valid answer LOL

Thanks in advance, 

Giulio