To follow along, download my calculator here. Make a copy of this Google spreadsheet file, and play with the copy. (You need to be on Google Chrome to get in.)

I’ve put Harry down for a 24% federal tax bracket, which applies to joint returns with roughly $200,000 to $350,000 of adjusted gross income. His state tax rate is 6%. He qualifies for the 15% rate on dividends and long gains. If his adjusted gross is below $250,000 he won’t owe the 3.8% surcharge on investment income.

To pay for the boat, he needs to either sell off $104,000 of the stock or take $143,000 out of the IRA. He chooses one of those moves.

Time passes. At some point later—12 years later, using the default values in the calculator spreadsheet—there’s a second cash-out.

If it was stock that Harry cashed out at the beginning, he or his heir is left with an IRA that has grown to $257,000 in year 12 and is good for $180,000 of spending money after tax.

If, however, Harry had chosen to use IRA money on the boat and hang onto the stock, the stock would have grown in value. But, absent some way to duck the capital gain tax, it would have yielded only $164,000 on liquidation. Taxes hit dividends along the way and, at the end, they hit the appreciation on the original shares from their $80 cost and the appreciation on shares acquired with reinvested dividends.

In this case the choice of preserving the IRA instead of the stock is a clear winner, to the tune of $16,000.

Harry might, however, escape the capital gain at the end. Perhaps he uses the stock for charitable giving, or he’s still holding onto it when he dies. In that case, the strategy of preserving the stock would leave Harry ahead, but only by a small amount.

The calculator allows for a roll of the dice. Putting in a 50% probability that the capital gain will be ducked, Harry finds that preserving the IRA is the better move.

Insert your own assumptions in your copy of the spreadsheet. You can change tax rates, the waiting time until there’s a second cash-out and other variables. You’ll probably find the arithmetic steering you to the strategy of selling taxable stock to pay for today’s living expenses.

There are circumstances, though, in which it would make sense to hold onto the stock. That can happen if both of these things are true: the stock in question has a low cost basis, and you have a fairly high degree of confidence that you or your heirs will be ducking the capital gain tax.

When using this calculator to plot your moves, follow these steps:

—Apply the decision-making to your highest-cost stock positions first.

—Don’t waste any time pondering whether to sell bonds in a taxable account. They should always be sacrificed before damaging an IRA. If this leaves you with too high an allocation to equities, correct that problem inside the IRA.

—Don’t withdraw from the IRA just because you expect your tax rate to go up in later years. If you are in this situation, do a Roth conversion, paying tax now to make a portion of your IRA permanently tax-free. Sell enough of your taxable assets to pay for both the boat and the conversion tax.

—Keep an eye on the proposal from Democrats to deny wealthy families a capital gain bypass on bequests and gifts. (There is at present no threat to take away the exemption on appreciated property given to charity.) You might need to scale back your odds of benefiting from the bypass.

Play what-if with the calculator by altering the numbers in the yellow cells. You’ll find that the biggest swings in outcomes come from the cost basis of the appreciated shares you may be selling. The length of the holding period and the assumed return on the stock market are less important.

The federal tax rate on ordinary income, which includes IRA distributions, determines how big a withdrawal you would need for your boat. But it has no impact on the wisdom of preserving the IRA. If this perplexes you, I again recommend Guide To Income For Early Retirees. That essay explains how an IRA is best understood not as a tax-deferred asset, but as a shrunken asset that is completely tax-exempt.

For simplicity, my calculator assumes that your spouse or other heir will be in the same tax bracket as you are. It doesn’t allow for a change in your bracket over time, but if such a change is in the cards, follow these rules:

—If your bracket is likely to go down, don’t invade the IRA.

—If your bracket is likely to go up, do a partial Roth conversion right now.Follow me on Twitter.