Save time and earn more with this one investing trick

Recently, we have seen many videos and blog posts on when to sell to improve your investing results. These all rely on the S&P 500 as the investment of choice for the algorithms. But they are telling you when to sell. But what do you do then? Sit on the cash? No! You have to buy back in at some point. So when do you optimally sell and when do you optimally buy? Because we at TimeCatchApp are an inquisitive lot with expertise in data science, we used machine learning to find the best algorithm for selling and buying.

At TimeCatchApp, we are always trying to make your life easier and more prosperous. Usually we do it supporting your consulting business with a great platform that saves you time and help you earn more with integrate time tracking, invoicing, document storage, project management, all backed by regulatory grade audit trails. But now that you are using TimeCatchApp and making more money than before and also have some free time to invest in your future, you may want to invest your extra earnings in the stock market.

Disclaimer: At TimeCatchApp, we are experts in data science, AI, and software development. But we are not financial professionals. Always consult with your own financial advisor before making any investment decisions, and do your own due diligence. Past results does not guarantee future performance.

Data and assumptions

We collected monthly data from the S&P 500 index, from December 1927 to December 2025. Over that time there were many market increases and decreases. We assumed that the investment option was a S&P 500 index fund or cash. We also assumed that there was minimal fees in the index fund, and cash pays 3%. In this scenario cash would be stashed in a money market fund, and not the low interest cash account most brokerages default to. We did not account for dividends, which add another 3%. And importantly the algorithm also assumes no leverage, no borrowing of money to buy stocks.

The typical claim is to sell some amount of the portfolio when the index is down a fixed percentage from its last high, sell another tranche at a lower percentage, and the final liquidation at the third even lower percentage. All well and good, but one needs to buy back in. And what does this gain you versus a buy & hold strategy, where you just buy the market and never sell for any reason? Let’s find out.

Best selling/buying strategy

We have two options for our algorithm: (1) Sell at one time and buy at one time [we will call this the cliff algorithm]; (2) Sell in thirds and buy back in thirds, with the exact percentages to be decided by the machine learning algorithm [we will call this the 3-step algorithm]. We did this with both the series starting in 1927 (before the great crash in 1930 and the Great Depression), and one starting in 1947 (generally the more modern time period). What did we find?

Let’s consider the longest run possible, training the models on the data from 1927 onwards. The optimal strategy, for either the cliff or 3-step algorithm produces somewhat higher earnings, with an average of 7.6% for the 3-step algorithm, 7.3% for the cliff algorithm, or 6.0% for the buy & hold algorithm.

The economic environment from 1927 to end of World War II had some very unusual circumstances that are not likely to be replicated. So, what if we constrict to just the 1947 onwards data? Do we get similar results? Yes, yes we do.

The 3-step algorithm yields 8.3% growth, the cliff model yields 8.1% growth, while the buy & hold achieves only 7.7%. Over a 30 year investment horizon, the optimal gives you 16% more assets, for not much work. And in fact the number of trades is fairly small in number: 5 times you jump out of the market in the cliff algorithm over the 100 year period, and in the 3-step algorithm about once every 3 years.

When to buy and sell

The optimal solution for the full life of the data series is shown in the figure below. Sell at the indication that the market drop is coming, and buy in aggressively after the bottom.

When and how much to sell and buy
Sell when market is starting to head down, and buy when starting to head up. Here’s when.

How does this look in practice? The plot below shows you the balance between being invested and in cash. Green indicates invested, and blue in cash. And in some months you have both green and blue indicating holding of both. As you can see, with this strategy you are essentially just sidestepping the downside. And this sidestepping of the down drafts is what produces the earnings difference.

Best strategy outperforms buy and hold
Holdings and market returns by month from 1927 to 2025

We looked at strategies with up to 3 sell and buy points. But you are busy keeping clients happy. Can we just sell at one time, and get similar results? Indeed you can! Below is the algorithm when there is only 1 sell and 1 buy per cycle.

Buy/sell graphic
And the number of cycles is not very high. With this reduced rate of trading, you only need to look at cases with large drops in the market, so you can concentrate on growing your consulting business.
Optimal strategy outperforms buy and hold, giving you another 1.5% yearly returns on average
Simple strategy outperforms buy and hold

But there is one more huge benefit to this trading strategy: Less volatility. Substantially so. On years where the market is down, the optimal trading has an average loss of -3.0%, with a maximum loss of -18.8%. However, the buy & hold strategy has an average loss of -8.2% and a worst case loss of -45.4%. But to be fair you will also miss out on some bragging rights to the upside, since the optimal strategy average gain during an up year is 11.5% vs 13.8% for the buy & hold, with maximum gains of +37.5% for the optimal and a whopping +61.0% for the buy & hold.

Optimal strategy sidesteps market downturns
Optimal strategy vs buy and hold

Refer a friend to TimeCatchApp and get the full report, coming in February

The optimal trading strategy gives you higher average earnings and less volatility. If you want the R code and underlying data, sign up for a free account on TimeCatchApp. Information will be provided in a template project available only to TimeCatchApp account owners.

To get this report, project templates, and our latest ebook on consulting metrics, sign up today!

Happy time catching!