Optimize Stock Evaluation: Calculating Ratios and Growth Rates
Written on
Chapter 1: Introduction to Stock Evaluation
In the realm of value investing, I have established a systematic approach to assess stock prices before making any purchasing decisions. My methodology includes several key steps:
- Screening potential stock candidates.
- Comparing various ratios and growth rates to pinpoint promising options.
- Estimating the intrinsic values of these stocks utilizing Benjamin Graham's formula and the discounted cash flow method.
- Selecting stocks priced below their intrinsic values.
- Finally, reviewing the financial reports of the top candidates.
Since analyzing financial reports can be quite labor-intensive, I prioritize it as the concluding step in my evaluation process. For the initial stock screening, I rely on platforms like Finviz and TradingView. Additionally, if a stock is recommended in a YouTube video, I take note of its ticker symbol for subsequent analysis.
While checking ratios and growth rates for a single company is relatively straightforward—thanks to the abundance of available online data—comparing ten or more stocks becomes a daunting task. To streamline this, I aim to develop a program that automates data retrieval and organizes it into a single table.
Chapter 2: Selecting the Right Library
As mentioned in my previous writings, I utilize an open-source library called yfinance to fetch financial data for companies. Although the Python script has expedited my stock valuation process, I've encountered some limitations with the yfinance library:
- It only offers four years of historical data, whereas I prefer ten or, at the very least, five years.
- It lacks essential financial metrics such as gross margin and debt-to-equity ratio, requiring me to write additional code to compute these metrics from the raw financial information.
- For certain companies, some necessary data points for calculating these metrics are unavailable, which necessitates robust error handling in my code.
Consequently, I began searching for alternatives to yfinance. Being a novice investor, I wanted to avoid incurring expenses during my learning process, which led me to seek out free libraries. Unfortunately, many of the available options did not meet my requirements.
Eventually, I discovered a viable solution called Financial Modeling Prep (FMP). Its free tier allows up to 250 API calls daily and provides five years of historical data. The API not only supplies the raw data as reported in financial statements but also includes the crucial ratios and growth metrics I need.
Though five years of data is not ideal, it is still better than the four years offered by yfinance. It's worth noting that I have no affiliation with FMP; my discussions stem solely from my experiences. If you have any concerns regarding the accuracy of the data, I encourage you to cross-verify it with official financial reports and perform your own calculations.
The first video titled "Building a PEG Ratio Screener with Python" offers insights on how to automate the screening of stocks based on their PEG ratios, helping investors make informed decisions.
Chapter 3: Utilizing the FMP API
Key Metrics:
- ROIC
- Ratios (TTM)
- P/E
- P/FCF
- ROA
- ROE
- Gross margin
- Net income margin
- Debt to equity
- Current ratio
- Long-term debt to capitalization
- Cash flow to debt ratio
Financial Growth:
- Revenue growth
- Net income growth
- EPS growth
- Free cash flow growth
- Dividend per share growth
Balance Sheet Growth:
- Growth long-term debt
Enterprise:
- Number of shares
- Number of shares growth
- Market capitalization
- Market capitalization growth
To illustrate how to retrieve data using the Key Metrics API, here are the steps:
- Obtain Your API Key: Register for a free account to get your API key. This key is essential as it limits the number of calls you can make per day.
- Set Up Your IDE: I recommend using Google Colab, which is free and has the necessary libraries pre-installed.
- Import Required Python Packages: For data manipulation, you will need to import pandas and requests.
import pandas as pd
import requests
- Construct the API URL: For example, the Key Metrics endpoint for Apple would look like this:
ticker_input = 'AAPL' # Stock ticker
period_input = 'annual' # Only 'annual' is allowed for free accounts
API_KEY = 'YOUR_API_KEY'
- Retrieve the Data: Fetch the data using a simple GET request:
key_metrics_json = requests.get(key_metrics_url).json()
- Handle Errors: Implement error handling to manage cases where the API limit is exceeded.
- Extract and Calculate Data: You may wish to distill the data down to relevant metrics for your analysis.
Now that I've outlined the process, let’s take a closer look at how to aggregate and analyze the data efficiently.
The second video titled "Stock Market Analysis using Python" delves into leveraging Python for comprehensive stock market evaluations, emphasizing data analysis techniques.
Chapter 4: Final Thoughts
While five years of data isn't perfect, it suffices for preliminary stock evaluations. The daily API call limit of 250 can be restrictive, especially since I often need to check multiple financial metrics across various statements. This means I can effectively analyze only around 41 stocks daily.
After downloading the resulting data as a CSV file, I transfer it to Google Sheets for further comparison. If I identify stocks that seem promising, I then cross-reference the data on platforms like quickfs.net for additional historical insights. If everything still appears favorable, I proceed to compute intrinsic values and examine financial reports.
Although I cannot claim to be an expert in stock valuation, this thorough methodology certainly enhances my confidence in making investment choices. My next goal is to automate the intrinsic value calculation process, and I look forward to sharing my progress in future updates.
I hope you find this information and code helpful!