Cracking the Code: A Beginner’s Guide to Stock Price Prediction

Miryam Chen
5 min readApr 19, 2023

--

Introduction

At first glance, the stock market may seem daunting, especially for those who are not in the financial industry and have no prior experience with it. You might have heard people say, “Putting money in stocks is like gambling, you will lose money!” . While the investing culture in the United States is more developed, and people tend to be more savvy in these topics. Unfortunately, this is not the case in many other countries.

Having recently learned that the stock market is an excellent wealth-building tool, I have decided to familiarize myself with it. As the saying goes, “compound interest is the eighth wonder of the world.” To start my journey, I will be using a simple S&P500 dataset that I found on Kaggle.

The S&P 500 (Standard & Poor’s 500) is a stock market index that tracks the performance of 500 large-cap publicly traded companies in the United States. It is widely regarded as a benchmark for the overall performance of the US stock market, and many investors use it as a gauge of the economy’s health. Some of the basic concepts we need to understand to get started are:

Sector: segment of the economy where businesses operate and offer a common product or service.

Price: The cost of a single share of the company’s stock.

Price to Earnings(PE): The ratio of a company’s price per share to its earnings per share.

Dividend yield: The ratio of the annual dividends per share divided by the price of a share

Earnings Per Share (EPS): A company’s profit divided by the number of shares

Market Cap: The market value of a company ( share price x total number of shares)

EBITDA: A company’s earnings before interest, taxes, depreciation, and amortization; often used as a proxy for its profitability

Price to Sales(PS): A company’s market capitalization divided by its total sales/revenue over the past year.

Price to Book (PB): A company’s market capitalization divided by its book value, which is the total value of a company’s assets minus its liabilities.

Part I: How to get started with so many companies and so much information?

While there are many ways to classify the companies in the stock market, such as by size, by growth, etc. As a first approach, to understand the market, I would start by categorizing the companies by sector, that is, by the common industry their business is focused. This data is usually readily available.

On this first analysis, we see there are 11 sectors included in the S&P500: Industrials, Health Care, Information Technology, Consumer Discretionary, Utilities, Financials, Materials, Real Estate, Consumer Staples, Energy, Telecommunication Services.

How are these sectors represented in the S&P500 index? Are they evenly represented?

In the below graph we see that the top 5 sectors account for more than 57% of all the companies in the index:

Figure 1: S&P500 company distribution per sector

If we look at the composition of S&P500 by market cap, the top 5 sectors (which happens to be the same 5 sectors by company number) make up for more than 67% of the total market cap.

Figure 2: S&P500 market cap distribution per sector

Given that the S&P500 includes the top 500 companies with the largest market cap in the US, we can conclude that these sectors are significant drivers of the US economy and have a considerable influence on the index’s overall performance. This distribution might vary over time as the economy trend changes, but the at the time the dataset was gathered, the top sectors both by company count and market cap are: Consumer Discretionary, Information Technology, Financials, Industrials and Health Care.

Part II: How to approach the sectors?

To begin, it would be interesting to understand if we can apply the same criteria to analyze all the sectors. For example, would the leading sectors discovered above also lead in the distribution of all the financial metrics? I ranked the different sectors by their mean on each metric, and it turns out the companies occupying the top rank in each metric differs considerably.

Figure 3: various financial metric distribution by sector mean

The above indicates that some metrics might be more import for some sector than others. This raises the below questions: which metrics are more important for which sectors and why is it so? Are some sectors more profitable than others? These are interesting questions that can be explored in detail in another time, in a sector by sector basis.

Part III: How to Evaluate Individual Companies?

While financial metrics serve as valuable tools to guide investors in assessing a company’s performance, they should only be used as a general guideline. A good starting point is to gain an understanding of the sector in which the company operates. Look at comparables within that sector for additional guidance.

While assessing the performance of a company’s stock, it is essential to consider various factors beyond just the market trends. A range of other factors, such as the company’s growth potential, perceived risk, and economic conditions, can significantly impact its valuation.

Chart showing the predicted stock prices versus the real price based on the 10 financial metrics provided in the dataset.

Figure 4: stock price prediction versus real price

Conclusion

While the stock market may initially appear intimidating, the above analysis has demonstrated that it can be demystified by breaking it down into smaller, more manageable groups based on shared characteristics. Furthermore, there are many financial metrics available to aid in its valuation, facilitating analysis and comprehension.

The key takeaway from this exercise is that taking the first step is crucial in the learning process. Although it may be daunting to become an expert on the entire stock market, starting with a single sector and trying to become an expert in that area could be a viable approach.

--

--