This post was written using the yfinance library for Python as well as pandas and matplotlib. yfinance allows you to access Yahoo Finance’s public APIs to get data on companies. I’ve just started learning python, having taken some excellent courses from Alex the Analyst, and I wanted to try out some of the skills I’ve learned. I’d also wanted to access company data and yfinance seemed a great tool to do this.

First of all, I picked a company – British pharmaceutical giant AstraZeneca.

So, some basic stats. At time of writing (11th September 2024), the current share price for AstraZeneca was 12322 pence, so £123.22p.

Its market capitalization was £191.03 billion.

Its price to book ratio was 483.37, peg ratio 2.81, book value 25.49.

Looking at the graph below, the price of AstraZeneca shares has been rising sharply in recent years, taking off around 2016.

The next graph simplifies the data by looking at the yearly average.

Next we look at how AstraZeneca shares compare to another British pharmaceutical company, GlaxoSmithKline. As you can see, the share prices have diverged, especially around 2016.

yfinance offers lots of great commands to access interesting information about companies. One that caught my eye was the EPS or earnings per share, since there are also data on analysts expectations for the company. As seen in the graph below, AstraZeneca has often done better than expected, indicating better-than-expected financial performance. The ‘surprise’ factor (reported/estimate as a percentage) shown in the left hand panel has more often than not, been greater than zero.