Is Tesla overvalued? How to do stock valuation with machine learning.

Model basic anatomy

  • Dataset: The latest balance sheet, income statement, and cash flow statement from each stock of the S&P 1500. The S&P 1500 is the combination of the S&P 500 (large-cap stocks), S&P 600 (mid-cap stocks), and S&P 400 (small-cap stocks). Because of missing data, I had to discard 93 stocks.
  • Input variables (Xs): A total of 16 different financial figures for each company, pulled from the last quarterly filing (10Q). Think income, revenue, assets, dividends-paid, revenue-growth, etc.
  • Output variable (Y): Market cap. This is the stock price multiplied by the number of shares outstanding. You can think of the market cap as the price to buy the entire company. Tesla’s market cap is currently about $700 billion.

Conventional stock valuation

Perhaps the most well-known investment strategy is known as “value investing”. Most commonly associated with Benjamin Graham and Warren Buffet, value investing recommends buying undervalued stocks and holding them for long durations — usually years or decades. While value investing is conceptually simple, execution can be tricky.

How do you identify an undervalued stock?

One basic strategy is to look at valuation ratios. Some well-known ratios include the following:

Price/Earnings (P/E)

The P/E ratio is a company’s market cap divided by its earnings. A good way to think of this ratio is how expensive a company is relative to its yearly profits. Since the 1920s, the P/E has been the most well-known and commonly used stock valuation metric. Tesla has a P/E of about 1400x which implies that it would take 1400 years of Tesla’s yearly profits to buy the company. For comparison, Apple’s P/E ratio is closer to 40 — slightly above the current market average.

Earnings vs. Market Cap. TSLA is red.

Price/Sales (P/S)

The P/S ratio is a company’s market cap divided by its top-line sales. This ratio has become increasingly important in recent decades as more companies choose to forgo profits and instead reinvest their spare cash to grow faster. For example, consider that Amazon didn’t make a profit until 2017. Before that, AMZNs P/E was meaningless and it was more sensible to use P/S instead.

Sales vs. Market Cap. TSLA is red.

Price/Book (P/B)

The P/B ratio is a company’s market cap divided by its “book” — which is its assets minus its liabilities (debt). Another way to think of “book” is how much you could get by closing down a company and selling everything. P/B is most useful in two categories: traditional companies with a lot of assets, and companies in financial trouble. For companies with a lot of assets, the P/B is a measure of how well they are making use of them. So a company that owns one factory but makes a lot of money from that factory would likely have a high valuation. At the other end, for companies in financial trouble, the P/B becomes a worst-case contingency measure. If the company must shut down, how do the stockholders fare after assets are sold and debt is settled?

Book Value vs. Market Cap. TSLA is red.

Dividend yield

The dividend yield is a little different than the other ratios above. It’s the total yearly dividends divided by the market cap — so the numerator and denominator are swapped. Before the 1920s, this was the primary stock valuation ratio. In that era, companies distributed most earnings back to the shareholders via dividends. Today, the biggest dividend payers tend to be old stable industries like utilities. These enduring, steady companies make regular profits but can’t easily reinvest them.

Dividend Yield vs. Market Cap. TSLA is red.

The problem with valuation ratios

Using the valuation ratios above, we can get a sense of how overvalued Tesla is by comparing Tesla’s ratios to the market averages.

TSLA figures from MorningStar. S&P 500 figures from multpl.

Model Design


The financial statements of public US companies are available for free on the SEC website. Companies are required by law to disclose their finances in a quarterly form called the 10Q. In this document, you can find their balance sheet, income statement, and cash flow statement. While the SEC has mandated that this data must be available in computer-readable form, it is still quite burdensome to parse. As a result, several companies have stepped in to sell cleaned financial figures via API. I used EODHistoricalData.

Algorithm selection

Estimating stock prices is a regression problem. We are taking a set of numbers and using that to estimate another number. In the regression algorithm class, there are a few options:

  • Linear regression
  • Polynomial regression
  • Linear SVMs
  • Decision trees
  • Neural networks

Model inputs

In each SEC-filed 10Q, there are hundreds of figures that reveal a company’s financial health. Ideally, I would have preferred to use all of them as model inputs. However, I needed to limit the input count for two reasons:

  1. Lack of consistency: Apart from a handful of top-line items like revenue, earnings, and assets, companies are surprisingly different in what they choose to report and how they choose to calculate their figures.
  2. Overfitting: Overfitting is more likely when there is a limited dataset. My dataset only contained 1407 individual data points.


  • Dataset: 1407 stocks
  • Algorithm: XGBoost in a 100-model ensemble
  • Runs: 100 random test/train splits
  • Average test r²: 0.95

Problems with the model / next steps

Recently, I’ve started working with a financial advisor on the model. There are three specific improvement areas we are targeting:

  1. More data != better results: While we’re using the S&P 1500 stocks for the dataset, we would like to use the 6000+ stocks from the US market (NYSE + Nasdaq). However, attempting to use this larger dataset throws off the model. Our hypothesis is that S&P selects their index constituents partially for the rationality of their market caps. However, a good stock valuation model should be able to predict any market cap.
  2. Model jitter: Given that financial fundamentals only change once-per-quarter, price estimates also shouldn’t swing much day-to-day. However, because the market caps change, the model itself also tends to swing. We think this is partially explained by XGBoost, which is a decision tree algorithm. Decision tree algorithms have a reputation for being more “touchy” like this. The problem might be remedied with a different algorithm or by averaging market caps over several days/weeks.
  3. Better explainability: While the model has a high r², the input dimensions are somewhat discordant. Some are absolute values, others are ratios, others seem like repeats. Missing, but not for lack of effort, are any input dimensions that capture the “acceleration” of a company — e.g. the change of the change.

So should I buy Tesla stock?

I wouldn’t recommend it 🙂



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Scott Rogowski

Scott Rogowski

Author of mongita & code2flow. Working on FFER & fastmap.