FMP

# How to calculate Price Book ratio with Python

## How to calculate Price Book ratio with Python

Sep 11, 2023 5:32 PM - Rajnish Katharotiya

#### 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

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

Sep 11, 2023 - Rajnish Katharotiya

## P/E Ratios Using Normalized Earnings

Price to Earnings is one of the key metrics use to value companies using multiples. The P/E ratio and other multiples are relative valuation metrics and they cannot be looked at in isolation. One of the problems with the P/E metric is the fact that if we are in the peak of a business cycle, earni...

Sep 11, 2023 - Rajnish Katharotiya

## What is Price To Earnings Ratio and How to Calculate it using Python

Price-to-Earnings ratio is a relative valuation tool. It is used by investors to find great companies at low prices. In this post, we will build a Python script to calculate Price Earnings Ratio for comparable companies. Photo by Skitterphoto on Pexels Price Earnings Ratio and Comparable Compa...

Oct 17, 2023 - Davit Kirakosyan

## VMware Stock Drops 12% as China May Hold Up the Broadcom Acquisition

Shares of VMware (NYSE:VMW) witnessed a sharp drop of 12% intra-day today due to rising concerns about China's review of the company's significant sale deal to Broadcom. Consequently, Broadcom's shares also saw a dip of around 4%. Even though there aren’t any apparent problems with the proposed solu...

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.