Many investors consider fundamental analysis as their secret weapon to beat the stock market. You can perform it using many methods, but one thing they have in common. They all need data about companies’ financial statements.
Luckily all stocks traded on US stock markets must quarterly report to the Securities and Exchange Commission (SEC). Every quarter SEC prepares a comfortable CSV package to help all the investors in their quest for the investment opportunity. Let’s explore how to get valuable insights from these .csv files.
In this tutorial, we will use python’s pandas library which ideal for parsing CSV files, and we will learn how to:
We will process the data and:
As usual, you can follow the code in the notebook shared on GitHub.
There doesn’t seem to be any problem. You simply download the quarterly package from the SEC dataset page, you sort the values from the financial statements in descending order and pick the stocks on the top. The reality isn’t that straightforward. Let’s have a look and explore 45.55MB big zip file with all SEC filings for the first quarter of 2020.
The package for every quarter contains 5 files. Here’s an example of 2020 Q1:
Unzipped files in the SEC quarterly data dump
This article will only deal with the submission master because it contains more than enough information for one article. Follow-up story will examine the data in more detail. Let’s begin.
In the first quarter of 2020, the companies have submitted 13560
files and the sub.txt gathers 36 columns about them.
# load the .csv file into pandas
sub = pd.read_csv(os.path.join(folder,"sub.txt"), sep="\t", dtype={"cik":str})
# explore number of rows and columns
sub.shape
[Out]: (13560, 36)
I always start with a simple function that reviews each column of the data frame, checks the percentage of empty values, and how many unique values appear in the columns.
Explore the sub.txt file to see what data each column contain
Let me highlight a few important columns in the SEC submission master.
Example of the quick file overview in pandas
Based on the analysis, we see that the 2020Q1 submission contains 23 unique types of financial reports. Investors’ primary interest lies in the 10-K report, which covers the annual performance of the publically traded company. Because this report is expectedly delivered only once a year, important is also 10-Q report showing quarterly changes in the company’s financials.
10-K
Annual report of US-based company10-Q
Quarterly report and maybe20-F
Annual Reports of a foreign company40-F
Annual Reports of a foreign company (Canadian)Let’s see which forms are the most common in the dataset. Plotting of the form types in the 2020Q1 will show this picture:
Using Plotly’s low level API to produce bar and pie subplots
Different submission types reported by the companies in 2020Q1 using visualization in Plotly
The dataset contains over 7000 8-K reports notifying about important events like agreements, layoffs, usage of material, modification of shareholder rights, change in the senior positions, and more (see SEC’s guideline). Since they are the most common we should spend some time exploring them.
#stocks #exploratory-data-analysis #python #data-analysis #stock-market #data analysis