Selling / rebalancing algorithm (the opposite of dollar-cost averaging)

music-and-ski

Recycles dryer sheets
Joined
May 28, 2020
Messages
78
Location
Calgary
I've always liked dollar-cost averaging during the accumulation phase of life, to automatically and mindlessly buy more units of when prices are down, and less units when prices are up. You know, the "buy low" part.

But I have yet to come across or devise a simple algorithm for selling equities to support a lifestyle in retirement. Obviously the worst answer would be to sell the same dollar-value each month, since then you'd be selling more units when prices are low, the opposite of "sell high".

Anyone know of any selling algorithms?

I'm thinking something along the lines of setting a limit order to sell at a price x% higher than the maximum price over the past year, and then burn through your cash while you wait for your limit order to come through. If the limit order doesn't come through and you start running out of cash, you'd might have to progressively lower your threshold to avoid selling in desperation, and maybe you'd also change the size of your order (I could see an argument to increasing the size of your sell order so that when it does come through you're replenishing your cash basket more, but I could see an argument to reducing the size of your order since you're selling at a cheaper price.)

When the stocks eventually rise to the point where you hit the limit and replenish your cash position, you'd then put in another stop limit order at a higher price, for the next replenishment.

Anyone know any strategy like this? I guess it's really a rebalancing timing strategy, to shift equity positions into cash (or fixed income products), to support regular withdrawals from the cash position.

I guess I could write an algorithm and try to optimize it over historic data by adjusting the few parameters. I do optimizing like this in my day job. I'd just need historic high/low/close data over 25ish years. Where can I download such data for free?
 
Obviously the worst answer would be to sell the same dollar-value each month, since then you'd be selling more units when prices are low, the opposite of "sell high".
Instead of withdrawing the same dollar value each month, how about withdrawing the same percentage each month? So, when the price is low you'll withdraw less and when the price is high you'll withdraw more.

The "algorithm" you're attempting define is little more than market timing. We know it rarely works for buying, so it's going to be little different when selling.

I guess I could write an algorithm and try to optimize it over historic data by adjusting the few parameters. I do optimizing like this in my day job. I'd just need historic high/low/close data over 25ish years.
Folks with technical backgrounds want to believe that they can excel at investing by analyzing data, that past data is a predictor for future results...or how markets will move. It's not true. It's a waste of time and the simple no-effort approach will likely provide better results. You're certainly free to experiment and prove it for yourself.

Yahoo Finance provides the data you want on the historical prices tab for any security you want. There is a download link on the top right of the table.

For example:
https://finance.yahoo.com/quote/XOM/history?p=XOM

https://query1.finance.yahoo.com/v7...l=1d&events=history&includeAdjustedClose=true
 
Last edited:
If you have a MF or ETF sell same number of shares each month. Some months you can live the hi life, others you’ll need to tighten your belt.
 
A regular withdrawal ($) effectively is reverse DCA... you'll sell fewer shares to get x dollars when prices are high. My "algorithm" is simple, end of year, sell enough to replenish cash to cover the next years anticipated expenses while minimizing taxes (which makes it a bit less simple - primarily managing MAGI for ACA). If taxes were non-existent, I would likely keep a smaller cash cushion and withdraw monthly to keep more fully invested but that would lock in too much income early in the year and make managing MAGI much more difficult.


Not my Plan A but a contingency plan that would technically be timing the market is that if there was a major market decline at the end of the year just as I'm preparing to sell, I might draw from my HELOC to keep fully invested until (hoping) the market recovered. I would still sell to realize income for MAGI and stepping up the basis but still remaining in the market beyond my planned "sell" point at the end of the year. Of course, this would be adding a little bit of leverage and interest expenses to my portfolio.
 
I sell tactically, not by a schedule. I raised quite a bit last year. Fortunately now you can get a decent return from cash.
 
Selling algorithm: rebalancing takes care of that. It automatically sells from the winners (or least losers). I do the withdrawal and rebalancing one a year in early Jan. The withdrawal typically goes to a high yield savings account which then feeds my checking monthly.

