Max quantity calculation

Hey man can you send me the formula you have. Im also trying to do it in Python