Guide To Fundamental Analysis for Stock Market Investing with Python – DataDrivenInvestor

Introduction to fundamental analysis to start investing in the stock market.

Photo by Jeremy Bezanger on Unsplash

Money Money Everywhere. At least this has been the case for the global stock market last two years (2020 and 2021). All the indexes were going up. Some stocks climbed a couple of folds. It doesn’t matter which company you picked, it went up. Everyone became a stock market genius. Nobody cared about the fundamentals of a business. There was free money for everyone to grab, and many people became rich doing so.

But now the tide has turned. With a higher US Fed interest rate to fight inflation and another deep recision fear in mind, the stock market plunged, and volatility has gone to the sky.
This is not the time when you just randomly pick a stock and hope it will go to the moon. This is the time to carefully select companies with solid fundamentals and select those who have the tools needed to navigate this difficult economic time. Now you have to pick companies that have intrinsic value and good leadership, where you will be able to invest for the long term.

Different economic models can be employed to identify the intrinsic value of a company and check if the stock is trading below or over that number representing undervalued or overvalued respectively. But for that, we need historical performance data of the company. Unfortunately, getting a grip on a company’s longer-term historical data is often not that easy. At least not for free. 5 years of historical data are usually available on many websites, but no more than that.

Of course, you can always go into the customer relationship page of a company and look at the financial report that every publicly traded company must publish each quarter and look at the numbers. Thats the best approach, but it is time-consuming and requires a lot of effort.

In this blog post, I’ll describe to you the basics of fundamental analysis and how you can get a ton of historical data to run a fundamental analysis of a business. By the end of this article, you will be able to do your own fundamental analysis of a company and identify long-term investable businesses.

Fundamental analysis

As I said earlier, fundamental analysis is the process of looking at historical data of a company and using one or more economic models to identify the “fair value” or intrinsic value of that company.

Fundamental analysis typically looks into the following matters:

– The overall state of the company

– The strength of the industry in which the company operates

– The financial performance of the company

– The competitive advantage or as Warren Buffett says “economic moat” of the company

Read more about the fundamental analysis:

Libraries

There are a lot of sites that offer API endpoints to gather technical and fundamental information about a company, like Alpha Vantage, Polygon, Yahoo Finance, etc. In this blog, we’ll use the “fundamentalanalysis” Python library. This offers 20 years of company profiles, financial statements, and a hand full of calculated ratios.

Gathering fundamental data

Enough talk. Let’s dive in.

First, we need to set up our free developer account at financialmodelingprep.com and grab the API key. Using this API key and the company ticker we will request information about our desired company. For this tutorial, I’m going to use my favorite company Microsoft (MSFT).

The library offers several functions to collect necessary data. But for our fundamental analysis, the following functions are going to be enough for now:

  • quote: for basic company information
  • income_statement: offers revenue, income, eps, etc
  • balance_sheet_statement: provides asset, liability, equity, etc
  • cash_flow_statement: provides net-income, free-cash-flow, etc
  • key_metrics: offers important calculated metrics (pe ratio, roic, roe, etc)

The ‘quote’ function offers basic information about the company, like market-cap, current price, earning per share (eps), price to earning (pe), etc.

We have learned that a company’s overall state and financial performance play key roles in the fundamental analysis. Normally these key details are found in the Income Statement, Balance Sheet, and Cash Flow Statement. Let’s see how we can get this information using the fundamentalanalysis library.

You might have noticed that I have transposed the ‘income_statement_annually’ dataframe. The reason is our library returns a dataframe that has the timeline (year) in the columns and features (revenue, eps, etc) as the index. This is more friendly to the financial analysts, but not that friendly to programmatic data manipulation. That’s why I transposed the dataframe and took the features into the column.

There are a lot of fields returned with the library call, but for our fundamental analysis, we are only interested in revenue, operating income, and diluted eps from the income statement. Thats why we sliced the dataframe and kept the interesting attributes.

Conclusion

I hope you have learned the basics of fundamental analysis of a company and how to gather information using the fundamentalanalysis library.
The entire code is available in this Deepnote notebook.

In the next post, we will get more into the reasoning behind our focus on those attributes and collect more information from the balance sheet and cash flow statement. Using all this information, we will check the soundness of the company’s financial health.

Source: https://medium.datadriveninvestor.com/guide-to-fundamental-analysis-for-stock-market-investing-with-python-e1a2923de6b7