My withdrawal calculation is based on each Dec 31 portfolio value so I do take a pay cut after market down years as we draw the same x% each year. The pay cut has not been a problem for us as we often experience strong market up years ahead of it so income rises on average.
 
Last edited:
The "algorithm" you're attempting define is little more than market timing. We know it rarely works for buying, so it's going to be little different when selling.

Folks with technical backgrounds want to believe that they can excel at investing by analyzing data, that past data is a predictor for future results...or how markets will move. It's not true. It's a waste of time and the simple no-effort approach will likely provide better results. You're certainly free to experiment and prove it for yourself.

Yahoo Finance provides the data you want on the historical prices tab for any security you want. There is a download link on the top right of the table.

For example:
https://finance.yahoo.com/quote/XOM/history?p=XOM

https://query1.finance.yahoo.com/v7...l=1d&events=history&includeAdjustedClose=true

Thanks for the thoughts and the link to data. I don’t want to design a fancy algorithm, I wish there was something as brainless as dollar cost averaging is for buying. I just think there must be something simple that’s a little better than selling on December 31st each year. I’ll work on something as simple as possible.
 
I usually withdraw once a quarter rebalancing on the way out. The last few years I take out more or less than a quarters worth based on how I feel things are going.
 
... Folks with technical backgrounds want to believe that they can excel at investing by analyzing data, that past data is a predictor for future results...or how markets will move. It's not true. ...
Yes! How true. My first foray into investing, literally 50 years ago, was an effort to use Fourier transforms to analyze stock price series. :banghead: It didn't work, of course.

@music-and-ski, what I slowly learned is what sixty years of academic research has shown: The equity market is best viewed as a random process with a slight upward bias. So while it is certainly possible to develop an algorithm that fits historical data, it will not be predictive. You can't predict random.

Assuming you have a simple portfolio of broad index funds as the research recommends, the withdrawal decision just becomes a decision to sell from the equity side, the fixed income side, or a little from both. Your AA and recent market effects on it will guide you in most cases.

As far as when to sell, that's mostly a matter of psychology. Selling in January maybe indicates some pessimism about the year's market. Selling only as needed leaves money in the market longer and is maybe a sign of optimism (or of faith in the market's long-term upward bias). Like all decisions to trade, this too is a market timing decision. No reason to be ashamed.

One salvation is that you are withdrawing a relatively small amount of money; just a few percent of the portfolio. So a decision that turns out to be wrong will not affect you very much and you can still crow about decisions that turn out to be right. :LOL:
 
I have always followed the formula of spending cash on hand first, replenishing cash on hand from fixed income interest and or maturing bonds, then using equities.
I haven’t touched equities yet and there exists a chance I may never have to touch equities out of need and only by desire for rebalancing.
 
Last edited:
When I was buying, my algorithm was to buy as much as possible, as soon as possible, and rebalance to my target AA according to my IPS, which in turn was based on my life circumstances.

Now that I am selling, my algorithm is to sell as little as possible, as late as possible, and rebalance to my target AA according to my IPS, which in turn is based on my life circumstances.
 
People here know that I am a self-proclaiming market timer (a clean and not dirty one, as I take a shower everyday).

My withdrawal has nothing to do with my market timing, because I have a big cash buffer, way bigger than my annual expenses. I withdraw cash for expenses as I need, and never sell because I need cash.


...
One salvation is that you are withdrawing a relatively small amount of money; just a few percent of the portfolio. So a decision that turns out to be wrong will not affect you very much and you can still crow about decisions that turn out to be right. :LOL:

Yes. A few percent of selling or rebalancing will not make much of a difference.

My WR is less than 1%/year. My cash level is currently almost 40% of portfolio.

In the last month of October, I sold many OTM call options, and enough got assigned such that my stock AA dropped from 74% to 60%. This 14% additional cash is now sitting in a T-bill fund earning almost 3%/year.

And I am waiting to move this cash back to stocks. I like high stock AA, at 70-80%. :)
 
Last edited:
Yes! How true. My first foray into investing, literally 50 years ago, was an effort to use Fourier transforms to analyze stock price series. :banghead: It didn't work, of course.

