Logo

Portfolio Rebalancer

  1. App
  2. About

A free and private whole-share portfolio rebalancing calculator for the rest of us

Portfolio Rebalancer is a free and private whole-share portfolio rebalancing calculator, or asset allocation optimizer, that uses a mathematical optimization algorithm to tell you how to invest, withdraw, or rebalance your portfolio, given your available cash.

That is, it can identify how you can invest your next, say, $1000, over your currently held assets, stocks or ETFs, or how to withdraw, say, 4% of your portfolio’s value, in a way that ensures your eventual portfolio stays closest to your target percent allocations.

Story of Portfolio Rebalancer

I whipped up this app because, even for casual investing, spreadsheet formulae aren’t always robust enough to rebalance whole number shares. This app uses mathematical optimization to converge on the optimal solution. The technique is simple, but it requires an algorithm—more than what a spreadsheet can handle.

Also, unlike a spreadsheet, you can use this app anywhere, and on mobile—you can save the app for convenience too (use your browser’s web app download or web app saving feature from the browser’s menu). Using the app on mobile is a life saver—you’ll understand if you have a beloved toddler that commandeers your laptop whenever you open it.

App Usage Instructions

Input your target allocations for each stock, current holdings, available cash, and intention to Buy-only, Sell-only or rebalance (‘Any’), and the app will calculate the buy, sell or hold actions you should take in order to get a final portfolio that’s as close as possible to your target allocations.

It’s especially handy for those of us who buy whole shares, because when dealing with whole shares, we can’t always make values exactly match our ideal targets. So, the algorithm converges on the closest solution.

The rebalancing algorithm does this by using linear programming (a mathematical optimization technique). That is, the algorithm formulates a linear constraint optimization problem and solves it. It will attempt to find a solution that’s as close as possible to your target percentages while investing as much of your available cash as possible, while also adhering to various other constraints you might set, such as Buy-only or Sell-only mode (i.e. to invest only or to withdraw only).

It’s also possible to ask the app to rebalance your portfolio by both selling and buying from your existing holdings, with no extra cash available to invest. You can set this mode by choosing ‘Any’ for the Buy/Sell Mode in Rebalance Options, and setting 0 for Cash Available. If you do this, it’s possible for the app to calculate a solution with two phases—a selling phase, then a buying phase. That’s because, by design, we assume that we can’t instantaneously receive cash from sold shares, then buy with that cash in the same phase. In real life, there’s often a settlement period. Therefore, the algorithm only considers available cash on hand to be usable for buying shares in a single phase, not cash received from sold shares during that same phase.

Privacy and Disclaimer

Privacy: The app runs entirely in your browser—no portfolio data is collected. There’s a feature to save and load your portfolio data (because it’s annoying to have to enter it all over again)—it saves this data locally in your browser storage.

Disclaimer: This app is not financial advice. This app is an indi tool that was made to be a little better than spreadsheet formulae, especially because of whole number shares. Professional rebalancing tools probably use more sophisticated techniques like QP programming, but this is good enough for me—feel free to try it out and decide for yourself. Always check if the results make sense to you, because not all scenarios have been tested.

Constraints and Bugs

By the way, on the rare occasion, it might be possible to confuse the algorithm—for example, by making impossible constraints. That’s why the rebalance results will say if the algorithm successfully determined a solution, or if it got confused.

If it gets confused, it may have something to do with the nuances of mathematical convergence. Sometimes, a small change can ‘unclog’ the algorithm—try these: increase your available cash a little; and/or adjust target percents a little; and/or set Buy-only or Sell-only mode to simplify the puzzle for the algorithm. Then try to Calculate again.

If it still gets confused, perhaps it’s in fact far from possible to achieve your target allocations, given your available cash and market prices. Or, perhaps you found a bug.

Feel free to contact me at andy@portfolio-rebalancer.app to say hi or anything else!

Logo
A free and private whole-share portfolio rebalancing calculator for the rest of us.
© 2025 Andy Teng.