Investing in Stocks - 4b: What to Buy - A Sample Simulation

2024-07-18

Topic(s): Stocks

Investing in Stocks - 4b: What to Buy - A Sample Simulation

In the previous article we learned about different parameters we can use to simulate stock trading using historic stock prices. In this article, we'll look at the results of a sample simulation and understand how to use this to decide which investment strategy works best.

Simulation Parameters

In the previous article we introduced a few buy-/sell- related threshold parameters in our profile. Let's revisit them here. We'll be using these in our sample simulation.

Thresholds
ParameterValueNotes
Expected gain30%The gain that we're expecting from our stock investment. This could be a conservative value (<10%) or an ambitious value.
Buy threshold4%Percentage points by which a stock's price needs to rise (from its latest lowest ('trough') value) for us to invest in it.
Peak drop threshold8%Percentage points by which a stock's price needs to drop (from its latest highest ('peak') value) for us to sell it.

Sample Simulation

Similar to stock analysis, there are several ways to perform the simulation. We could use a publicly available stock simulation service (some services refer to this simulation as backtesting). Some of services are free and some require a payment. Alternatively, we could use a spreadsheet and/or a programming language to perform the simulation ourselves, either 'by hand' or automated through a computer program.

Irrespective of whether we use a publicly available service or roll one out ourselves, we want to make sure that the simulation/backtesting supports what we need:

  • Support for simulating different investment strategies. We want to see which strategy worked best for each stock, and for how long. A company's stock price may show different growth patterns during its start-up and mature phases. And, different stocks may behave differently with the same strategy.
  • Configurable investment periods. We want to see how a stock did quarter over quarter, year over year, etc., over a period of 1 to 10 years.
  • Configurable 'buy' and 'sell' thresholds and 'expected gain' values. Since the 'investment window' (the time we're actually invested in a stock) is defined by the 'buy' and 'sell' times, threshold combinations allow us to simulate investment windows, and see which worked best.
  • Support for taxes. If our simulation includes 'selling' a stock (and not just 'buying and holding'), we want to understand the short- and long-term tax implications.
  • Ability to compare the performance of multiple stocks, and sort the results by period, by gain/loss, etc.
  • Ability to exclude certain time frames where we know that the stock price was skewed due to external factors unrelated to the underlying company's performance (e.g., an international political event or a natural calamity affecting several stock prices). Use this with caution: external factors affecting the stock market are fairly common and may give us a more realistic view of the stock price's history — we don't want to exclude these times just to get an 'ideal' set of numbers.

Sample Simulation Report

Here's a sample report that simulates trading a hypothetical stock AAAA. It shows the gain percentage (or loss, if negative) for each of the strategies we discussed above.

Symbol: AAAA
Period: 1 to 4 years
Strategies:
  Pass - passive,
  Gain - sell upon gain,
  Peak - sell upon drop from peak
Buy Threshold: 4%
Peak drop threshold: 8%
Expected gain percent: 30%
Short term Tax rate: 33%
Long term Tax rate: 20%

Gain (or loss) if the stock was held over the last 'Period' years.

Prd Strat      Gain%  BuyT% SellT% GainT%  #Buys #Sells
-------------------------------------------------------
 1y  Pass      +8.03      4      -      -      1      0
 2y  Pass     +42.85      4      -      -      1      0
 3y  Pass    +123.65      4      -      -      1      0
 4y  Pass    +227.37      4      -      -      1      0

 1y  Peak      -2.17      4      8      -      6      5
 2y  Peak     +22.10      4      8      -     11     10
 3y  Peak     +61.87      4      8      -     13     12
 4y  Peak    +105.30      4      8      -     15     14

 1y  Gain      +0.89      4      8     30      5      4
 2y  Gain     +17.49      4      8     30      6      5
 3y  Gain     +52.87      4      8     30      8      7
 4y  Gain     +99.93      4      8     30     10      9

Here are what the columns in the report mean:

  • Prd: Period: how long were we invested.
  • Strat: Strategy we used.
  • Gain%: Cumulative gain that we got during this period.
  • BuyT%, SellT%, GainT%: the buy, sell, and gain thresholds at which we bought or sold stock. These are the same values that we specified in our profile (4%, 8%, 30%, respectively). If any of these wasn't relevant for the strategy, it is indicated as '−'.
  • #Buys, #Sells: number of times we bought and sold the stock.

The first four rows of the report indicate the performance if we had used the 'passive' strategy, the next four represent the 'peak' strategy and the last four the 'gain' strategy. Each row shows the gain (or loss) percentage as if we had invested in this stock X years ago (where X is 1 to 4).

Let's look at a few rows.

Row 1 (the one starting with '1y Pass') indicates that: we bought the stock 1 year ago and decided to use the 'passive' strategy. In that period, the stock price increased by 8.03%. We bought the stock when it's price rose by 4% from its 'trough' value. Since this was the 'passive' strategy, the 'sell' and 'gain' thresholds were not relevant (and are thus indicated as '−'). Since we held on to the stock after buying (i.e., did not sell any), the number of buys is 1 and the number of sells is 0. In summary: if we had invested $100 a year ago, our investment would now be worth $108.03.

Row 7 (the one starting with '3y Peak') tells us this: we bought the stock 3 years ago and decided to use the 'peak' strategy. In that period, the stock price increased by 61.87%. We bought the stock when its price rose by 4% from its 'trough' value. Since this was the 'peak' strategy, we sold the stock when the price peaked and fell by 8% from its 'peak' price. We then waited for the price to rise again so that we can buy it again, and so on. Since we used only the 'peak drop threshold' to sell the stock, the 'gain threshold' wasn't used in this strategy (and is thus indicated as '−'). The number of times we bought and sold the stock are 13 and 12, respectively. Summary: if we had invested $100 three years ago, our investment would now be worth $161.87.

Row 9 (the one starting with '1y Gain') tells us that we bought the stock 1 year ago and decided to use the 'gain' strategy. In that period, the stock price rose by 0.89%. We bought the stock when its price rose by 4% from its 'trough' value. Since this was the 'gain' strategy, we sold the stock when the gain reached 30% or the price peaked and fell by 8%, whichever occurred first. (Judging by the dismal gain of 0.89%, it was probably the latter!) We then waited for it to rise again so that we can buy it again, and so on. The number of times we bought and sold the stock are 5 and 4, respectively. Summary: if we had invested $100 a year ago, our investment would now be worth $100.89.

It is important to note that the 'Gain%' column indicates cumulative gains over the entire period, not annualized gains. For example, a gain of +42.85% in two years means that over the course of two years the stock price went up by 42.85%.

What this simulation report tells us at a high level:

  • For the hypothetical stock AAAA, the 'passive' strategy worked best every year.
  • The 'peak' strategy lost money in the last year, but over the last four years, performed pretty well.

More Insights

There are a lot more insights in the stock simulation report. By studying the result of a simulation, we can learn about the stock. For example, in the one year 'peak' strategy case, even though the stock price dropped five times (as indicated by the number of sells), it clearly recovered to produce an overall gain (as shown by the corresponding 'passive' strategy row). This seems to be true for other periods also, for this stock. In other words, this stock price seems to be steadily going up year over year, albeit with bumps in between. (The number of buys and sells is a good indicator of the volatility of the stock.)

Every stock will have a different trajectory of gains and losses. That is the whole point of the what-if simulation. Simulation tells us which strategy worked best for which stock, and over what periods. For a generally upward trending stock (even with several blips along the way), a passive strategy might bring in most gains. Similarly, for a volatile stock that goes up and down a lot but whose overall gain isn't much, a peak strategy might work better because we could take advantage of every drop and rise of the stock price. However, too many 'sells' will also increase the amount of tax we need to pay on any gains we make.

Effect of Threshold Values on the Gain

Here's a simulation report that uses a range of values of buy/sell/gain thresholds (not just the ones in our profile) for the same hypothetical stock AAAA. As these thresholds control when we buy and sell, it is interesting to see the effect these have on the overall returns.

To make comparison easier, we'll first reproduce the earlier report here. It is then followed by the one with varying threshold values. In the second report, the simulation program varied the 'buy threshold' from 1% to 5% and the 'peak drop threshold' from 4% to 10%, and showed the combinations that produced the highest return, for each strategy. This time, in both reports, we've shown the rows ordered by maximum gain percent for each period (1 year, 2 years, etc.).

Buy Threshold: 4%
Peak drop threshold: 8%
Expected gain percent: 30%

Prd Strat      Gain%  BuyT% SellT% GainT%  #Buys #Sells
-------------------------------------------------------
 4y  Pass    +227.37      4      -      -      1      0
 4y  Peak    +105.30      4      8      -     15     14
 4y  Gain     +99.93      4      8     30     10      9
 3y  Pass    +123.65      4      -      -      1      0
 3y  Peak     +61.87      4      8      -     13     12
 3y  Gain     +52.87      4      8     30      8      7
 2y  Pass     +42.85      4      -      -      1      0
 2y  Peak     +22.10      4      8      -     11     10
 2y  Gain     +17.49      4      8     30      6      5
 1y  Pass      +8.03      4      -      -      1      0
 1y  Gain      +0.89      4      8     30      5      4
 1y  Peak      -2.17      4      8      -      6      5
Buy Threshold: 1% to 5%
Peak drop threshold: 4% to 10%
Expected gain percent: 30%

Prd Strat      Gain%  BuyT% SellT% GainT%  #Buys #Sells
-------------------------------------------------------
 4y  Pass    +227.37      4      -      -      1      0
 4y  Gain    +126.90      1      8     30     11     10
 4y  Peak    +121.89      5      8      -     13     12
 3y  Pass    +123.65      4      -      -      1      0
 3y  Gain     +73.51      1      8     30      9      8
 3y  Peak     +69.40      3      8      -     13     12
 2y  Pass     +42.85      4      -      -      1      0
 2y  Peak     +29.47      5      7      -     12     11
 2y  Gain     +25.25      1      8     30      5      4
 1y  Gain      +9.48      5      6     30      4      3
 1y  Pass      +8.03      4      -      -      1      0
 1y  Peak      +7.82      1      9      -      5      4

It is instructive to compare the two reports to see the effect of the 'buy' and 'peak drop' threshold values on the overall gain percent and also on the number of buys and sells.

Once again, this reinforces that different strategies work best for different stocks for different time periods.

Another Example

Now let's now look at the simulation for another hypothetical stock (BBBB) for the same periods.

Symbol: BBBB
Period: 1 year to 4 years
Strategies:
  Pass - passive,
  Gain - sell upon gain,
  Peak - sell upon drop from peak
Buy Threshold: 4%
Peak drop threshold: 8%
Expected gain percent: 30%
Short term Tax rate: 33%
Long term Tax rate: 20%

Gain (or loss) if the stock was held over the last 'Period' years.

Prd Strat      Gain%  BuyT% SellT% GainT%  #Buys #Sells
-------------------------------------------------------
 1y  Pass     -33.04      4      -      -      1      0
 2y  Pass     -28.30      4      -      -      1      0
 3y  Pass     -50.93      4      -      -      1      0
 4y  Pass     -28.50      4      -      -      1      0

 1y  Peak      -6.26      4      8      -     10      9
 2y  Peak     +12.91      4      8      -     14     13
 3y  Peak     -23.41      4      8      -     22     21
 4y  Peak     +26.85      4      8      -     27     26

 1y  Gain     -11.34      4      8     30      7      6
 2y  Gain     +14.08      4      8     30     12     11
 3y  Gain     -18.43      4      8     30     17     16
 4y  Gain      -7.80      4      8     30     24     23

This stock shows a very different picture. It's performance is all over the place! According to the simulation, over a 4 year period, if we had used the 'passive' strategy, we would have lost 28.5% (an initial investment of $100 would now be $71.50). If we had used the 'gain' strategy, our losses would have been a modest 7.8%. But, if we had used the 'peak' strategy, we would have actually gained 26.85%.

For this particular stock, the 'peak' strategy seemed to have worked better for certain periods.

A Note on Taxes

We briefly mentioned taxes above. Every time we sell a stock (either because we hit the 'peak drop threshold', or 'gain' threshold, or for any other reason), the gains are taxable — at the short- or long-term tax rate, depending on how long we were invested. That means that our net gains are typically lesser by that much. (For example: if the tax rate is 33% and we made a pre-tax gain of 30%, our post-tax (real) gain will be 20%.) It is important to keep this in mind, especially if the simulation program does not factor this into its calculations.

Of course, the net tax depends on our other incomes and losses. Consulting a licensed tax planner that can advise us on the best tax strategy suited for our individual needs is a good idea.

Summary

We got introduced to stock trading simulation — a technique that helps us understand a) how specific stocks behaved historically, b) how different investment strategies worked for different stocks, and c) how different buy/gain/sell thresholds could affect our gains and losses.

In subsequent articles, we'll look at ways to decide when to buy a stock and how many shares of a stock to buy at a time.

`