@music-and-ski, what I slowly learned is what sixty years of academic research has shown: The equity market is best viewed as a random process with a slight upward bias. So while it is certainly possible to develop an algorithm that fits historical data, it will not be predictive. You can't predict random.

Assuming you have a simple portfolio of broad index funds as the research recommends, the withdrawal decision just becomes a decision to sell from the equity side, the fixed income side, or a little from both. Your AA and recent market effects on it will guide you in most cases.

As far as when to sell, that's mostly a matter of psychology. Selling in January maybe indicates some pessimism about the year's market. Selling only as needed leaves money in the market longer and is maybe a sign of optimism (or of faith in the market's long-term upward bias). Like all decisions to trade, this too is a market timing decision. No reason to be ashamed.

One salvation is that you are withdrawing a relatively small amount of money; just a few percent of the portfolio. So a decision that turns out to be wrong will not affect you very much and you can still crow about decisions that turn out to be right. :LOL:

Ha I can tell we are the same in spirit. Thanks. Nice to meet you.

If it’s a random process with a slight upward bias, then one should be able to do better than fixed % withdrawal on a schedule just by putting in some limit orders and waiting for things to rise before selling. Maybe I’ll model it as a Monte Carlo as a random correlated time series, rather than using historic data, to prove the point. It’s not “market timing”, it’s just recognizing that random processes have highs and lows. Hopefully I’ll be able to report back soon.
 
Nice to meet you too. Sad to say, though, is that there is a catch to "random." The distribution is not Gaussian.
 
Selling algorithm: rebalancing takes care of that. It automatically sells from the winners (or least losers). I do the withdrawal and rebalancing one a year in early Jan. The withdrawal typically goes to a high yield savings account which then feeds my checking monthly.

My withdrawal calculation is based on each Dec 31 portfolio value so I do take a pay cut after market down years as we draw the same x% each year. The pay cut has not been a problem for us as we often experience strong market up years ahead of it so income rises on average.

Have you thought about:
1) setting a trigger level for rebalancing, eg 5% off-target is when you sell the part that went high, and/or
2) using something less arbitrary than Dec 31 valuations for your calculation
??
 
Nice to meet you too. Sad to say, though, is that there is a catch to "random." The distribution is not Gaussian.

Ahh here’s an article https://towardsdatascience.com/statistical-properties-of-stock-prices-15145be752a2 looks complicated maybe I’ll just use historic prices instead, reality us sometimes so much easier to work with than math.
 
Have you thought about:
1) setting a trigger level for rebalancing, eg 5% off-target is when you sell the part that went high, and/or
2) using something less arbitrary than Dec 31 valuations for your calculation
??

1) I do have some bands and in Jan if things are pretty close to in balance that’s good enough. If there is a huge change during the year I may do some rebalancing. This doesn’t happen often.

2) No. Dec 31 is it. I don’t mess around with that. The timing is not that arbitrary because end of year I typically get a lot of distributions affecting my asset allocation.
 
I did some simulation with the daily TSX quotes from 1979, adjusted for inflation. Scenario was:
* Start with 800K investment (1979 dollars)
* Spending needs 100K 2022 dollars (26K 1979 dollars)
* Cash earns zero interest
* No commissions on sales.
Also, I didn't find the TSX total return index, just the TSX index (so, I guess dividends are ignored).


Parameters were:
a) cash refill amount (how high to fill up the tank of cash when choosing to sell)
b) if cash is less than X% and growth over Y days is greater than Z%, refill the tank.
Additionally, if the tank of cash ever gets completely empty, fill it up again to the top.

After running some genetic algorithm search, it seems that the best strategy in this scenario is quite simple:

KEEP CASH RESERVES AS SMALL AS POSSIBLE. Any gain from trying to wait until the TSX had risen an appropriate percentage is offset by the fact that having enough cash on hand to wait it out meant less was invested in equities.

Not the result I was expecting.
 
^^^

I am not sure about the Canadian market, but the period of 1980-2000 may be the strongest and longest bull run of the US market. It would pay to invest 100% during this period (I did not).

