Analysing Institutional Investors Stocks Holdings with Python
As you may have noticed in my previous stories, I like having fun by tracking institutional investor portfolios. In this post we will keep having fun by analysing institutional investors stocks holdings with Python.
To be more precise, we will look at how many institutional investors hold a given stock for a given period of time. On top of that, we will plot the data for the last few quarters to unravel which stocks are trending higher among institutions. Below is a snapshot of the outcome!
How many institutions are holding a particular stock?
Institutional investors are due to report their portfolio positions every quarter to the SEC. This disclosing takes place through the SEC Form called 13F. Therefore, the 13F will be the source of our data. How can we extract the number of holdings for a given company?
We have a couple of options to analyse the filings and gather our data:
- First option is going manually through each of the 13F filings. I would not recommended this since it will be super time consuming
- The second option would be to scrape the SEC site and extract the 13F filing information using Python. This would be the best way since we have all information publicly available and for free. The problem with this approach is that it is quite challenging parsing SEC filings
- And the last option, and the one I will use in this post, is to use an API provider. The API provider has already done the job to collect data for us. In this post, we will be using financialmodelingprep which has great API end points on institutional stock ownership. The problem with this approach is that we require an API subscription to retrieve the data.
Analysing Institutional Holdings with Python
We start by making an API call to the API end point. The request returns a dictionary. Each element in the dictionary contains key information for a given quarter for the selected stock.
Note that as part of the url request, we need to pass our API key as well as the ticker of the stock. In this example, we want to analyse Facebook holdings by quarter per institution:
import requests
import pandas as pd
import matplotlib.pyplot as plt stock = 'FB' api_key = 'your api key'
ownswership_by_stock = requests.get(f'https://financialmodelingprep.com/api/v4/institutional-ownership/symbol-ownership?symbol={stock}&apikey={api_key}').json() print(ownswership_by_stock)
Below screenshot shows some of the key information returned by the API for each quarter. In this post, we will uniquely extract the date and the investors holdings data points (i.e. how many institutions are currently holding Facebook).
It is important to note that the API is providing real-time information. Since the date of this post is the 3rd of January, we only have 3 days of data for the most recent quarter. That means that we are missing the big majority of institutional fillings which are yet to report the 13F filing. For that reason, we will exclude the latest data point (i.e. latest quarter) from the analysis.
Next, we create an empty dictionary to extract the information from the API. Then, we convert the dictionary into a Pandas DataFrame and keep only the latest 15 quarters, excluding the most recent one:
data_points = {} for item in ownswership_by_stock:
data_points[item['date']] = item['investorsHolding']pd_DF = pd.DataFrame(data_points,index=["Inst Investors Holdings"]).T
pd_DF["Inst Investors Holdings"] = pd_DF["Inst Investors Holdings"].astype(float) #reverse dates and take only latest 15 data points
pd_DF = pd_DF.iloc[::-1][-15:-1] print(pd_DF)
Plotting number of institutions holding Facebook
Once we have our pandas DataFrame containing the dates and the number of institutions holding Facebook, we can easily plot the data using Matplotlib:
fig, ax = plt.subplots()
ax.plot(pd_DF["Inst Investors Holdings"]) # Rotate and align the tick labels so they look better. fig.autofmt_xdate()
plt.title("Number of Institutions holding " + stock) plt.show()
Wrapping Up
Great, as we can see in the chart, during the last few quarters, more and more institutions are holding Facebook. Is this due to Facebook attractiveness or it is due to an increase number of institutions in the market? Feel free to perform a similar analysis with other stocks by simply replacing the name of the stock in the code. Then, you can see how the trend compares with Facebook.
As next steps, it would be interesting to analyse the decrease and increase of holdings per quarter in percentage terms. I leave that analysis to you.
Disclaimer: Note that this post is not intended to provide financial advise. The information provided in this blog may not be free of errors and therefore cannot be relied upon to make financial decisions.