FMP

FMP

Enter

How to calculate Price Book ratio with Python

-

twitterlinkedinfacebook
blog post cover photo

Image credit: Syd Wachs

Price to Book ratio (PB) is a very useful metric to analyse the relative value of a company. PB helps to determine if a company is currently undervalued or overvalued in comparison to similar firms. In this article, we are going to learn how to calculate Price Book value (PB) using Python.

What is Price to Book Ratio?

Before moving to Python, it is always good to have clear what we want to do. In this case, we need to know what is the Price Book ratio and how it is calculated.

Price Book value is a financial ratio which can give a good indication of a firm price compare to other similar firms. It is calculated as the company market capitalisation divided by the book value of equity.

An alternative method to calculate PB ratio is to divide the stock price by the book value of equity on a per share basis. We will use the first approach for our example.

There are only two elements required to calculate the Price Book Ratio:

  • Company Market Capitalisation: It can be easily obtained from any exchange or financial website. It is the quote price per stock multiply by the number of shares outstanding.

  • Book Value of Equity: It can be extracted from the financial reports published by public companies. It is found under the Equity section of the Balance Sheet under the label of total shareholders equity. The book value is simply the net assets of a company and it is a past looking measure. I.e. it takes into account historic transactions such as profit and losses from previous periods, dividends, etc.

Photo by Isaac Smith on Unsplash

How to interpret Price Book Ratio?

Price Book ratio is a good indicator to know if a firm is overvalued or undervalued compared to a peer company. A high Price Book ratio may indicate that the firm is expensive or maybe that the market is very optimistic about a firm future prospects. Growing firms tends to have a very high Price to Book ratio.

On the other hand, companies with low Price Book ratios are known as value stocks. It may indicate that a company is undervalued since the book value is higher than the market capitalisation.

However, we need to be cautious with companies with low Price to Book ratios since it may also be a sign of financial distress or expected future earnings drop.

Firms in the technology industry are a clear example of growth companies with very high Price to Book ratio.

Let's check the PB ratio with Python by calculating the ratio for companies in the technological sector.

Calculating Price Book Ratio with Python



We will create a function getpricetobook that will take as argument the ticker of the company for which we want to extract data. In our example, we will pass AAPL to get financials for Apple.

We make a request to the end point of our financial API to retrieve Balance Sheet statement data. Then, we store the response in a variable call BS.

import requests

api_key = 'your api key'

def getpricetobook(stock):

BS = requests.get(f'https://financialmodelingprep.com/api/v3/balance-sheet-statement/AAPL?period=quarter&limit=400&apikey={api_key}')

BS = BS.json()

print(BS)

getpricetobook('AAPL')

If we print our BS variable, we will see that we have a json object that we need to parse. This is an easy task to do with Python.

First, we need to extract the Total shareholders equity value since that will represent our Book value of equity (i.e. denominator of the Price Book ratio).

We can extract it by parsing BS and getting the total shareholder equity included in the first element of the list:

book_value_equity_now = float(BS[0]['totalStockholdersEquity'])

print(book_value_equity_now)

Note that we have included float in front of the API returned string in order to convert it to a float.

Next, we have to retrieve Apple's market capitalisation. We can easily do that by making a request to the respective API end point:

company_info = requests.get(f'https://financialmodelingprep.com/api/v3/profile/AAPL?apikey={api_key}')

company_info = company_info.json()

market_cap = float(company_info[0]['mktCap'])

print(market_cap)

As we did previously, we extract the mktCap value within the profile dictionary. Note that this value is based on the most current stock price while our equity book value is based on the latest available Balance Sheet Statement.

Finally, we can calculate our Price to Book ratio:

price_to_book = market_cap/book_value_equity_now

return (price_to_book)

Now, we have our Python script ready. We can pass any company ticker and Python will calculate the Price Book ratio for us. It was quite easy to build and may be useful to know if certain companies may be overvalued/ undervalued compared to a peer or industry group.

Other Blogs

Aug 7, 2024 7:53 AM - Parth Sanghvi

The Impact of Interest Rates on the Economy and Financial Markets: A Comprehensive Analysis

Interest rates play a crucial role in the economy and financial markets, influencing everything from consumer behavior to investment decisions. Understanding their impact is essential for making informed financial and investment decisions. This comprehensive analysis delves into how interest rates a...

blog post title

Sep 10, 2024 11:33 AM - Parth Sanghvi

Best Alternatives to Yahoo Finance for Downloading Historical Stock Data

When it comes to downloading historical stock data, Yahoo Finance has been a popular choice for many. However, for those looking for more comprehensive, accurate, and flexible options, Financial Modeling Prep (FMP) offers a suite of powerful tools and services that stand out as superior alternatives...

blog post title

Nov 8, 2024 10:30 AM - Sanzhi Kobzhan

Understanding Equity Valuation: When to Use DCF, DDM, and Price-Income (Multiplicators) Models

When it comes to investing in stocks, one of the key decisions an investor must make involves determining the intrinsic value of a company's shares. Equity valuation isn't just about numbers, it's an art mixed with science, aiming to predict future performance based on current and historical data. H...

blog post title
FMP

FMP

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.
twitterlinkedin
2017-2025 © Financial Modeling Prep