I wrote software to bulk analyze and calculate the DCF value of all stocks in U.S. stock markets
Why DCF?
As a value investor, I believe the starting point to making money in the stock market is to determine a base value of a company using the sum of it’s future cash flows, discounted by risk, expected inflation, and the return of safe alternative investments.
But, why did I build software to automate DCF analysis en masse?
Running a DCF analysis for a single stock is tedious. 😩
(For example, I wrote this article that covers the eleven basic steps to generating a dsicounted cash flow value for a given stock.)
Running a DCF analysis by hand for 5,000+ stocks is impossible.
I’ve always wanted to write software to automate the process, but I lacked a clean, cost-effective data feed with which to do it.
Four or five years ago, when doing a software project for a friend, I finally found a great set of APIs (iexcloud.io) for writing this software tool.
How did I develop the application?
This application was written, over a weekend, in Microsoft’s .NET C#. (.NET 6.0 to be exact)
The beautiful expressiveness of C#, combined with .NET’s support for Dynamic, means that this entire application is only 620 lines of code (including whitespace).
How does the application work?
I call the application, Analyzer-Engine. (Very creative. I know. 🙂)
Analyzer-Engine takes a list of stock tickers provided in JSON format as input.
For each company ticker, my application calls iexcloud.io APIs to retrieve:
1. The company’s last 12 quarters of cash flow data
2. The company’s balance sheet as of the latest filing
3. The company’s latest stock quote
From there, my Analyzer-Engine:
1. Computes the company’s free cash flows for the last 3 years.
2. Calculates current totals of cash and other liquid assets
3. Calculates current totals of current and long-term debt
4. Computes the company’s net liquid assets after subtracting debts
5. Computes free cash flow averages over the last 3 years
6. Calculates average free cash flow growth rates
7. Projects a conservative and aggressive discounted cash flow value for the company using the average growth rates and free cash flows
8. Computes a net DCF value after adding/subtracting net cash from the DCF value
9. Computes what the per-share price of the company would be at its conservative and aggressive DCF values
10. Computes the amount which the company is over or undervalued based on the conservative estimate and based on the aggressive estimate
11. Appends these computations and data to a single output CSV file
Now, in CSV format, I have a quick and dirty DCF value for EVERY COMPANY in U.S. stock markets! 🤯
I can use Excel filters to scan these companies, or I can print the data to hand select the companies on the U.S. stock markets that look most undervalued!
This is no small deal.
Over the past year, this tool allowed me to see the META and Tesla opportunities before those stocks’ meteoric rise from Q4 2022 to Q3 2023!!
Below you can see what the application looks like as it executes.
And below is a snapshot of what the CSV looks like as I use it in Excel.
How did I develop the application?
This application was written, over a weekend, in Microsoft’s .NET C#. (.NET 6.0 to be exact)
The beautiful expressiveness of C#, combined with .NET’s support for Dynamic, means that this entire application is only 620 lines of code (including whitespace)!
As you can see above, to speed development, I developed it as a command line application.
Below is an example of what the command line looks like to trigger an application execution.
Below is a snapshot of a simple input test file with just two tickers. (Note: My full JSON file contains as many as 7,500+ tickers — some of these tickers are for international companies that trade OTC.)
How do I build the JSON file of stock tickers? Definitely not by hand…
The source list of tickers came from Nasdaq’s own stock screener (See: https://www.nasdaq.com/market-activity/stocks/screener). From there I got a CSV of tickers.
I converted the CSV to JSON using Powershell. Using JSON allows for safer, easier structured consumption.
What sort of stock analysis tool do you think I should write next?
Let me know if you’d like to use this application. I’ve thought about making it publicly available.
If you’re interested, I can share the code with you so you can have it too.