A Preliminary Study on the Investment Strategy Based on the History of S&P500’s Stock Price in Nearly 100 Years

Renyuan Lyu
8 min readJan 8, 2022

Apply Pattern Recognition, AI, Python to financial data (signal) processing

The chart above is a time-series of historical stock prices for the S&P 500 since 1930. This data is one of the most valuable data I have seen in recent years, and you can get it here.

Using Signal Processing, Pattern Recognition, Machine Learning, AI, which we are good at, plus Python and its data analysis modules numpy, scipy, matplotlib, pandas, yfinance, we can do some analysis, get some conclusions, and then form reliable suggestions , In the future financial planning of life, stick to the practice, and expect to gain benefits.

Preliminary observations of the original data:

  1. Dates 1928.01.01~2022.01.01, spanning 94 (= 2022–1928) years.

During this period, the stock price has risen about 270 times (= 4782.378 / 17.659= 270.8 times) and
converted into [annual average rate of return] r = 6.14%

Check: (1+6.14%)⁹⁴ = 270.8

In fact, the above data browsing and very simple data analysis alone provide great information:

1. 94 years ago (1st generation 30 years ago, this is 3rd generation ago, that is, the era of your great-grandfather), your ancestors helped you buy 1 yuan of S&P500 stock, which has now become 270 yuan. (If your great-grandfather gave 1 yuan to your grandfather, then to your father, and finally to you, it is still 1 yuan)
2. Your father helped you buy 1 yuan of stocks 30 years ago, and it has now become (1 +6.14%)³⁰=6 yuan.

Although the above is an exaggeration, it is only a simplified general concept. For example, the r value is actually a changing value, that is, the first 30 years, the middle 30 years, and the last 30 years are different.

Well, start practicing setting a strategy, and analyzing it:

[Ex001: buy stock @ t, sell stock @ t + 10 years]

Although the S&P500 stock can be multiplied by 270 times in 1994, it is impossible for you to use all the money. Therefore, it is inevitable to sell it at the right time after buying it. Let’s analyze it for 10 years first!

In the figure below,
X[t] (black and gray line) represents the stock price @t,
X[t+10 years] (purple line) represents the stock price @t +10 years

At time t, at the price of X[t],
buy the stock, pay 1 yuan, get n(t) shares = 1/X[t]
At the time of t+10 years, at the time of t+10 years, at the time of X[t+10 years] Price,
sell stock, pay n(t) shares, get y(t) yuan = X[t+10 years] *n(t)

In this way, every 1 yuan @t becomes y(t) yuan after 10 years.

For every share, stay in your house for 10 years, then say goodbye,
you get your cash back and do anything you can do with money.

We want to study this y(t)…

People who like to see pictures and tell stories or see things clearly, maybe you can follow my instructions below:

1. y(t) is the ratio of X[t+ 10 years] (purple line) to X[t] (black-gray line) in the figure
2. The difference between the purple line and the black-gray line is the profit (or loss) ) money
Purple on the top means making money, black on the top means losing money.
3. As shown in the picture below (the enlarged picture of the previous picture), it means that in December/2011, the 1 yuan invested will be sold in 10 years (ie December/2021), and the net profit will be 2.7753 yuan ( That is, it will sell for 3.7753 yuan at that time).

This strategy starts from 1928.01.01 and continues to be done every day (daily)
~ 2012.01.01 (this date is 10 years ago),
(PS: There is no 10-year data after 2012.01.01, so ignore it for now)

I would like to know the answers to the following questions.

  1. How much was paid in total during this period?
  2. How many days to make money? How much do you earn? (mean, standard deviation)
  3. How many days to lose money? How much? (mean, standard deviation)
  4. How much do you earn in total? (mean, standard deviation)

Use Python + data analysis module to make the following analysis step by step:

1. How much did you pay in total during this period?

ans:
dayBegin=1927–12–30
dayEnd= 2012–01–27
days= 17259 trading day
cost= 17259 yuan

2. How many days are there to make money? How much do you earn? (mean, standard deviation)

ans:
earnDays= 16015 days
cost= 16015 yuan
earnMoney= 23137 yuan

averageEarn= 1.44 yuan/day
stdEarn= 1.17 yuan/day

3. How many days do you lose money? How much? (mean, standard deviation)

