Extracting Historical Earnings Data Using Python

Earnings Announcement Strategies Extracting Earnings Dates

By Milind Paradkar

Earnings announcement events are important events for investors and traders. Earnings results of a company tend to determine the future price direction of a stock and hence these are closely followed and analyzed by them. The period around the date of the earnings announcement sees increased volatility in price and the traded volume of the stocks. Traders can take advantage of this by using different earnings announcement trading strategies.

You can check the “Screener” page on the Quantpedia site where they have listed different earnings announcement trading strategies. The “Screener” page on Quantpedia categorizes hundreds of trading strategies based on different parameters like Period, Instruments, Markets, Keywords etc. Quantpedia has made some of these trading strategies available for free to their users.

 

Some of the earnings announcement strategies listed on the Quantpedia site include:

To formulate and backtest any earnings announcement strategy, we need the historical dates of earnings release for any given company. Once the dates are extracted, an earnings announcement strategy can be formulated using these dates and other important data like price-volume history, historical performance numbers like sales, profit margin, net margin etc.

Earnings release dates can be obtained from different sources; a financial markets portal being one of such sources. The goal of this article is to extract the historical earnings dates from a popular financial markets portal using Python.

 

Corporate Events Table

Python Code for Extracting Historical Earnings Release Dates

Step 1: We first import the required libraries; requests, pandas, and BeautifulSoup. We then copy the URL from the financial market portal for the particular company.

We apply the requests.get function from the Python requests library (which is a simple HTTP library) on the URL which creates a response object (named as “page” in the code). One can check whether we were able to successfully execute the function by checking the status code. The contents of the “page” object can be viewed using the content method.

Step 2: In this step, we use the BeautifulSoup library for pulling the events table from the HTML. Some basic knowledge of HTML is required in this step. We inspect the HTML page to find the exact location of the events table. We apply the “find_all” method on the respective table class.

Step 3: Note that find_all returns a list. Hence we loop through or use list indexing to extract the required content. We parse the body of the table to grab each row, and extract the values from its columns, and then move on to the next row.

We create two separate empty Python Lists, namely date_list and event_list, which we will populate with the event dates and the event names respectively using the Python For-Loop. The values obtained using the text method is in the Unicode format and we need to convert them to string type.

Learn Algorithmic trading from Experienced Market Practitioners




  • This field is for validation purposes and should be left unchanged.

Step 4: In the final step, we merge the two Python lists into a Pandas data frame and select only the “Quarterly Results” and the “Audited Results & Dividend” events. Let us print the earnings release dates of the latest four years.

 

 

One can extract earnings release dates using this Python code and then use other relevant data to build earnings announcement trading strategies. We will explore such trading strategies in our upcoming post. Meanwhile, you can check other quantitative trading strategies listed on our site. As always, we appreciate the likes and shares for our posts. Keep them coming!

Next Step

If you want to learn various aspects of Algorithmic trading then check out our Executive Programme in Algorithmic Trading (EPAT™). The course covers training modules like Statistics & Econometrics, Financial Computing & Technology, and Algorithmic & Quantitative Trading. EPAT™ is designed to equip you with the right skill sets to be a successful trader. Enroll now!

Download Data Files

  • Extracting Earnings Dates.py

5 thoughts on “Extracting Historical Earnings Data Using Python

  1. November 27, 2017

    Akshay Reply

    Hi
    Thanks for the code on historical results calendar. But how to extract this for 500 stocks..?
    Would highly appreciate your help.

    • November 27, 2017

      admin Reply

      You will have to add a Python For-Loop statement and create a list of the appropriate URLs for all the stocks required. This will give you the desired result.

  2. November 30, 2017

    Akshay Reply

    Hi
    I would like to this information cnx500 stocks. I could not see a pattern in url which is common. And manually creating list of 500 URL’s would not be efficient. Do you have any suggestions?
    Appreciate your help on this.

    • November 30, 2017

      admin Reply

      Unfortunately, you will have to manually create a list of the required URL’s. Readers can drop a comment if they have suggestions to do it automated way. Thanks.

  3. December 25, 2017

    maverick Reply

    how do i find an image or a javascript query that contains a .csv file using find_all method. For example the corporate actions of BSE website contains a link to download csv of all corporate actions.

    http://www.bseindia.com/corporates/corporate_act.aspx

Leave a Reply

Your email address will not be published. Required fields are marked *