Analysing Inside Trading within a Company with Python

What are company insiders (e.g. CEO, CFO, etc.) doing respect to the stocks they own in their own company? Are they selling or buying the stock? Let’s find out

Analysing Inside Trading within a Company with Python

Sep 11, 2023 5:02 PM - Rajnish Katharotiya

blog post cover photo

Image credit: sebastiaan stam

What are company insiders (e.g. CEO, CFO, etc.) doing respect to the stocks they own in their own company? Are they selling or buying the stock? Let's find out by retrieving inside trading within a company with Python.

Photo by The Lazy Artist Gallery on

Why to Analyse what Company Insiders do?

When we are analysing a company, in addition to perform the widely used fundamental analysis, we should search for other ways to get valuable information that can give us additional insights. For example, we may take a look at company insiders trading.

While insider trading is not illegal, there are certain timelines that company insiders need to follow in order to buy sell inside stocks (i.e. buy or sell stocks from the company they work). For instance, directors or officers from a company must not buy or sell company stocks when they are in possession of internal material information that is not yet public.

Outside of this “quite period” (i.e. period where they are not allowed to buy or sell stocks), they actually can buy and sell the stocks. To do that they need to report their transactions to the SEC through the SEC form 4 - Statement of Changes in Beneficial Ownership Overview.

What is the SEC Form 4 - Statement of Changes in Beneficial Ownership Overview?

All company directors and officers of the company must report in the SEC Form 4 if they buy or sell shares of the company for which they operate within 48 hours. Also, shareholders owning more than 10% of the shares must fill in this form.

The SEC form 4 covers any buy or sells of stocks as well as execution of company stock options.

Why is important for an investor to know what insiders are doing?

For company analysts, knowing what company insiders are doing can offer a very valuable insight on what are the upcoming prospects of the company.

For example, if the CEO of a company is buying shares, it may mean that he/she perceives the company as currently undervalued in the market or that he see some growth potential within the next months. So that may be a bullish signal.

On the other side, a company insider may be selling stocks if the current stock price is above what is considered fair value. Of course, it could also be that insiders are selling because they want to cash out some of the stocks that they own.

Having said this, I perceive as a bullish signal when company insiders are buying the company stock. However, this is just my personal opinion and you should not take it as an investment advise.

Looking into Inside Trading with Python

While looking into the SEC filings may be super time consuming, we can use Python and an Insider Trading API endpoint to retrieve the latest traders performed by company insider within a company. It provides a great overview of the latest inside transactions for a selected company.

Please note that this is a special endpoint and you need to use advanced plan to deal with it.

So the code will do the next thing:

  • It will request the latest insider transactions for a specific company.

  • Then it will subsctract date and volume of transacted securities.

  • If the type of transaction would be "acquistion", it will show that as a positive number, otherwise we should count that a negative number.

So here is the code:

api_key = 'demo'

company = 'AAPL'

response = requests.get(f'{company}&page=0&apikey={api_key}')

company_insiders_transactions = []

for res in response:

date = res['transactionDate']

volume = res['securitiesTransacted']

acquistion_or_disposition = res['acquistionOrDisposition']

change = volume if acquistion_or_disposition == 'A' else volume * (-1)

transaction = { "date": date, "change": change }



Wrapping Up

After running the code, we can see that for Apple there were a few insider transactions happening within the last few weeks.

Can we rely on that information without any additional information? No, we can't, espesially when we don't see a huge amout of transactions last days. Anyway, insider transactions gives us a lot material to think about. For additional information, we could use, for example, different financial ratios and key financial statisctics.

Other Blogs

Sep 11, 2023 - Rajnish Katharotiya

P/E Ratios Using Normalized Earnings

Price to Earnings is one of the key metrics use to value companies using multiples. The P/E ratio and other multiples are relative valuation metrics and they cannot be looked at in isolation. One of the problems with the P/E metric is the fact that if we are in the peak of a business cycle, earni...

blog post title

Sep 11, 2023 - Rajnish Katharotiya

What is Price To Earnings Ratio and How to Calculate it using Python

Price-to-Earnings ratio is a relative valuation tool. It is used by investors to find great companies at low prices. In this post, we will build a Python script to calculate Price Earnings Ratio for comparable companies. Photo by Skitterphoto on Pexels Price Earnings Ratio and Comparable Compa...

blog post title

Oct 17, 2023 - Davit Kirakosyan

VMware Stock Drops 12% as China May Hold Up the Broadcom Acquisition

Shares of VMware (NYSE:VMW) witnessed a sharp drop of 12% intra-day today due to rising concerns about China's review of the company's significant sale deal to Broadcom. Consequently, Broadcom's shares also saw a dip of around 4%. Even though there aren’t any apparent problems with the proposed solu...

blog post title


Financial Modeling Prep API provides real time stock price, company financial statements, major index prices, stock historical data, forex real time rate and cryptocurrencies. Financial Modeling Prep stock price API is in real time, the company reports can be found in quarter or annual format, and goes back 30 years in history.
2017-2023 © Financial Modeling Prep