ans:
lossDays= 1244 days
cost= 1244 yuan
earnMoney= -178 yuan
averageLoss= -0.14 yuan/day
stdLoss= 0.12 yuan/day

3.1
Probability of making money from extended information = 16015/17259 = 92.79%
chance of losing money = 1 — chance of making money = 7.21%

4. How much is the total profit and loss? (mean, standard deviation)

The horizontal axis of the above figure is the time axis (1928~2022), and the vertical axis is the money earned (investment 1 yuan, 10 years later), which is the [y(t) -1] yuan mentioned in the previous paragraph (1 yuan is cost)

The vertical axis of the above figure is the distribution of the 5 PR values ​​of the money earned
(min=0%, 25%, 50%, 75%, 100%=max)

count=17259
mean=1.33
std=1.20
min = -0.48
25% = 0.37
50% = 1.02
75% = 2.03
max = 9.9

— — — — — — — — — — — — — — — —

Total input cost = 17,259 yuan
Total net profit and loss = 22,958 yuan
Total rate of return = +133.02%

=================

The thoughts are listed as follows :

The above statistical chart data can be interpreted as follows.

For every $1, the “average” earnings after 10 years are $1.33.
Most of the time earning falls between [+0.13, +2.53] (=1.33 (+-) 1.20)

In the worst case, you will lose, (-) 0.48 yuan when you have
bad luck (25%), you can earn (+) 0.37 yuan when you have
ordinary luck (50%), you can earn (+) 1.02 yuan when
you have good luck (75%), you can Earn(+) $2.03
Best luck, earn(+) $9.9

Take another look at the statistics, histogram, to strengthen the confidence in the aforementioned analysis!

The horizontal axis of the figure below is the money earned (-0.48 ~ +9.9), and the vertical axis is the number of days of occurrence, which can be regarded as a probability distribution.

[For every 1 yuan, after 10 years, the “average” earns 1.33 yuan. 】

The statistical period spanned 94 years and about 3 generations. From the generation of great-grandfather (+90), grandfather (+60), father (+30) to you and me (0), among the 17,259 trading days, 16,015 were On the day of making money, only the remaining 1244 days are the days of losing money (including no profit and no loss, 1 yuan is still 1 yuan after 10 years, and there are also 3 days for this kind of day),

Chance of making money = 16015/17259 = 92.79%
chance of losing money = 1 — chance of making money = 7.21%
===================

When I was young (30 years ago), I didn’t know about such a good thing. Therefore, after I started to earn income, I failed to “do good deeds in time”. Even now, financial ability still belongs to the “lower middle” class of Taiwanese society. The so-called financial freedom cannot be achieved.

Now that I have learned this knowledge and technology by myself, I hope that I can use it for 30 years.
Buffett is in his 90s and is still active on the world stage with significant influence and contributions.

In another 30 years, I will still be younger than Buffett now, so from now on, I will definitely have a chance to catch up with Buffett’s 1/N, (N can be adjusted below 10^k (10 to the power of k)).

PS:

“Ex001: buy stock @ t, sell stock @ t + 10 years”

This is just an investment strategy, and investment matters are broad and profound.

Which stocks to buy?
How many years does it take to sell?
How much will it cost to sell?
How to reinvest the rest?

are topics for further study.
This article selects the S&P 500 Index to include the average market capitalization of the top 500 companies in the United States (the century-old country), spanning nearly a century of history.

Investment should have “investment goals”, and investment goals should be clear, never without goals, and should not set goals to make as much as possible. Because if you set the goal of “the more you earn, the better”, you will end up not knowing when to get out of the car, or even “dust returns to dust” after a crash!

There is a goal to achieve or not. After reaching the goal, take a rest to settle down and set the next stage goal.

keep it up.

PS 01:
This article is only presenting the process of personal analysis of information, not an investment advice. Everyone should be responsible for his own financial life.

PS 02:
S&P500 is a hodgepodge of concepts. The most famous financial products that track and copy it are SPY, VOO and other ETFs

PS03: The
Nasdaq 100 is another object worth studying. It represents the 100 strongest technology companies, and Apple, the strongest company in the 30 years, is also worthy of research. We will discuss it later.

【REF】: The python code used in the text is placed here.

--

--