For years I looked for a simple way to get earnings reports from Wall St. It seems they would change their earning reports on a regular basis and the dates would be inconsistent. Then one day when I wasn’t paying attention, BAM. Earnings report and the stock would take off or crash on the numbers and I would be left holding the bag or missed the boat. You get the point.
It has been my experience that Yahoo Financial calendar provides the most consistent and update earning report for listed companies. (If there any better ones out there please do email or do PR for the repo.) So now that I have found a source, how to do I make take that information and standardize and normalize it into a database. Obviously once I have that information in a database, I can use that data to purchase calls, puts or evaluate the earnings date based on a host of other information I have available to “cross reference” or analyze.
Luckily, through the power of scraping + python + github anybody can now have standardized earnings date reports and now I can scrape and standard the data and manipulate it to my needs.
In my repo I added the file earnings.py. This is where the magic occurs..
Just a simple Mysql table to capture date, stocks, eps estimates, etc…
q = "truncate yahoo_earnings"
cursor.execute(q)
Then we have to a little “wonky” stuff with the dates that we are going to query. It seems like weather I’m in PHP or Python, I’m always getting entagled in dealing with DATE or TIME, if anybody can parse those dates better please send at PR.
#set dates
now = datetime.now()
startDate = now.strftime('%b %d %Y %I:%M%p')
print(startDate)
endDate = now + timedelta(days=60)
endDate = endDate.strftime('%b %d %Y %I:%M%p')
print(endDate)
startDate = datetime.strptime(
startDate, '%b %d %Y %I:%M%p')
endDate = datetime.strptime(
endDate, '%b %d %Y %I:%M%p')
Then as you can see from the code it’s pretty simple after that, call the function, parse the data, load it into your database or where ever you need it. Oh I forgot to mention, Make a ton of Money.
All this code can be found in my stock and options API repo, specifically with the Earnings-Scraper/earnings.py file that I’m discuss here. If you want the raw repo from wenboyu2
This does not work for acting on just out earning results. Any idea how get it, since company websites don’t allow bots to keep polling their earnings results pages.
Since I wrote this post, this is probably not the best way to get earnings report dates. I believe that Interactive Brokers has API function to pull earning report dates, that one can call regularly. You could also poll the company’s pages using some scrapping code and automate it. (python/beautiful soup). I would be surprised if a company has blocking software.