This is a python reimplementation of the "Optimal lazy portfolio rebalancing calculator" on http://optimalrebalancing.tk/index.html.
From the original website:
When contributing, use this calculator to help you purchase under-weighted assets optimally using only the contributed amount so that you get as close as possible to your target allocation without selling anything. Similarly, if you are withdrawing from your portfolio, use this calculator to help you sell over-weighted assets optimally to yield the desired withdrawal while getting as close as possible to your target allocation without purchasing anything.
The source code for that calculator is licensed under the GPL but it is only provided in minified-JavaScript form, which was pretty hard for me to understand.
Rewriting it in python was how I understood what it is actually doing.