I wonder if your result changes any if you start from 2000. Or if you look at individual 10-year periods.

If the result does not change, then you know what to do.

If it changes, then there is no universal method that is applicable both for bull and bear periods. Next, one would need a bull/bear detector.
 
Ahh here’s an article https://towardsdatascience.com/statistical-properties-of-stock-prices-15145be752a2 looks complicated maybe I’ll just use historic prices instead, reality us sometimes so much easier to work with than math.
Probably wise. To amplify a little from post #14:

The distribution has fat tails.
The distribution is asymmetric; the left tail is fatter.
Samples are not uncorrelated. The momentum effect is small but real.
The rightward bias is very noisy; it may take averaging over years to see it.

Finally, Nassim Taleb has observed that unless one knows what a distribution looks like (which we do not), one cannot know how many samples are needed to characterize it.

But at the bottom, sadly, IMO you are attempting to predict random behavior. If you figure it out, though, please let me know and tell no one else. :LOL:
 
I did some simulation with the daily TSX quotes from 1979, adjusted for inflation. Scenario was:
* Start with 800K investment (1979 dollars)
* Spending needs 100K 2022 dollars (26K 1979 dollars)
* Cash earns zero interest
* No commissions on sales.
Also, I didn't find the TSX total return index, just the TSX index (so, I guess dividends are ignored).


Parameters were:
a) cash refill amount (how high to fill up the tank of cash when choosing to sell)
b) if cash is less than X% and growth over Y days is greater than Z%, refill the tank.
Additionally, if the tank of cash ever gets completely empty, fill it up again to the top.

After running some genetic algorithm search, it seems that the best strategy in this scenario is quite simple:

KEEP CASH RESERVES AS SMALL AS POSSIBLE. Any gain from trying to wait until the TSX had risen an appropriate percentage is offset by the fact that having enough cash on hand to wait it out meant less was invested in equities.

Not the result I was expecting.


You guys I set the cash portfolio to have a return equal to inflation. Now I see a different story. Fill up your cash bucket to 80% of annual spending. Fill it up again by selling equities when it's empty, or when it's at least 20% empty and growth over the last 276 days is 31% or more.
 
You guys I set the cash portfolio to have a return equal to inflation. Now I see a different story. Fill up your cash bucket to 80% of annual spending. Fill it up again by selling equities when it's empty, or when it's at least 20% empty and growth over the last 276 days is 31% or more.
Sigh. Why would you expect that this scheme will be optimum in the future?
 
Sigh. Why would you expect that this scheme will be optimum in the future?

I'm not expecting it to be "optimum", any more than I expect DCA to be "optimum" for buying. I was looking for a simple no-brainer rule set that just makes sense.

This is worth repeating: I used an optimization algorithm to find a simple rule set for one data set, but I'm not expecting it to be an optimum rule set.

This one's a pretty simple rule. It keeps one quite highly invested in equities which I know from Firecalc is almost always wise. (Only zero to 80% of annual spending in "cash"). It only prompts you to bump up more cash (keeping closer to the 80% annual spending) if returns have been quite stellar lately.
 
I'm not expecting it to be "optimum", any more than I expect DCA to be "optimum" for buying. I was looking for a simple no-brainer rule set that just makes sense.

This is worth repeating: I used an optimization algorithm to find a simple rule set for one data set, but I'm not expecting it to be an optimum rule set. ...
Got it. As long as you understand what you're doing I have no problem with it at all. We are much more ad hoc with our withdrawals. Yearly spending is not at all level, so that is a factor for us too. Good luck.
 
When I was buying, my algorithm was to buy as much as possible, as soon as possible, and rebalance to my target AA according to my IPS, which in turn was based on my life circumstances.

Now that I am selling, my algorithm is to sell as little as possible, as late as possible, and rebalance to my target AA according to my IPS, which in turn is based on my life circumstances.

This does not seem crazy. But it does expose you to selling in down markets since "as late as possible" could easily be into a huge downdraft. At that point you have no good option.
 
Back
Top Bottom