Categories
Code Options Trading Trading Tools

How to get insider trading data from the SEC database using Python

Company insiders are forced to report their buy/sell operations to the SEC through form-4. We’ll use Python in order to get this data automatically without having to manually check each company in our portfolio.

Company insiders are forced to report their buy/sell operations to the SEC through form-4, and this can give us clues about the business direction. While insider selling is not always a bad sign, insider buying generally is good as shows insider confidence in the company’s future.

That said, is a waste of time to have to check the SEC website and the EDGAR database constantly (and manually) in order to get this information, for all the businesses we are following. That’s why we’ll use Python! So we can get the form-4 submission updates automatically.

This is the initial MVP code:

from bs4 import BeautifulSoup
from urllib2 import urlopen
 
EDGAR_STOCKS_TO_CHECK = ['T', 'GILD', 'MO', 'MMM', 'AMCR']
 
def _edgar_form_4(ticker):
 
    url = urlopen('https://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&CIK=' + ticker + '&type=4&dateb=&owner=only&count=40')
    soup = BeautifulSoup(url, 'html.parser')
     
    filling_date_block = soup.find_all('tr')
    data = list()
    rows = filling_date_block[3].find_all('td')
    for row in rows:
        data.append(row)
    print ticker + ': Latest change was on ' + str(data[3])
     
for eachStock in EDGAR_STOCKS_TO_CHECK:
    _edgar_form_4(eachStock)

And this will be the end result in our terminal:

Leave a Reply